|
| 1 | +from typing import Union |
| 2 | +import pytest |
| 3 | +from tests.utils.syncify import syncify |
| 4 | +from workos.organization_domains import AsyncOrganizationDomains, OrganizationDomains |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.sync_and_async(OrganizationDomains, AsyncOrganizationDomains) |
| 8 | +class TestOrganizationDomains: |
| 9 | + @pytest.fixture(autouse=True) |
| 10 | + def setup( |
| 11 | + self, module_instance: Union[OrganizationDomains, AsyncOrganizationDomains] |
| 12 | + ): |
| 13 | + self.http_client = module_instance._http_client |
| 14 | + self.organization_domains = module_instance |
| 15 | + |
| 16 | + @pytest.fixture |
| 17 | + def mock_organization_domain(self): |
| 18 | + return { |
| 19 | + "object": "organization_domain", |
| 20 | + "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8", |
| 21 | + "organization_id": "org_01EHT88Z8J8795GZNQ4ZP1J81T", |
| 22 | + "domain": "example.com", |
| 23 | + "state": "pending", |
| 24 | + "verification_strategy": "dns", |
| 25 | + "verification_token": "workos_example_verification_token_12345", |
| 26 | + "verification_prefix": "_workos-challenge", |
| 27 | + "created_at": "2023-01-01T12:00:00.000Z", |
| 28 | + "updated_at": "2023-01-01T12:00:00.000Z", |
| 29 | + } |
| 30 | + |
| 31 | + @pytest.fixture |
| 32 | + def mock_organization_domain_verified(self): |
| 33 | + return { |
| 34 | + "object": "organization_domain", |
| 35 | + "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8", |
| 36 | + "organization_id": "org_01EHT88Z8J8795GZNQ4ZP1J81T", |
| 37 | + "domain": "example.com", |
| 38 | + "state": "verified", |
| 39 | + "verification_strategy": "dns", |
| 40 | + "verification_token": "workos_example_verification_token_12345", |
| 41 | + "verification_prefix": "_workos-challenge", |
| 42 | + "created_at": "2023-01-01T12:00:00.000Z", |
| 43 | + "updated_at": "2023-01-01T12:00:00.000Z", |
| 44 | + } |
| 45 | + |
| 46 | + def test_get_organization_domain( |
| 47 | + self, capture_and_mock_http_client_request, mock_organization_domain |
| 48 | + ): |
| 49 | + request_kwargs = capture_and_mock_http_client_request( |
| 50 | + self.http_client, |
| 51 | + mock_organization_domain, |
| 52 | + 200, |
| 53 | + ) |
| 54 | + |
| 55 | + organization_domain = syncify( |
| 56 | + self.organization_domains.get_organization_domain( |
| 57 | + organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 58 | + ) |
| 59 | + ) |
| 60 | + |
| 61 | + assert request_kwargs["url"].endswith( |
| 62 | + "/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 63 | + ) |
| 64 | + assert request_kwargs["method"] == "get" |
| 65 | + assert organization_domain.id == "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 66 | + assert organization_domain.domain == "example.com" |
| 67 | + assert organization_domain.state == "pending" |
| 68 | + assert organization_domain.verification_strategy == "dns" |
| 69 | + |
| 70 | + def test_create_organization_domain( |
| 71 | + self, capture_and_mock_http_client_request, mock_organization_domain |
| 72 | + ): |
| 73 | + request_kwargs = capture_and_mock_http_client_request( |
| 74 | + self.http_client, |
| 75 | + mock_organization_domain, |
| 76 | + 201, |
| 77 | + ) |
| 78 | + |
| 79 | + organization_domain = syncify( |
| 80 | + self.organization_domains.create_organization_domain( |
| 81 | + organization_id="org_01EHT88Z8J8795GZNQ4ZP1J81T", |
| 82 | + domain="example.com", |
| 83 | + ) |
| 84 | + ) |
| 85 | + |
| 86 | + assert request_kwargs["url"].endswith("/organization_domains") |
| 87 | + assert request_kwargs["method"] == "post" |
| 88 | + assert request_kwargs["json"] == { |
| 89 | + "organization_id": "org_01EHT88Z8J8795GZNQ4ZP1J81T", |
| 90 | + "domain": "example.com", |
| 91 | + } |
| 92 | + assert organization_domain.id == "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 93 | + assert organization_domain.domain == "example.com" |
| 94 | + assert organization_domain.organization_id == "org_01EHT88Z8J8795GZNQ4ZP1J81T" |
| 95 | + |
| 96 | + def test_verify_organization_domain( |
| 97 | + self, capture_and_mock_http_client_request, mock_organization_domain_verified |
| 98 | + ): |
| 99 | + request_kwargs = capture_and_mock_http_client_request( |
| 100 | + self.http_client, |
| 101 | + mock_organization_domain_verified, |
| 102 | + 200, |
| 103 | + ) |
| 104 | + |
| 105 | + organization_domain = syncify( |
| 106 | + self.organization_domains.verify_organization_domain( |
| 107 | + organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 108 | + ) |
| 109 | + ) |
| 110 | + |
| 111 | + assert request_kwargs["url"].endswith( |
| 112 | + "/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8/verify" |
| 113 | + ) |
| 114 | + assert request_kwargs["method"] == "post" |
| 115 | + assert organization_domain.id == "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 116 | + assert organization_domain.state == "verified" |
| 117 | + |
| 118 | + def test_delete_organization_domain(self, capture_and_mock_http_client_request): |
| 119 | + request_kwargs = capture_and_mock_http_client_request( |
| 120 | + self.http_client, |
| 121 | + None, |
| 122 | + 204, |
| 123 | + headers={"content-type": "text/plain; charset=utf-8"}, |
| 124 | + ) |
| 125 | + |
| 126 | + response = syncify( |
| 127 | + self.organization_domains.delete_organization_domain( |
| 128 | + organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 129 | + ) |
| 130 | + ) |
| 131 | + |
| 132 | + assert request_kwargs["url"].endswith( |
| 133 | + "/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8" |
| 134 | + ) |
| 135 | + assert request_kwargs["method"] == "delete" |
| 136 | + assert response is None |
0 commit comments