-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathservice.spec.ts
More file actions
67 lines (55 loc) · 2.02 KB
/
Copy pathservice.spec.ts
File metadata and controls
67 lines (55 loc) · 2.02 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
import { describe, expect, it, vi } from 'vitest';
import { createKeylessService, type KeylessAPI, type KeylessStorage } from '../service';
import type { AccountlessApplication } from '../types';
const accountlessApplication: AccountlessApplication = {
publishableKey: 'pk_test_keyless',
secretKey: 'sk_test_keyless',
claimUrl: 'https://dashboard.clerk.com/claim',
apiKeysUrl: 'https://dashboard.clerk.com/api-keys',
};
const createStorage = (): KeylessStorage => {
let value = '';
return {
read: vi.fn(() => value),
write: vi.fn(data => {
value = data;
}),
remove: vi.fn(() => {
value = '';
}),
};
};
describe('createKeylessService', () => {
it('passes the framework as the source when creating an accountless application', async () => {
const createAccountlessApplication = vi.fn<KeylessAPI['createAccountlessApplication']>(() =>
Promise.resolve(accountlessApplication),
);
const service = createKeylessService({
storage: createStorage(),
api: {
createAccountlessApplication,
completeOnboarding: vi.fn(() => Promise.resolve(accountlessApplication)),
},
framework: 'nextjs',
});
await service.getOrCreateKeys();
const [headers, source] = createAccountlessApplication.mock.calls[0];
expect(headers).toBeInstanceOf(Headers);
expect(source).toBe('nextjs');
});
it('passes the framework as the source when completing accountless application onboarding', async () => {
const completeOnboarding = vi.fn<KeylessAPI['completeOnboarding']>(() => Promise.resolve(accountlessApplication));
const service = createKeylessService({
storage: createStorage(),
api: {
createAccountlessApplication: vi.fn(() => Promise.resolve(accountlessApplication)),
completeOnboarding,
},
framework: 'nextjs',
});
await service.completeOnboarding();
const [headers, source] = completeOnboarding.mock.calls[0];
expect(headers).toBeInstanceOf(Headers);
expect(source).toBe('nextjs');
});
});