Skip to content

Commit

Permalink
Merge pull request #73 from mayorJAY/feat-modify-field-data-type
Browse files Browse the repository at this point in the history
Modify Field Data Types
  • Loading branch information
Cliftonz authored Apr 30, 2024
2 parents 813c81d + 50859db commit d4172c1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
34 changes: 30 additions & 4 deletions src/main/kotlin/dto/request/BaseEventRequest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.novu.dto.request

import co.novu.dto.Tenant

abstract class BaseEventRequest {

// Mandatory fields
Expand All @@ -9,16 +11,40 @@ abstract class BaseEventRequest {
// Optional fields
private var overrides: Map<String, Any>? = 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 protected]",
* "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<String, Any>,
overrides: Map<String, Any>? = null,
transactionId: String? = null,
actor: String? = null,
tenant: String? = null
actor: Any? = null,
tenant: Any? = null
): BaseEventRequest {
return this.apply {
this.name = name
Expand Down
27 changes: 15 additions & 12 deletions src/main/kotlin/dto/request/TriggerEventRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -12,8 +15,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() {
payload: Map<String, Any>,
overrides: Map<String, Any>?,
transactionId: String?,
actor: String? = null,
tenant: String? = null
actor: Any? = null,
tenant: Any? = null
) =
TriggerEventRequest()
.apply {
Expand All @@ -28,8 +31,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() {
payload: Map<String, Any> = mapOf(),
overrides: Map<String, Any>? = 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")
Expand All @@ -39,8 +42,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() {
payload: Map<String, Any> = mapOf(),
overrides: Map<String, Any>? = 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")
Expand All @@ -50,8 +53,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() {
payload: Map<String, Any> = mapOf(),
overrides: Map<String, Any>? = 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")
Expand All @@ -61,8 +64,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() {
payload: Map<String, Any> = mapOf(),
overrides: Map<String, Any>? = 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")
Expand All @@ -72,8 +75,8 @@ class TriggerEventRequest private constructor() : BaseEventRequest() {
payload: Map<String, Any> = mapOf(),
overrides: Map<String, Any>? = null,
transactionId: String? = null,
actor: String? = null,
tenant: String? = null
actor: Any? = null,
tenant: Any? = null
) = initFields(name, to, payload, overrides, transactionId, actor, tenant)
}
}
17 changes: 15 additions & 2 deletions src/test/kotlin/EventsApiTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 protected]",
"firstName" to "fName",
"lastName" to "lName",
"phone" to "phoneNo"
)
)
val result = mockNovu.trigger(requestBody)
val request = mockWebServer.takeRequest()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d4172c1

Please sign in to comment.