Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Field Data Types #73

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading