From 50859db4a735131b70e9467b8a462a117b2c279c Mon Sep 17 00:00:00 2001 From: MayorJay Date: Mon, 29 Apr 2024 22:03:37 +0100 Subject: [PATCH] feat: Modify field data types --- .../kotlin/dto/request/BaseEventRequest.kt | 34 ++++++++++++++++--- .../kotlin/dto/request/TriggerEventRequest.kt | 27 ++++++++------- src/test/kotlin/EventsApiTest.kt | 17 ++++++++-- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/dto/request/BaseEventRequest.kt b/src/main/kotlin/dto/request/BaseEventRequest.kt index 38ef87d..448f271 100644 --- a/src/main/kotlin/dto/request/BaseEventRequest.kt +++ b/src/main/kotlin/dto/request/BaseEventRequest.kt @@ -1,5 +1,7 @@ package co.novu.dto.request +import co.novu.dto.Tenant + abstract class BaseEventRequest { // Mandatory fields @@ -9,16 +11,40 @@ abstract class BaseEventRequest { // Optional fields private var overrides: Map? = null private var transactionId: String? = null - private var actor: String? = null - private var tenant: String? = null + + /** + * Possible types this field accepts are; String or [Map] + * + * For example: + * + * actor = mapOf( + * "subscriberId" to "sId", + * "email" to "email@mail.com", + * "firstName" to "fName", + * "lastName" to "lName", + * "phone" to "phoneNo") + */ + private var actor: Any? = null + + /** + * Possible types this field accepts are; String or [Tenant] + * + * For example: + * + * tenant = Tenant( + * identifier = "identifier", + * name = "name", + * data = Any()) + */ + private var tenant: Any? = null protected fun init( name: String, payload: Map, overrides: Map? = null, transactionId: String? = null, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ): BaseEventRequest { return this.apply { this.name = name diff --git a/src/main/kotlin/dto/request/TriggerEventRequest.kt b/src/main/kotlin/dto/request/TriggerEventRequest.kt index fcc8001..9dc56d3 100644 --- a/src/main/kotlin/dto/request/TriggerEventRequest.kt +++ b/src/main/kotlin/dto/request/TriggerEventRequest.kt @@ -3,6 +3,9 @@ package co.novu.dto.request import co.novu.dto.Topic class TriggerEventRequest private constructor() : BaseEventRequest() { + /** + * Possible types this field accepts are; [SubscriberRequest], list of [SubscriberRequest], [Topic] or list of [Topic] + */ private var to: Any? = null companion object { @@ -12,8 +15,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() { payload: Map, overrides: Map?, transactionId: String?, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ) = TriggerEventRequest() .apply { @@ -28,8 +31,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() { payload: Map = mapOf(), overrides: Map? = null, transactionId: String? = null, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ) = initFields(name, to, payload, overrides, transactionId, actor, tenant) @JvmName("fromListOfString") @@ -39,8 +42,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() { payload: Map = mapOf(), overrides: Map? = null, transactionId: String? = null, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ) = initFields(name, to, payload, overrides, transactionId, actor, tenant) @JvmName("fromListOfSubscribers") @@ -50,8 +53,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() { payload: Map = mapOf(), overrides: Map? = null, transactionId: String? = null, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ) = initFields(name, to, payload, overrides, transactionId, actor, tenant) @JvmName("fromSubscriber") @@ -61,8 +64,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() { payload: Map = mapOf(), overrides: Map? = null, transactionId: String? = null, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ) = initFields(name, to, payload, overrides, transactionId, actor, tenant) @JvmName("fromListOfTopics") @@ -72,8 +75,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() { payload: Map = mapOf(), overrides: Map? = null, transactionId: String? = null, - actor: String? = null, - tenant: String? = null + actor: Any? = null, + tenant: Any? = null ) = initFields(name, to, payload, overrides, transactionId, actor, tenant) } } diff --git a/src/test/kotlin/EventsApiTest.kt b/src/test/kotlin/EventsApiTest.kt index 3000e10..b14a2e6 100644 --- a/src/test/kotlin/EventsApiTest.kt +++ b/src/test/kotlin/EventsApiTest.kt @@ -1,5 +1,6 @@ import co.novu.Novu import co.novu.NovuConfig +import co.novu.dto.Tenant import co.novu.dto.Topic import co.novu.dto.request.BroadcastEventRequest import co.novu.dto.request.BulkTriggerEventRequest @@ -50,7 +51,14 @@ class EventsApiTest { lastName = "Doe" ), payload = mapOf("customVariables" to "Hello"), - transactionId = "transactionId" + transactionId = "transactionId", + actor = mapOf( + "subscriberId" to "sId", + "email" to "email@mail.com", + "firstName" to "fName", + "lastName" to "lName", + "phone" to "phoneNo" + ) ) val result = mockNovu.trigger(requestBody) val request = mockWebServer.takeRequest() @@ -84,7 +92,12 @@ class EventsApiTest { ) ), payload = mapOf("customVariables" to "Hello"), - transactionId = "transactionId" + transactionId = "transactionId", + tenant = Tenant( + identifier = "identifier", + name = "name", + data = Any() + ) ) val result = mockNovu.trigger(requestBody) val request = mockWebServer.takeRequest()