-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathfactory.test.ts
More file actions
86 lines (75 loc) · 2.42 KB
/
factory.test.ts
File metadata and controls
86 lines (75 loc) · 2.42 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
import { describe, expect, it } from 'vitest';
import type { ApiClient } from '../../api';
import { createAuthenticateRequest } from '../factory';
const TEST_PK = 'pk_test_Y2xlcmsuaW5jbHVkZWQua2F0eWRpZC05Mi5sY2wuZGV2JA';
describe('createAuthenticateRequest({ options, apiClient })', () => {
it('fallbacks to build-time options', async () => {
const buildTimeOptions = {
secretKey: 'sk',
jwtKey: 'jwtKey',
apiUrl: 'apiUrl',
apiVersion: 'apiVersion',
proxyUrl: 'proxyUrl',
publishableKey: TEST_PK,
isSatellite: false,
domain: 'domain',
audience: 'domain',
};
const { authenticateRequest } = createAuthenticateRequest({
options: buildTimeOptions,
apiClient: {} as ApiClient,
});
const requestState = await authenticateRequest(new Request('http://example.com/'));
expect(requestState.toAuth()?.debug()).toMatchObject(buildTimeOptions);
});
it('overrides build-time options with runtime options', async () => {
const buildTimeOptions = {
secretKey: 'sk',
jwtKey: 'jwtKey',
apiUrl: 'apiUrl',
apiVersion: 'apiVersion',
proxyUrl: 'proxyUrl',
publishableKey: TEST_PK,
isSatellite: false,
domain: 'domain',
audience: 'domain',
};
const { authenticateRequest } = createAuthenticateRequest({
options: buildTimeOptions,
apiClient: {} as ApiClient,
});
const overrides = {
secretKey: 'r-sk',
publishableKey: TEST_PK,
};
const requestState = await authenticateRequest(new Request('http://example.com/'), {
...overrides,
});
expect(requestState.toAuth()?.debug()).toMatchObject({
...buildTimeOptions,
...overrides,
});
});
it('ignore runtime apiUrl and apiVersion options', async () => {
const buildTimeOptions = {
secretKey: 'sk',
jwtKey: 'jwtKey',
apiUrl: 'apiUrl',
apiVersion: 'apiVersion',
proxyUrl: 'proxyUrl',
publishableKey: TEST_PK,
isSatellite: false,
domain: 'domain',
audience: 'domain',
};
const { authenticateRequest } = createAuthenticateRequest({
options: buildTimeOptions,
apiClient: {} as ApiClient,
});
const requestState = await authenticateRequest(new Request('http://example.com/'), {
apiUrl: 'r-apiUrl',
apiVersion: 'r-apiVersion',
});
expect(requestState.toAuth()?.debug()).toMatchObject(buildTimeOptions);
});
});