-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathAccountlessApplicationsApi.test.ts
More file actions
99 lines (77 loc) · 3.51 KB
/
Copy pathAccountlessApplicationsApi.test.ts
File metadata and controls
99 lines (77 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { http, HttpResponse } from 'msw';
import { describe, expect, it } from 'vitest';
import { server } from '../../mock-server';
import { createBackendApiClient } from '../factory';
describe('AccountlessApplications', () => {
const mockAccountlessApplication = {
object: 'accountless_application',
publishable_key: 'pk_test_keyless',
secret_key: 'sk_test_keyless',
claim_url: 'https://dashboard.clerk.com/claim',
api_keys_url: 'https://dashboard.clerk.com/api-keys',
};
it('creates an accountless application with a source query parameter', async () => {
const apiClient = createBackendApiClient({
apiUrl: 'https://api.clerk.test',
});
server.use(
http.post('https://api.clerk.test/v1/accountless_applications', ({ request }) => {
const url = new URL(request.url);
expect(url.searchParams.get('source')).toBe('nextjs');
expect(request.headers.get('Clerk-API-Version')).toBeTruthy();
expect(request.headers.get('User-Agent')).toBe('@clerk/backend@0.0.0-test');
return HttpResponse.json(mockAccountlessApplication);
}),
);
const response = await apiClient.__experimental_accountlessApplications.createAccountlessApplication({
source: 'nextjs',
});
expect(response.publishableKey).toBe('pk_test_keyless');
});
it('creates an accountless application without a source query parameter when source is omitted', async () => {
const apiClient = createBackendApiClient({
apiUrl: 'https://api.clerk.test',
});
server.use(
http.post('https://api.clerk.test/v1/accountless_applications', ({ request }) => {
const url = new URL(request.url);
expect(url.searchParams.has('source')).toBe(false);
return HttpResponse.json(mockAccountlessApplication);
}),
);
const response = await apiClient.__experimental_accountlessApplications.createAccountlessApplication();
expect(response.publishableKey).toBe('pk_test_keyless');
});
it('completes accountless application onboarding with a source query parameter', async () => {
const apiClient = createBackendApiClient({
apiUrl: 'https://api.clerk.test',
});
server.use(
http.post('https://api.clerk.test/v1/accountless_applications/complete', ({ request }) => {
const url = new URL(request.url);
expect(url.searchParams.get('source')).toBe('nextjs');
expect(request.headers.get('Clerk-API-Version')).toBeTruthy();
expect(request.headers.get('User-Agent')).toBe('@clerk/backend@0.0.0-test');
return HttpResponse.json(mockAccountlessApplication);
}),
);
const response = await apiClient.__experimental_accountlessApplications.completeAccountlessApplicationOnboarding({
source: 'nextjs',
});
expect(response.publishableKey).toBe('pk_test_keyless');
});
it('completes accountless application onboarding without a source query parameter when source is omitted', async () => {
const apiClient = createBackendApiClient({
apiUrl: 'https://api.clerk.test',
});
server.use(
http.post('https://api.clerk.test/v1/accountless_applications/complete', ({ request }) => {
const url = new URL(request.url);
expect(url.searchParams.has('source')).toBe(false);
return HttpResponse.json(mockAccountlessApplication);
}),
);
const response = await apiClient.__experimental_accountlessApplications.completeAccountlessApplicationOnboarding();
expect(response.publishableKey).toBe('pk_test_keyless');
});
});