-
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.
Add organization membership events (#218)
Add organization membership events.
- Loading branch information
Showing
4 changed files
with
124 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/OrganizationMembershipEvent.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.*` events. | ||
*/ | ||
class OrganizationMembershipEvent( | ||
@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
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
package com.workos.test.webhooks | ||
|
||
import com.workos.test.TestBase | ||
import com.workos.webhooks.models.EventType | ||
import com.workos.webhooks.models.OrganizationMembershipEvent | ||
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 OrganizationMembershipEvent) | ||
assertEquals(webhook.id, webhookId) | ||
assertEquals((webhook as OrganizationMembershipEvent).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 OrganizationMembershipEvent) | ||
assertEquals(webhook.id, webhookId) | ||
assertEquals((webhook as OrganizationMembershipEvent).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 OrganizationMembershipEvent) | ||
assertEquals(webhook.id, webhookId) | ||
assertEquals((webhook as OrganizationMembershipEvent).data.id, organizationMembershipId) | ||
} | ||
} |