-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/workos/webhooks/models/OrganizationMembershipCreatedEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.workos.webhooks.models | ||
|
||
import com.workos.usermanagement.models.OrganizationMembership | ||
|
||
/** | ||
* Webhook Event for `organization_membership.created`. | ||
*/ | ||
class OrganizationMembershipCreatedEvent( | ||
@JvmField | ||
override val id: String, | ||
|
||
@JvmField | ||
override val event: EventType, | ||
|
||
@JvmField | ||
override val data: OrganizationMembership, | ||
|
||
@JvmField | ||
override val createdAt: String | ||
) : WebhookEvent(id, event, data, createdAt) |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/workos/webhooks/models/OrganizationMembershipDeletedEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.workos.webhooks.models | ||
|
||
import com.workos.usermanagement.models.OrganizationMembership | ||
|
||
/** | ||
* Webhook Event for `organization_membership.deleted`. | ||
*/ | ||
class OrganizationMembershipDeletedEvent( | ||
@JvmField | ||
override val id: String, | ||
|
||
@JvmField | ||
override val event: EventType, | ||
|
||
@JvmField | ||
override val data: OrganizationMembership, | ||
|
||
@JvmField | ||
override val createdAt: String | ||
) : WebhookEvent(id, event, data, createdAt) |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/workos/webhooks/models/OrganizationMembershipUpdatedEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.workos.webhooks.models | ||
|
||
import com.workos.usermanagement.models.OrganizationMembership | ||
|
||
/** | ||
* Webhook Event for `organization_membership.updated`. | ||
*/ | ||
class OrganizationMembershipUpdatedEvent( | ||
@JvmField | ||
override val id: String, | ||
|
||
@JvmField | ||
override val event: EventType, | ||
|
||
@JvmField | ||
override val data: OrganizationMembership, | ||
|
||
@JvmField | ||
override val createdAt: String | ||
) : WebhookEvent(id, event, data, createdAt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/kotlin/com/workos/test/webhooks/OrganizationMembershipWebhookTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.workos.test.webhooks | ||
|
||
import com.workos.test.TestBase | ||
import com.workos.webhooks.models.EventType | ||
import com.workos.webhooks.models.OrganizationMembershipCreatedEvent | ||
import com.workos.webhooks.models.OrganizationMembershipDeletedEvent | ||
import com.workos.webhooks.models.OrganizationMembershipUpdatedEvent | ||
import org.junit.Test | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import kotlin.test.assertEquals | ||
|
||
class OrganizationMembershipWebhookTests : TestBase() { | ||
|
||
private val organizationMembershipId = "om_01EHWNC0FCBHZ3BJ7EGKYXK0E7" | ||
private val webhookId = "wh_01FMXJ2W7T9VY7EAHHMBF2K07Y" | ||
|
||
private fun generateWebhookEvent(eventType: EventType): String { | ||
return """ | ||
{ | ||
"id": "$webhookId", | ||
"event": "${eventType.value}", | ||
"data": { | ||
"object": "organization_membership", | ||
"id": "$organizationMembershipId", | ||
"user_id": "user_01EHWNC0FCBHZ3BJ7EGKYXK0E6", | ||
"organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", | ||
"status": "active", | ||
"created_at": "2023-11-27T19:07:33.155Z", | ||
"updated_at": "2023-11-27T19:07:33.155Z" | ||
}, | ||
"created_at": "2023-11-27T19:07:33.155Z" | ||
} | ||
""" | ||
} | ||
|
||
@Test | ||
fun constructOrganizationMembershipCreatedEvent() { | ||
val workos = createWorkOSClient() | ||
val webhookData = generateWebhookEvent(EventType.OrganizationMembershipCreated) | ||
val testData = WebhooksApiTest.prepareTest(webhookData) | ||
|
||
val webhook = workos.webhooks.constructEvent( | ||
webhookData, | ||
testData["signature"] as String, | ||
testData["secret"] as String | ||
) | ||
|
||
assertTrue(webhook is OrganizationMembershipCreatedEvent) | ||
assertEquals(webhook.id, webhookId) | ||
assertEquals((webhook as OrganizationMembershipCreatedEvent).data.id, organizationMembershipId) | ||
} | ||
|
||
@Test | ||
fun constructOrganizationMembershipDeletedEvent() { | ||
val workos = createWorkOSClient() | ||
val webhookData = generateWebhookEvent(EventType.OrganizationMembershipDeleted) | ||
val testData = WebhooksApiTest.prepareTest(webhookData) | ||
|
||
val webhook = workos.webhooks.constructEvent( | ||
webhookData, | ||
testData["signature"] as String, | ||
testData["secret"] as String | ||
) | ||
|
||
assertTrue(webhook is OrganizationMembershipDeletedEvent) | ||
assertEquals(webhook.id, webhookId) | ||
assertEquals((webhook as OrganizationMembershipDeletedEvent).data.id, organizationMembershipId) | ||
} | ||
|
||
@Test | ||
fun constructOrganizationMembershipUpdatedEvent() { | ||
val workos = createWorkOSClient() | ||
val webhookData = generateWebhookEvent(EventType.OrganizationMembershipUpdated) | ||
val testData = WebhooksApiTest.prepareTest(webhookData) | ||
|
||
val webhook = workos.webhooks.constructEvent( | ||
webhookData, | ||
testData["signature"] as String, | ||
testData["secret"] as String | ||
) | ||
|
||
assertTrue(webhook is OrganizationMembershipUpdatedEvent) | ||
assertEquals(webhook.id, webhookId) | ||
assertEquals((webhook as OrganizationMembershipUpdatedEvent).data.id, organizationMembershipId) | ||
} | ||
} |