|
1 | 1 | import fetch from 'jest-fetch-mock'; |
2 | | -import { fetchOnce, fetchSearchParams } from '../common/utils/test-utils'; |
| 2 | +import {fetchOnce, fetchSearchParams} from '../common/utils/test-utils'; |
3 | 3 | import { |
4 | | - DsyncUserUpdatedEvent, |
5 | | - DsyncUserUpdatedEventResponse, |
6 | | - Event, |
7 | | - EventResponse, |
8 | | - FlagCreatedEvent, |
9 | | - FlagCreatedEventResponse, |
10 | | - ListResponse, |
11 | | - VaultDataCreatedEvent, |
12 | | - VaultDataCreatedEventResponse, |
13 | | - VaultDataUpdatedEvent, |
14 | | - VaultDataUpdatedEventResponse, |
15 | | - VaultDataReadEvent, |
16 | | - VaultDataReadEventResponse, |
17 | | - VaultDataDeletedEvent, |
18 | | - VaultDataDeletedEventResponse, |
19 | | - VaultNamesListedEvent, |
20 | | - VaultNamesListedEventResponse, |
21 | | - VaultMetadataReadEvent, |
22 | | - VaultMetadataReadEventResponse, |
23 | | - VaultKekCreatedEvent, |
24 | | - VaultKekCreatedEventResponse, |
25 | | - VaultDekReadEvent, |
26 | | - VaultDekReadEventResponse, |
27 | | - VaultDekDecryptedEvent, |
28 | | - VaultDekDecryptedEventResponse, |
| 4 | + DsyncUserUpdatedEvent, |
| 5 | + DsyncUserUpdatedEventResponse, |
| 6 | + Event, |
| 7 | + EventResponse, |
| 8 | + FlagCreatedEvent, |
| 9 | + FlagCreatedEventResponse, |
| 10 | + ListResponse, |
| 11 | + OrganizationDomainCreatedEvent, |
| 12 | + OrganizationDomainCreatedEventResponse, |
| 13 | + OrganizationDomainVerificationFailedEvent, |
| 14 | + OrganizationDomainVerificationFailedEventResponse, |
| 15 | + VaultDataCreatedEvent, |
| 16 | + VaultDataCreatedEventResponse, |
| 17 | + VaultDataDeletedEvent, |
| 18 | + VaultDataDeletedEventResponse, |
| 19 | + VaultDataReadEvent, |
| 20 | + VaultDataReadEventResponse, |
| 21 | + VaultDataUpdatedEvent, |
| 22 | + VaultDataUpdatedEventResponse, |
| 23 | + VaultDekDecryptedEvent, |
| 24 | + VaultDekDecryptedEventResponse, |
| 25 | + VaultDekReadEvent, |
| 26 | + VaultDekReadEventResponse, |
| 27 | + VaultKekCreatedEvent, |
| 28 | + VaultKekCreatedEventResponse, |
| 29 | + VaultMetadataReadEvent, |
| 30 | + VaultMetadataReadEventResponse, |
| 31 | + VaultNamesListedEvent, |
| 32 | + VaultNamesListedEventResponse, |
29 | 33 | } from '../common/interfaces'; |
30 | | -import { WorkOS } from '../workos'; |
31 | | -import { ConnectionType } from '../sso/interfaces'; |
| 34 | +import {WorkOS} from '../workos'; |
| 35 | +import {ConnectionType} from '../sso/interfaces'; |
| 36 | +import {OrganizationDomainState, OrganizationDomainVerificationStrategy} from "../organization-domains/interfaces"; |
32 | 37 |
|
33 | 38 | describe('Event', () => { |
34 | 39 | beforeEach(() => fetch.resetMocks()); |
@@ -693,5 +698,119 @@ describe('Event', () => { |
693 | 698 | }); |
694 | 699 | }); |
695 | 700 | }); |
| 701 | + |
| 702 | + describe('organization domain events', () => { |
| 703 | + it('deserializes organization_domain.created events', async () => { |
| 704 | + const response: OrganizationDomainCreatedEventResponse = { |
| 705 | + "event": "organization_domain.created", |
| 706 | + "id": "event_01DOMAINCREATED001", |
| 707 | + "data": { |
| 708 | + "id": "org_domain_01TESTDOMAIN", |
| 709 | + "state": OrganizationDomainState.Pending, |
| 710 | + "domain": "example.com", |
| 711 | + "object": "organization_domain", |
| 712 | + "created_at": "2026-04-06T06:24:06.749Z", |
| 713 | + "updated_at": "2026-04-06T06:24:06.749Z", |
| 714 | + "organization_id": "org_01TESTORGANIZATION", |
| 715 | + "verification_strategy": OrganizationDomainVerificationStrategy.Manual, |
| 716 | + }, |
| 717 | + "context": {}, |
| 718 | + "created_at": "2026-04-06T06:24:06.776Z" |
| 719 | + }; |
| 720 | + |
| 721 | + const expected: OrganizationDomainCreatedEvent = { |
| 722 | + "event": "organization_domain.created", |
| 723 | + "id": "event_01DOMAINCREATED001", |
| 724 | + "data": { |
| 725 | + "id": "org_domain_01TESTDOMAIN", |
| 726 | + "state": OrganizationDomainState.Pending, |
| 727 | + "domain": "example.com", |
| 728 | + "object": "organization_domain", |
| 729 | + "createdAt": "2026-04-06T06:24:06.749Z", |
| 730 | + "updatedAt": "2026-04-06T06:24:06.749Z", |
| 731 | + "organizationId": "org_01TESTORGANIZATION", |
| 732 | + "verificationStrategy": OrganizationDomainVerificationStrategy.Manual, |
| 733 | + }, |
| 734 | + "context": {}, |
| 735 | + "createdAt": "2026-04-06T06:24:06.776Z" |
| 736 | + }; |
| 737 | + |
| 738 | + fetchOnce({ |
| 739 | + object: 'list', |
| 740 | + data: [response], |
| 741 | + list_metadata: {}, |
| 742 | + }); |
| 743 | + |
| 744 | + const list = await workos.events.listEvents({ |
| 745 | + events: ['organization_domain.created'], |
| 746 | + }); |
| 747 | + |
| 748 | + expect(list).toEqual({ |
| 749 | + object: 'list', |
| 750 | + data: [expected], |
| 751 | + listMetadata: {}, |
| 752 | + }); |
| 753 | + }); |
| 754 | + |
| 755 | + it('deserializes organization_domain.verification_failed events', async () => { |
| 756 | + const response: OrganizationDomainVerificationFailedEventResponse = { |
| 757 | + "event": "organization_domain.verification_failed", |
| 758 | + "id": "event_01DOMAIN0002", |
| 759 | + "data": { |
| 760 | + "reason": "domain_verification_period_expired", |
| 761 | + "organization_domain": { |
| 762 | + "id": "org_domain_0TESTDOMAIN", |
| 763 | + "state": OrganizationDomainState.Failed, |
| 764 | + "domain": "example.com", |
| 765 | + "object": "organization_domain", |
| 766 | + "created_at": "2026-03-07T02:24:56.621Z", |
| 767 | + "updated_at": "2026-04-06T02:25:00.494Z", |
| 768 | + "organization_id": "org_01TESTORGANIZATION", |
| 769 | + "verification_token": "FAKETOKEN", |
| 770 | + "verification_strategy": OrganizationDomainVerificationStrategy.Dns |
| 771 | + } |
| 772 | + }, |
| 773 | + "context": {}, |
| 774 | + "created_at": "2026-04-06T02:26:05.430Z" |
| 775 | + }; |
| 776 | + |
| 777 | + const expected: OrganizationDomainVerificationFailedEvent = { |
| 778 | + "event": "organization_domain.verification_failed", |
| 779 | + "id": "event_01DOMAIN0002", |
| 780 | + "data": { |
| 781 | + "reason": "domain_verification_period_expired", |
| 782 | + "organizationDomain": { |
| 783 | + "id": "org_domain_0TESTDOMAIN", |
| 784 | + "state": OrganizationDomainState.Failed, |
| 785 | + "domain": "example.com", |
| 786 | + "object": "organization_domain", |
| 787 | + "createdAt": "2026-03-07T02:24:56.621Z", |
| 788 | + "updatedAt": "2026-04-06T02:25:00.494Z", |
| 789 | + "organizationId": "org_01TESTORGANIZATION", |
| 790 | + "verificationToken": "FAKETOKEN", |
| 791 | + "verificationStrategy": OrganizationDomainVerificationStrategy.Dns |
| 792 | + } |
| 793 | + }, |
| 794 | + "context": {}, |
| 795 | + "createdAt": "2026-04-06T02:26:05.430Z" |
| 796 | + }; |
| 797 | + |
| 798 | + fetchOnce({ |
| 799 | + object: 'list', |
| 800 | + data: [response], |
| 801 | + list_metadata: {}, |
| 802 | + }); |
| 803 | + |
| 804 | + const list = await workos.events.listEvents({ |
| 805 | + events: ['organization_domain.verification_failed'], |
| 806 | + }); |
| 807 | + |
| 808 | + expect(list).toEqual({ |
| 809 | + object: 'list', |
| 810 | + data: [expected], |
| 811 | + listMetadata: {}, |
| 812 | + }); |
| 813 | + }); |
| 814 | + }); |
696 | 815 | }); |
697 | 816 | }); |
0 commit comments