-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathactions.spec.ts
71 lines (63 loc) · 2.16 KB
/
actions.spec.ts
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
import {
checkSessionAction,
handleSignOutAction,
getOrganizationAction,
getAuthAction,
refreshAuthAction,
} from '../src/actions.js';
import { signOut } from '../src/auth.js';
import { getWorkOS } from '../src/workos.js';
import { withAuth, refreshSession } from '../src/session.js';
jest.mock('../src/auth.js', () => ({
signOut: jest.fn().mockResolvedValue(true),
}));
const fakeWorkosInstance = {
organizations: {
getOrganization: jest.fn().mockResolvedValue({ id: 'org_123', name: 'Test Org' }),
},
};
jest.mock('../src/workos.js', () => ({
getWorkOS: jest.fn(() => fakeWorkosInstance),
}));
jest.mock('../src/session.js', () => ({
withAuth: jest.fn().mockResolvedValue({ user: 'testUser' }),
refreshSession: jest.fn().mockResolvedValue({ session: 'newSession' }),
}));
describe('actions', () => {
const workos = getWorkOS();
describe('checkSessionAction', () => {
it('should return true for authenticated users', async () => {
const result = await checkSessionAction();
expect(result).toBe(true);
});
});
describe('handleSignOutAction', () => {
it('should call signOut', async () => {
await handleSignOutAction();
expect(signOut).toHaveBeenCalled();
});
});
describe('getOrganizationAction', () => {
it('should return organization details', async () => {
const organizationId = 'org_123';
const result = await getOrganizationAction(organizationId);
expect(workos.organizations.getOrganization).toHaveBeenCalledWith(organizationId);
expect(result).toEqual({ id: 'org_123', name: 'Test Org' });
});
});
describe('getAuthAction', () => {
it('should return auth details', async () => {
const result = await getAuthAction();
expect(withAuth).toHaveBeenCalled();
expect(result).toEqual({ user: 'testUser' });
});
});
describe('refreshAuthAction', () => {
it('should refresh session', async () => {
const params = { ensureSignedIn: true, organizationId: 'org_123' };
const result = await refreshAuthAction(params);
expect(refreshSession).toHaveBeenCalledWith(params);
expect(result).toEqual({ session: 'newSession' });
});
});
});