-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathauthObjects.test.ts
More file actions
56 lines (49 loc) · 1.62 KB
/
authObjects.test.ts
File metadata and controls
56 lines (49 loc) · 1.62 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
import type { JwtPayload } from '@clerk/types';
import { describe, expect, it } from 'vitest';
import type { AuthenticateContext } from '../authenticateContext';
import {
authenticatedMachineObject,
makeAuthObjectSerializable,
signedInAuthObject,
signedOutAuthObject,
} from '../authObjects';
describe('makeAuthObjectSerializable', () => {
it('removes non-serializable props', () => {
const authObject = signedOutAuthObject();
const serializableAuthObject = makeAuthObjectSerializable(authObject);
for (const key in serializableAuthObject) {
expect(typeof serializableAuthObject[key]).not.toBe('function');
}
});
});
describe('signedInAuthObject', () => {
it('getToken returns the token passed in', async () => {
const mockAuthenticateContext = { sessionToken: 'authContextToken' } as AuthenticateContext;
const authObject = signedInAuthObject(mockAuthenticateContext, 'token', {
act: 'actor',
sid: 'sessionId',
org_id: 'orgId',
org_role: 'orgRole',
org_slug: 'orgSlug',
org_permissions: 'orgPermissions',
sub: 'userId',
} as unknown as JwtPayload);
const token = await authObject.getToken();
expect(token).toBe('token');
});
});
describe('authenticatedMachineObject', () => {
it('getToken returns the token passed in', () => {
const authObject = authenticatedMachineObject('token', {
act: null,
sid: null,
org_id: null,
org_role: null,
org_slug: null,
org_permissions: null,
sub: 'mch_id',
} as unknown as JwtPayload);
const token = authObject.getToken();
expect(token).toBe('token');
});
});