@intuned/runtime-dev 1.2.0-dev-peer → 1.2.1-hooks.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +2 -2
- package/.npmrc.wtf +1 -0
- package/CHANGELOG.md +5 -1
- package/WebTemplate.zip +0 -0
- package/bin/intuned +2 -0
- package/dist/commands/api/run.js +10 -3
- package/dist/commands/auth-sessions/run-check.js +18 -4
- package/dist/commands/auth-sessions/run-create.js +2 -1
- package/dist/commands/common/browserUtils.d.ts +1 -1
- package/dist/commands/common/browserUtils.js +1 -1
- package/dist/commands/common/getFirstLineNumber.js +2 -4
- package/dist/commands/interface/run.js +7 -6
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
- package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/build.command.js +12 -0
- package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
- package/dist/commands/intuned-cli/commands/command.js +9 -0
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/deploy.command.js +46 -0
- package/dist/commands/intuned-cli/commands/index.d.ts +15 -0
- package/dist/commands/intuned-cli/commands/index.js +170 -0
- package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/init.command.js +13 -0
- package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run.command.js +8 -0
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +20 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
- package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
- package/dist/commands/intuned-cli/commands/types.js +21 -0
- package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
- package/dist/commands/intuned-cli/constants/index.js +25 -0
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
- package/dist/commands/intuned-cli/controller/api.d.ts +44 -0
- package/dist/commands/intuned-cli/controller/api.js +181 -0
- package/dist/commands/intuned-cli/controller/authSession.d.ts +198 -0
- package/dist/commands/intuned-cli/controller/authSession.js +292 -0
- package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/build.js +36 -0
- package/dist/commands/intuned-cli/controller/deploy.d.ts +15 -0
- package/dist/commands/{deploy/utils.js → intuned-cli/controller/deploy.js} +115 -109
- package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/index.js +46 -0
- package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/api.js +19 -0
- package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
- package/dist/commands/intuned-cli/helpers/auth.js +129 -0
- package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
- package/dist/commands/intuned-cli/helpers/backend.js +26 -0
- package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/context.js +33 -0
- package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
- package/dist/commands/intuned-cli/helpers/errors.js +55 -0
- package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
- package/dist/commands/intuned-cli/helpers/index.js +115 -0
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
- package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -16
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
- package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
- package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
- package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
- package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/validation.js +12 -0
- package/dist/commands/intuned-cli/index.d.ts +1 -0
- package/dist/commands/intuned-cli/index.js +16 -0
- package/dist/commands/intuned-cli/main.d.ts +1 -0
- package/dist/commands/intuned-cli/main.js +15 -0
- package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -34
- package/dist/{common/cli → commands/intuned-cli}/types.js +1 -2
- package/dist/common/assets/browser_scripts.js +2509 -2143
- package/dist/common/asyncLocalStorage/index.d.ts +2 -2
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
- package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +2 -1
- package/dist/common/getPlaywrightConstructs.d.ts +6 -5
- package/dist/common/getPlaywrightConstructs.js +73 -37
- package/dist/common/jwtTokenManager.js +3 -5
- package/dist/common/runApi/errors.d.ts +1 -1
- package/dist/common/runApi/errors.js +4 -5
- package/dist/common/runApi/index.d.ts +4 -1
- package/dist/common/runApi/index.js +22 -21
- package/dist/common/runApi/types.d.ts +144 -13
- package/dist/common/runApi/types.js +28 -27
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -0
- package/dist/runtime/executionHelpers.test.js +3 -4
- package/dist/runtime/export.d.ts +18 -0
- package/dist/runtime/extendPayload.js +1 -1
- package/dist/runtime/extendTimeout.js +0 -7
- package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
- package/dist/runtime/getAuthSessionParameters.js +20 -0
- package/dist/runtime/getCdpAddress.d.ts +1 -0
- package/dist/runtime/getCdpAddress.js +11 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +15 -1
- package/package.json +11 -10
- package/template.tsconfig.json +4 -7
- package/tsconfig.json +2 -1
- package/bin/check-auth-session +0 -3
- package/bin/cli-build +0 -3
- package/bin/create-auth-session +0 -3
- package/bin/deploy +0 -3
- package/bin/init +0 -3
- package/bin/run-api +0 -3
- package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
- package/dist/commands/cli-auth-sessions/check.js +0 -40
- package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
- package/dist/commands/cli-auth-sessions/create.js +0 -53
- package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
- package/dist/commands/cli-auth-sessions/utils.js +0 -285
- package/dist/commands/cli-build/cli-build.d.ts +0 -2
- package/dist/commands/cli-build/cli-build.js +0 -20
- package/dist/commands/deploy/deploy.d.ts +0 -2
- package/dist/commands/deploy/deploy.js +0 -47
- package/dist/commands/deploy/utils.d.ts +0 -16
- package/dist/commands/init/init.d.ts +0 -2
- package/dist/commands/init/init.js +0 -22
- package/dist/commands/init/utils.d.ts +0 -11
- package/dist/commands/init/utils.js +0 -181
- package/dist/commands/run-api-cli/run-api.d.ts +0 -2
- package/dist/commands/run-api-cli/run-api.js +0 -57
- package/dist/commands/run-api-cli/utils.d.ts +0 -9
- package/dist/commands/run-api-cli/utils.js +0 -144
- package/dist/common/cli/cliReadme.d.ts +0 -1
- package/dist/common/cli/cliReadme.js +0 -92
- package/dist/common/cli/constants.d.ts +0 -33
- package/dist/common/cli/constants.js +0 -39
- package/dist/common/cli/utils.d.ts +0 -6
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _api = require("../api");
|
|
5
|
+
var _authSession = require("../authSession");
|
|
6
|
+
var _helpers = require("../../helpers");
|
|
7
|
+
var _neverthrow = require("neverthrow");
|
|
8
|
+
var _runApi = require("../../../../common/runApi");
|
|
9
|
+
var _fsExtra = require("fs-extra");
|
|
10
|
+
function getTerminal() {
|
|
11
|
+
return new Proxy(() => ({}), {
|
|
12
|
+
get: () => getTerminal(),
|
|
13
|
+
apply: () => ({})
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_vitest.vi.mock("fs-extra", () => ({
|
|
17
|
+
writeJSON: _vitest.vi.fn()
|
|
18
|
+
}));
|
|
19
|
+
_vitest.vi.mock("../authSession", async importOriginal => {
|
|
20
|
+
const original = await importOriginal();
|
|
21
|
+
return {
|
|
22
|
+
...original,
|
|
23
|
+
executeRunValidateAuthSessionCLI: _vitest.vi.fn()
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
_vitest.vi.mock("../../../../common/runApi", async importOriginal => {
|
|
27
|
+
const original = await importOriginal();
|
|
28
|
+
return {
|
|
29
|
+
...original,
|
|
30
|
+
runApi: _vitest.vi.fn().mockImplementation(() => (0, _neverthrow.ok)({}))
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
_vitest.vi.mock("../../helpers/terminal", () => ({
|
|
34
|
+
terminal: getTerminal()
|
|
35
|
+
}));
|
|
36
|
+
_vitest.vi.mock("../../helpers", async importOriginal => {
|
|
37
|
+
const original = await importOriginal();
|
|
38
|
+
return {
|
|
39
|
+
...original,
|
|
40
|
+
terminal: getTerminal(),
|
|
41
|
+
assertApiFileExists: _vitest.vi.fn(),
|
|
42
|
+
withCLIContext: _vitest.vi.fn(fn => fn()),
|
|
43
|
+
withTimeout: _vitest.vi.fn(fn => fn()),
|
|
44
|
+
parseUrlProxy: _vitest.vi.fn(),
|
|
45
|
+
registerGetAuthSessionParameters: _vitest.vi.fn()
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
(0, _vitest.describe)("API controller", () => {
|
|
49
|
+
(0, _vitest.beforeEach)(() => {
|
|
50
|
+
_vitest.vi.clearAllMocks();
|
|
51
|
+
});
|
|
52
|
+
(0, _vitest.describe)("attemptApi", () => {
|
|
53
|
+
(0, _vitest.it)("calls timeout middleware with timeout", async () => {
|
|
54
|
+
await (0, _api._attemptApi)({
|
|
55
|
+
apiName: "testApi",
|
|
56
|
+
inputData: {},
|
|
57
|
+
headless: false,
|
|
58
|
+
timeout: 6000
|
|
59
|
+
});
|
|
60
|
+
(0, _vitest.expect)(_helpers.withTimeout).toHaveBeenCalledWith(_vitest.expect.any(Function), 6000);
|
|
61
|
+
});
|
|
62
|
+
(0, _vitest.it)("calls runApi with correct parameters and parses proxy", async () => {
|
|
63
|
+
_vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
|
|
64
|
+
await (0, _api._attemptApi)({
|
|
65
|
+
apiName: "testApi",
|
|
66
|
+
inputData: "inputData",
|
|
67
|
+
headless: "headless",
|
|
68
|
+
auth: "auth",
|
|
69
|
+
proxy: "proxy",
|
|
70
|
+
timeout: 999999999
|
|
71
|
+
});
|
|
72
|
+
(0, _vitest.expect)(_helpers.parseUrlProxy).toHaveBeenCalledWith("proxy");
|
|
73
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
|
|
74
|
+
automationFunction: {
|
|
75
|
+
name: "api/testApi",
|
|
76
|
+
params: "inputData"
|
|
77
|
+
},
|
|
78
|
+
runOptions: {
|
|
79
|
+
headless: "headless",
|
|
80
|
+
environment: "standalone",
|
|
81
|
+
proxy: "parsed-proxy"
|
|
82
|
+
},
|
|
83
|
+
auth: {
|
|
84
|
+
session: {
|
|
85
|
+
type: "state",
|
|
86
|
+
state: "auth"
|
|
87
|
+
},
|
|
88
|
+
runCheck: false
|
|
89
|
+
},
|
|
90
|
+
importFunction: _vitest.expect.anything()
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
(0, _vitest.it)("returns the result and extended payloads if runApi succeeds", async () => {
|
|
94
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.ok)({
|
|
95
|
+
result: "result",
|
|
96
|
+
extendedPayloads: "extendedPayloads"
|
|
97
|
+
}));
|
|
98
|
+
const result = await (0, _api._attemptApi)({
|
|
99
|
+
apiName: "testApi",
|
|
100
|
+
inputData: "inputData",
|
|
101
|
+
headless: "headless",
|
|
102
|
+
auth: "auth",
|
|
103
|
+
timeout: 999999999
|
|
104
|
+
});
|
|
105
|
+
(0, _vitest.expect)(result).toEqual({
|
|
106
|
+
result: "result",
|
|
107
|
+
payloadToAppend: "extendedPayloads"
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
(0, _vitest.it)("throws the error runApi fails with an error", async () => {
|
|
111
|
+
const error = new Error("runApi failed");
|
|
112
|
+
_vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
|
|
113
|
+
await (0, _vitest.expect)((0, _api._attemptApi)({
|
|
114
|
+
apiName: "testApi",
|
|
115
|
+
inputData: "inputData",
|
|
116
|
+
headless: "headless",
|
|
117
|
+
auth: "auth",
|
|
118
|
+
timeout: 999999999
|
|
119
|
+
})).rejects.toThrow(error);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
(0, _vitest.describe)("executeRunApiCLI", () => {
|
|
123
|
+
(0, _vitest.it)("calls attemptApi once if success", async () => {
|
|
124
|
+
await (0, _api.executeRunApiCLI)({
|
|
125
|
+
apiName: "testApi",
|
|
126
|
+
inputData: {},
|
|
127
|
+
retries: 3
|
|
128
|
+
});
|
|
129
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
131
|
+
(0, _vitest.it)("stops retrying after max retries", async () => {
|
|
132
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed")));
|
|
133
|
+
await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
|
|
134
|
+
apiName: "testApi",
|
|
135
|
+
inputData: {},
|
|
136
|
+
retries: 10
|
|
137
|
+
})).rejects.toThrow(_helpers.CLIError);
|
|
138
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(10);
|
|
139
|
+
});
|
|
140
|
+
(0, _vitest.it)("stops retrying on non-automation errors", async () => {
|
|
141
|
+
_vitest.vi.mocked(_runApi.runApi).mockRejectedValue(new Error("runApi failed"));
|
|
142
|
+
await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
|
|
143
|
+
apiName: "testApi",
|
|
144
|
+
inputData: {},
|
|
145
|
+
retries: 3
|
|
146
|
+
})).rejects.toThrow("runApi failed");
|
|
147
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
148
|
+
});
|
|
149
|
+
(0, _vitest.it)("stops retrying on success", async () => {
|
|
150
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed"))).mockResolvedValue((0, _neverthrow.ok)({
|
|
151
|
+
result: "success"
|
|
152
|
+
}));
|
|
153
|
+
await (0, _api.executeRunApiCLI)({
|
|
154
|
+
apiName: "testApi",
|
|
155
|
+
inputData: {},
|
|
156
|
+
retries: 10
|
|
157
|
+
});
|
|
158
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(2);
|
|
159
|
+
});
|
|
160
|
+
(0, _vitest.it)("validates auth session before each attempt if provided", async () => {
|
|
161
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed"))).mockResolvedValue((0, _neverthrow.ok)({
|
|
162
|
+
result: "success"
|
|
163
|
+
}));
|
|
164
|
+
await (0, _api.executeRunApiCLI)({
|
|
165
|
+
apiName: "testApi",
|
|
166
|
+
inputData: {},
|
|
167
|
+
authSession: {
|
|
168
|
+
id: "authSessionId",
|
|
169
|
+
autoRecreate: false,
|
|
170
|
+
checkRetries: 1,
|
|
171
|
+
createRetries: 2
|
|
172
|
+
},
|
|
173
|
+
retries: 10
|
|
174
|
+
});
|
|
175
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toBeCalledTimes(2);
|
|
176
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toHaveBeenCalledWith({
|
|
177
|
+
id: "authSessionId",
|
|
178
|
+
autoRecreate: false,
|
|
179
|
+
checkRetries: 1,
|
|
180
|
+
createRetries: 2
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
(0, _vitest.it)("doesn't validate auth session if not provided", async () => {
|
|
184
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
|
|
185
|
+
result: "success"
|
|
186
|
+
}));
|
|
187
|
+
await (0, _api.executeRunApiCLI)({
|
|
188
|
+
apiName: "testApi",
|
|
189
|
+
inputData: {},
|
|
190
|
+
retries: 1
|
|
191
|
+
});
|
|
192
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
(0, _vitest.it)("fails if auth session is provided but not valid", async () => {
|
|
195
|
+
_vitest.vi.mocked(_authSession.executeRunValidateAuthSessionCLI).mockRejectedValue(new _helpers.CLIError("Auth session validation failed"));
|
|
196
|
+
await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
|
|
197
|
+
apiName: "testApi",
|
|
198
|
+
inputData: {},
|
|
199
|
+
authSession: {
|
|
200
|
+
id: "authSessionId",
|
|
201
|
+
autoRecreate: false,
|
|
202
|
+
checkRetries: 1,
|
|
203
|
+
createRetries: 2
|
|
204
|
+
},
|
|
205
|
+
retries: 10
|
|
206
|
+
})).rejects.toThrow("Auth session validation failed");
|
|
207
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toHaveBeenCalledWith({
|
|
208
|
+
id: "authSessionId",
|
|
209
|
+
autoRecreate: false,
|
|
210
|
+
checkRetries: 1,
|
|
211
|
+
createRetries: 2
|
|
212
|
+
});
|
|
213
|
+
(0, _vitest.expect)(_runApi.runApi).not.toHaveBeenCalled();
|
|
214
|
+
});
|
|
215
|
+
(0, _vitest.it)("writes result to file if outputFile is provided", async () => {
|
|
216
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
|
|
217
|
+
result: "result",
|
|
218
|
+
extendedPayloads: "extendedPayloads"
|
|
219
|
+
}));
|
|
220
|
+
await (0, _api.executeRunApiCLI)({
|
|
221
|
+
apiName: "testApi",
|
|
222
|
+
inputData: {},
|
|
223
|
+
outputFile: "output.json",
|
|
224
|
+
retries: 1
|
|
225
|
+
});
|
|
226
|
+
(0, _vitest.expect)(_fsExtra.writeJSON).toHaveBeenCalledWith("output.json", {
|
|
227
|
+
result: "result",
|
|
228
|
+
extendedPayloads: "extendedPayloads"
|
|
229
|
+
}, _vitest.expect.anything());
|
|
230
|
+
});
|
|
231
|
+
(0, _vitest.it)("asserts API file exists", async () => {
|
|
232
|
+
await (0, _api.executeRunApiCLI)({
|
|
233
|
+
apiName: "testApi",
|
|
234
|
+
inputData: {},
|
|
235
|
+
retries: 1
|
|
236
|
+
});
|
|
237
|
+
(0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("api", "testApi");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
(0, _vitest.describe)("executeAttemptApiCLI", () => {
|
|
241
|
+
(0, _vitest.it)("calls attemptApi once", async () => {
|
|
242
|
+
await (0, _api.executeAttemptApiCLI)({
|
|
243
|
+
apiName: "testApi",
|
|
244
|
+
inputData: {},
|
|
245
|
+
retries: 3
|
|
246
|
+
});
|
|
247
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
248
|
+
_vitest.vi.mocked(_runApi.runApi).mockReset();
|
|
249
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed")));
|
|
250
|
+
await (0, _vitest.expect)((0, _api.executeAttemptApiCLI)({
|
|
251
|
+
apiName: "testApi",
|
|
252
|
+
inputData: {}
|
|
253
|
+
})).rejects.toThrow(_runApi.AutomationError);
|
|
254
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
255
|
+
});
|
|
256
|
+
(0, _vitest.it)("writes result to file if outputFile is provided", async () => {
|
|
257
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
|
|
258
|
+
result: "result",
|
|
259
|
+
extendedPayloads: "extendedPayloads"
|
|
260
|
+
}));
|
|
261
|
+
await (0, _api.executeAttemptApiCLI)({
|
|
262
|
+
apiName: "testApi",
|
|
263
|
+
inputData: {},
|
|
264
|
+
outputFile: "output.json"
|
|
265
|
+
});
|
|
266
|
+
(0, _vitest.expect)(_fsExtra.writeJSON).toHaveBeenCalledWith("output.json", {
|
|
267
|
+
result: "result",
|
|
268
|
+
extendedPayloads: "extendedPayloads"
|
|
269
|
+
}, _vitest.expect.anything());
|
|
270
|
+
});
|
|
271
|
+
(0, _vitest.it)("asserts API file exists", async () => {
|
|
272
|
+
await (0, _api.executeRunApiCLI)({
|
|
273
|
+
apiName: "testApi",
|
|
274
|
+
inputData: {},
|
|
275
|
+
retries: 1
|
|
276
|
+
});
|
|
277
|
+
(0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("api", "testApi");
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|