-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrigger_workflow.test.js
More file actions
141 lines (115 loc) · 3.7 KB
/
retrigger_workflow.test.js
File metadata and controls
141 lines (115 loc) · 3.7 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import assert from "node:assert/strict";
import { describe, it } from "node:test";
const { default: component } = await import("./retrigger_workflow.js");
describe("Retrigger Workflow", () => {
it("should call workflow (as POST) when datastore has keys", async () => {
globalThis.__axiosCalls = [];
const mockDatastore = {
async keys() {
return ["key1", "key2"];
},
};
component.dev_datastore = mockDatastore;
component.workflow_url = "https://example.com/workflow";
component.headers = {
authorization: "Bearer test-token",
};
component.is_prod = false;
component.current_key = "different-key";
await component.run({ steps: {}, $: {} });
assert.equal(globalThis.__axiosCalls.length, 1);
assert.equal(globalThis.__axiosCalls[0].method, 'POST');
assert.equal(
globalThis.__axiosCalls[0].url,
"https://example.com/workflow",
);
});
it("should not call workflow when no DEV keys remain (for not-prod)", async () => {
globalThis.__axiosCalls = [];
const mockDevDataStore = {
async keys() {
return [];
},
};
const mockProdDataStore = {
async keys() {
return ["key2", "key3"];
},
};
component.dev_datastore = mockDevDataStore;
component.prod_datastore = mockProdDataStore;
component.is_prod = false;
component.current_key = "key1";
await component.run({ steps: {}, $: {} });
assert.equal(globalThis.__axiosCalls.length, 0);
});
it("should not call workflow when no PROD keys remain (for prod)", async () => {
globalThis.__axiosCalls = [];
const mockDevDataStore = {
async keys() {
return ["key2", "key3"];
},
};
const mockProdDataStore = {
async keys() {
return [];
},
};
component.dev_datastore = mockDevDataStore;
component.prod_datastore = mockProdDataStore;
component.is_prod = true;
component.current_key = "key1";
await component.run({ steps: {}, $: {} });
assert.equal(globalThis.__axiosCalls.length, 0);
});
it("should throw error on infinite loop detection", async () => {
const mockDatastore = {
async keys() {
return ["key-1", "loop-key", "key-2"];
},
};
component.dev_datastore = mockDatastore;
component.is_prod = false;
component.current_key = "loop-key";
await assert.rejects(async () => {
await component.run({ steps: {}, $: {} });
}, /Infinite loop detected/);
});
it("should pass through only the specified headers (case-insensitive)", async () => {
globalThis.__axiosCalls = [];
const mockDatastore = {
async keys() {
return ["key1", "key2"];
},
};
component.dev_datastore = mockDatastore;
component.workflow_url = "https://example.com/workflow";
component.headers = {
authorization: "Bearer test-token",
'x-is-production': 'false',
'User-Agent': 'Dummy User Agent',
'x-UPPERCASE-test': 'dummy value',
};
component.headers_to_pass_through = [
'x-uppercase-TEST', // Use different capitalization from actual header.
'authorization',
'x-is-production',
]
component.is_prod = false;
component.current_key = "different-key";
await component.run({ steps: {}, $: {} });
assert.equal(globalThis.__axiosCalls.length, 1);
assert.equal(
globalThis.__axiosCalls[0].url,
"https://example.com/workflow",
);
assert.equal(
JSON.stringify(globalThis.__axiosCalls[0].headers),
JSON.stringify({
authorization: "Bearer test-token",
'x-is-production': 'false',
'x-UPPERCASE-test': 'dummy value', // Result should match the actual header.
})
)
});
});