-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathv2_temp_wf.test.ts
115 lines (99 loc) · 3.02 KB
/
v2_temp_wf.test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { DBOS, DBOSConfig } from '../src';
import { DBOSLocalCtx, runWithTopContext } from '../src/context';
import { generateDBOSTestConfig, setUpDBOSTestDb } from './helpers';
class TempWorkflowTest {
@DBOS.transaction()
static async tx_GetWorkflowID() {
return Promise.resolve(DBOS.workflowID);
}
@DBOS.step()
static async st_GetWorkflowID() {
return Promise.resolve(DBOS.workflowID);
}
@DBOS.transaction()
static async tx_GetAuth() {
return Promise.resolve({
user: DBOS.authenticatedUser,
roles: DBOS.authenticatedRoles,
});
}
@DBOS.step()
static async st_GetAuth() {
return Promise.resolve({
user: DBOS.authenticatedUser,
roles: DBOS.authenticatedRoles,
});
}
@DBOS.transaction()
static async tx_GetRequest() {
return Promise.resolve(DBOS.request);
}
@DBOS.step()
static async st_GetRequest() {
return Promise.resolve(DBOS.request);
}
}
describe('v2api-temp-wf', () => {
let config: DBOSConfig;
beforeAll(async () => {
config = generateDBOSTestConfig();
await setUpDBOSTestDb(config);
});
beforeEach(async () => {
DBOS.setConfig(config);
await DBOS.launch();
});
afterEach(async () => {
await DBOS.shutdown();
});
test('tx_GetWorkflowID', async () => {
const wfUUID = `tx-${Date.now()}`;
const actual = await DBOS.withNextWorkflowID(wfUUID, async () => {
return await TempWorkflowTest.tx_GetWorkflowID();
});
expect(actual).toBe(wfUUID);
});
test('st_GetWorkflowID', async () => {
const wfUUID = `st-${Date.now()}`;
const actual = await DBOS.withNextWorkflowID(wfUUID, async () => {
return await TempWorkflowTest.st_GetWorkflowID();
});
expect(actual).toBe(wfUUID);
});
test('tx_GetAuth', async () => {
const now = `${Date.now()}`;
const user = `user-${now}`;
const roles = [`role-1-${now}`, `role-2-${now}`, `role-3-${now}`];
const actual = await DBOS.withAuthedContext(user, roles, async () => {
return await TempWorkflowTest.tx_GetAuth();
});
expect(actual).toEqual({ user, roles });
});
test('st_GetAuth', async () => {
const now = `${Date.now()}`;
const user = `user-${now}`;
const roles = [`role-1-${now}`, `role-2-${now}`, `role-3-${now}`];
const actual = await DBOS.withAuthedContext(user, roles, async () => {
return await TempWorkflowTest.st_GetAuth();
});
expect(actual).toEqual({ user, roles });
});
test('tx_GetRequest', async () => {
const ctx: DBOSLocalCtx = {
request: { requestID: `requestID-${Date.now()}` },
};
const actual = await runWithTopContext(ctx, async () => {
return await TempWorkflowTest.tx_GetRequest();
});
expect(actual).toEqual(ctx.request);
});
test('st_GetRequest', async () => {
const ctx: DBOSLocalCtx = {
request: { requestID: `requestID-${Date.now()}` },
};
const actual = await runWithTopContext(ctx, async () => {
return await TempWorkflowTest.st_GetRequest();
});
expect(actual).toEqual(ctx.request);
});
});