Skip to content

Commit eb82686

Browse files
committed
Add tests
1 parent fecc8b1 commit eb82686

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { http, HttpResponse } from 'msw';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import { server, validateHeaders } from '../../mock-server';
5+
import { createBackendApiClient } from '../factory';
6+
7+
describe('EnterpriseConnectionAPI', () => {
8+
const apiClient = createBackendApiClient({
9+
apiUrl: 'https://api.clerk.test',
10+
secretKey: 'deadbeef',
11+
});
12+
13+
const mockEnterpriseConnectionResponse = {
14+
object: 'enterprise_connection',
15+
id: 'entconn_123',
16+
name: 'Clerk',
17+
provider: 'saml_custom',
18+
domains: ['clerk.dev'],
19+
organization_id: null,
20+
created_at: 1672531200000,
21+
updated_at: 1672531200000,
22+
active: true,
23+
sync_user_attributes: false,
24+
};
25+
26+
describe('createEnterpriseConnection', () => {
27+
it('sends nested saml params in snake_case', async () => {
28+
server.use(
29+
http.post(
30+
'https://api.clerk.test/v1/enterprise_connections',
31+
validateHeaders(async ({ request }) => {
32+
const body = (await request.json()) as Record<string, unknown>;
33+
34+
expect(body.name).toBe('Clerk');
35+
expect(body.domains).toEqual(['clerk.dev']);
36+
expect(body.saml).toEqual({
37+
idp_entity_id: 'xxx',
38+
idp_metadata_url: 'https://oauth.devsuccess.app/metadata',
39+
idp_sso_url: 'https://oauth.devsuccess.app/sso',
40+
});
41+
42+
return HttpResponse.json(mockEnterpriseConnectionResponse);
43+
}),
44+
),
45+
);
46+
47+
await apiClient.enterpriseConnections.createEnterpriseConnection({
48+
name: 'Clerk',
49+
domains: ['clerk.dev'],
50+
saml: {
51+
idpEntityId: 'xxx',
52+
idpMetadataUrl: 'https://oauth.devsuccess.app/metadata',
53+
idpSsoUrl: 'https://oauth.devsuccess.app/sso',
54+
},
55+
});
56+
});
57+
58+
it('sends nested oidc params', async () => {
59+
server.use(
60+
http.post(
61+
'https://api.clerk.test/v1/enterprise_connections',
62+
validateHeaders(async ({ request }) => {
63+
const body = (await request.json()) as Record<string, unknown>;
64+
65+
expect(body.oidc).toEqual({
66+
discovery_url: 'https://oidc.example.com/.well-known/openid-configuration',
67+
client_id: 'client_123',
68+
client_secret: 'secret_456',
69+
auth_url: 'https://oidc.example.com/authorize',
70+
token_url: 'https://oidc.example.com/token',
71+
user_info_url: 'https://oidc.example.com/userinfo',
72+
requires_pkce: true,
73+
});
74+
75+
return HttpResponse.json(mockEnterpriseConnectionResponse);
76+
}),
77+
),
78+
);
79+
80+
await apiClient.enterpriseConnections.createEnterpriseConnection({
81+
name: 'OIDC Connection',
82+
domains: ['example.com'],
83+
oidc: {
84+
discoveryUrl: 'https://oidc.example.com/.well-known/openid-configuration',
85+
clientId: 'client_123',
86+
clientSecret: 'secret_456',
87+
authUrl: 'https://oidc.example.com/authorize',
88+
tokenUrl: 'https://oidc.example.com/token',
89+
userInfoUrl: 'https://oidc.example.com/userinfo',
90+
requiresPkce: true,
91+
},
92+
});
93+
});
94+
});
95+
96+
describe('updateEnterpriseConnection', () => {
97+
it('sends nested saml params', async () => {
98+
server.use(
99+
http.patch(
100+
'https://api.clerk.test/v1/enterprise_connections/entconn_123',
101+
validateHeaders(async ({ request }) => {
102+
const body = (await request.json()) as Record<string, unknown>;
103+
104+
expect(body).toHaveProperty('saml');
105+
expect((body.saml as Record<string, unknown>).idp_entity_id).toBe('updated_entity');
106+
expect((body.saml as Record<string, unknown>).idp_metadata_url).toBe(
107+
'https://updated.example.com/metadata',
108+
);
109+
110+
return HttpResponse.json(mockEnterpriseConnectionResponse);
111+
}),
112+
),
113+
);
114+
115+
await apiClient.enterpriseConnections.updateEnterpriseConnection('entconn_123', {
116+
saml: {
117+
idpEntityId: 'updated_entity',
118+
idpMetadataUrl: 'https://updated.example.com/metadata',
119+
},
120+
});
121+
});
122+
});
123+
});

0 commit comments

Comments
 (0)