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