-
Notifications
You must be signed in to change notification settings - Fork 0
/
threshold.spec.ts
113 lines (102 loc) · 4.02 KB
/
threshold.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
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
import { test, expect } from '@playwright/test';
import axios from 'axios';
import {
createTemporalClient,
getWorkflowHandle,
} from '../utils/temporal';
import { config } from '../utils/config';
import { setupClientAndScheduleStores, setupTemporal, trashTemporal } from '../utils/setup-temporal';
test.describe('threshold', () => {
const {
minioClient,
scheduleIds,
scheduleHandles,
workflowIds,
} = setupClientAndScheduleStores();
// eslint-disable-next-line no-empty-pattern
test.beforeEach(async ({}, testInfo) => {
const {
scheduleId,
scheduleHandle,
workflowId,
} = await setupTemporal({
name: testInfo.title,
s3Client: minioClient,
duration: '1 minute',
docMapThreshold: 1,
});
scheduleIds[testInfo.title] = scheduleId;
scheduleHandles[testInfo.title] = scheduleHandle;
workflowIds[testInfo.title] = workflowId;
});
// eslint-disable-next-line no-empty-pattern
test.afterEach(async ({}, testInfo) => {
await Promise.all([
trashTemporal({
name: testInfo.title,
s3Client: minioClient,
scheduleId: scheduleIds[testInfo.title],
}),
// Because this is idempotent we can run for reject and approve.
trashTemporal({
name: testInfo.title,
s3Client: minioClient,
msid: `${testInfo.title}-msid-2`,
}),
]);
});
[
{
// test docmap threshold triggers workflow pause.
name: 'reject',
expectation: async (name: string) => {
const workflowHandle = getWorkflowHandle(workflowIds[name], await createTemporalClient());
// Wait for threshold pause to commence and check output.
await expect(async () => {
const response = await workflowHandle.query<{ awaitingApproval: number, docMapUrls: string[] }>('awaitingApproval');
expect(response.docMapUrls).not.toBeNull();
expect(response.docMapUrls).toHaveLength(2);
}).toPass();
// Send approval signal with value of false.
await workflowHandle.signal('approval', false);
await expect(async () => {
const workflowStatus = await workflowHandle.describe().then((wf) => wf.status.name);
expect(workflowStatus).toBe('COMPLETED');
}).toPass();
// Confirm no longer awaiting approval.
const response = await workflowHandle.query('awaitingApproval');
expect(response).toBeNull();
},
},
{
// test import continues when approval signal true.
name: 'approve',
expectation: async (name: string) => {
const workflowHandle = getWorkflowHandle(workflowIds[name], await createTemporalClient());
// Wait for threshold pause to commence and check output.
await expect(async () => {
const response = await workflowHandle.query<{ awaitingApproval: number, docMapUrls: string[] }>('awaitingApproval');
expect(response.docMapUrls).not.toBeNull();
expect(response.docMapUrls).toHaveLength(2);
}).toPass();
// Send approval signal with value of true.
await workflowHandle.signal('approval', true);
await expect(async () => {
const workflowStatus = await workflowHandle.describe().then((wf) => wf.status.name);
expect(workflowStatus).toBe('COMPLETED');
}).toPass();
// Confirm no longer awaiting approval.
const response = await getWorkflowHandle(workflowIds[name], await createTemporalClient()).query('awaitingApproval');
expect(response).toBeNull();
// Check previews available on server.
expect((await axios.get(`${config.api_url}/api/preprints/${name}-msidv1?previews`).then((r) => r.status))).toBe(200);
expect((await axios.get(`${config.api_url}/api/preprints/${name}-msid-2v1?previews`).then((r) => r.status))).toBe(200);
},
},
].forEach(({ name, expectation }) => {
// eslint-disable-next-line no-empty-pattern
test(`threshold--${name}`, async ({}, testInfo) => {
await expectation(testInfo.title);
});
});
});