-
Notifications
You must be signed in to change notification settings - Fork 457
Expand file tree
/
Copy pathsessionTasks.test.ts
More file actions
77 lines (67 loc) · 2.32 KB
/
Copy pathsessionTasks.test.ts
File metadata and controls
77 lines (67 loc) · 2.32 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
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { warnPendingSessionStatus } from '../sessionTasks';
describe('warnPendingSessionStatus', () => {
let warnSpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
});
afterEach(() => {
warnSpy.mockRestore();
});
it('does not warn when status is active', () => {
warnPendingSessionStatus({ id: 'sess_active', status: 'active', currentTask: undefined as any });
expect(warnSpy).not.toHaveBeenCalled();
});
it('warns when status is pending and includes the session id', () => {
warnPendingSessionStatus({
id: 'sess_pending_1',
status: 'pending',
currentTask: { key: 'choose-organization' },
});
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy.mock.calls[0][0]).toContain('sess_pending_1');
expect(warnSpy.mock.calls[0][0]).toContain('pending');
});
it('includes the current task key in the message', () => {
warnPendingSessionStatus({
id: 'sess_pending_2',
status: 'pending',
currentTask: { key: 'choose-organization' },
});
expect(warnSpy.mock.calls[0][0]).toContain('choose-organization');
});
it('omits the tasks suffix when no current task is present', () => {
warnPendingSessionStatus({
id: 'sess_pending_3',
status: 'pending',
currentTask: undefined as any,
});
expect(warnSpy.mock.calls[0][0]).not.toContain('Remaining session tasks');
});
it('dedupes identical messages across calls', () => {
warnPendingSessionStatus({
id: 'sess_pending_dedupe',
status: 'pending',
currentTask: { key: 'choose-organization' },
});
warnPendingSessionStatus({
id: 'sess_pending_dedupe',
status: 'pending',
currentTask: { key: 'choose-organization' },
});
expect(warnSpy).toHaveBeenCalledTimes(1);
});
it('logs again when the task key changes within the same session', () => {
warnPendingSessionStatus({
id: 'sess_pending_task_change',
status: 'pending',
currentTask: { key: 'choose-organization' },
});
warnPendingSessionStatus({
id: 'sess_pending_task_change',
status: 'pending',
currentTask: { key: 'setup-mfa' },
});
expect(warnSpy).toHaveBeenCalledTimes(2);
});
});