@lowdefy/server-dev 0.0.0-experimental-20261118134457 → 0.0.0-experimental-20261119084338
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/client/recorder/createRecorder.test.mjs +51 -0
- package/lib/docs/addNestedEndpoints.js +1 -2
- package/lib/docs/addNestedEndpoints.test.mjs +1 -1
- package/lib/docs/addWriteFlags.js +1 -2
- package/lib/docs/checkStepReferences.js +1 -2
- package/lib/docs/createDevServerHost.js +35 -11
- package/lib/docs/createDevServerHost.test.mjs +47 -0
- package/lib/docs/createInProcessRequest.js +3 -1
- package/lib/docs/observe/evaluateInvariants.js +5 -2
- package/lib/docs/observe/evaluateInvariants.test.mjs +28 -0
- package/lib/docs/rails/checkAuthActionsRan.js +20 -13
- package/lib/docs/rails/checkAuthActionsRan.test.mjs +34 -16
- package/lib/docs/rails/checkPressRails.js +115 -0
- package/lib/docs/rails/checkPressRails.test.mjs +210 -0
- package/lib/docs/rails/checkStepRails.js +113 -0
- package/lib/docs/rails/checkStepRails.test.mjs +207 -0
- package/lib/docs/runJourney.js +15 -5
- package/lib/docs/runJourney.test.mjs +82 -7
- package/lib/docs/runJourneyHeadless.js +3 -1
- package/lib/docs/runJourneyHeadless.test.mjs +58 -0
- package/lib/docs/runJourneySteps.js +380 -59
- package/lib/server/log/createHandleError.js +8 -1
- package/lib/server/log/createHandleError.test.mjs +20 -0
- package/lib/server/mutants/walkArtifact.js +1 -1
- package/package.json +41 -41
- package/package.original.json +41 -41
- package/lib/docs/pageBlocks.js +0 -47
- package/lib/docs/rails/checkClickRails.js +0 -56
- package/lib/docs/rails/createDataSetRails.js +0 -82
- package/lib/docs/rails/createDataSetRails.test.mjs +0 -173
- package/lib/docs/rails/findExternalBlocks.js +0 -147
- package/lib/docs/rails/findExternalBlocks.test.mjs +0 -255
- package/lib/docs/rails/readBuiltArtifact.js +0 -30
- package/lib/docs/readRoutineSteps.js +0 -45
- package/lib/server/isRoutineStep.js +0 -27
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { vi, afterEach, beforeEach, expect, test } from 'vitest';
|
|
21
|
+
import { getTrace } from '@lowdefy/engine';
|
|
22
|
+
import { formatSessionLog, validateTraceRecord } from '@lowdefy/node-utils';
|
|
21
23
|
|
|
22
24
|
import createRecorder from './createRecorder.js';
|
|
23
25
|
|
|
@@ -316,3 +318,52 @@ test('a page shown with no pageview pending records nothing', async () => {
|
|
|
316
318
|
await window.__lowdefyRecorder.flush();
|
|
317
319
|
expect(fetch).not.toHaveBeenCalled();
|
|
318
320
|
});
|
|
321
|
+
|
|
322
|
+
test('a recorded click on a Modal OK button in its portal is a { blockId, control } click step', async () => {
|
|
323
|
+
window.history.replaceState({}, '', '/tickets');
|
|
324
|
+
document.body.innerHTML = `
|
|
325
|
+
<div id="bl-page"><div id="bl-delete_modal"></div></div>
|
|
326
|
+
<div class="ant-modal-root"><div role="dialog" class="ant-modal"><div class="ant-modal-footer">
|
|
327
|
+
<button data-lf-block="delete_modal" data-lf-control="cancel"><span>Cancel</span></button>
|
|
328
|
+
<button data-lf-block="delete_modal" data-lf-control="ok"><span id="ok">OK</span></button>
|
|
329
|
+
</div></div></div>`;
|
|
330
|
+
const lowdefy = {
|
|
331
|
+
basePath: '',
|
|
332
|
+
contexts: {
|
|
333
|
+
'page:tickets': {
|
|
334
|
+
pageId: 'tickets',
|
|
335
|
+
_internal: { RootSlots: { map: { delete_modal: { type: 'Modal' } } } },
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
home: {},
|
|
339
|
+
user: { roles: [] },
|
|
340
|
+
_internal: { globals: { window } },
|
|
341
|
+
};
|
|
342
|
+
recorder = createRecorder({
|
|
343
|
+
basePath: '',
|
|
344
|
+
lowdefy,
|
|
345
|
+
recording: { enabled: true },
|
|
346
|
+
window,
|
|
347
|
+
getTrace,
|
|
348
|
+
});
|
|
349
|
+
recorder.pageview({ path: 'tickets' });
|
|
350
|
+
recorder.pageShown(page('tickets'));
|
|
351
|
+
document.getElementById('ok').click();
|
|
352
|
+
await window.__lowdefyRecorder.flush();
|
|
353
|
+
// The dev server stamps the source on each record it writes.
|
|
354
|
+
const records = sentBodies()[0].records.map((record) => ({ ...record, source: 'dev' }));
|
|
355
|
+
const click = records.find((record) => record.kind === 'click');
|
|
356
|
+
expect(click.target).toEqual({
|
|
357
|
+
block_id: 'delete_modal',
|
|
358
|
+
block_type: 'Modal',
|
|
359
|
+
row: null,
|
|
360
|
+
row_key: null,
|
|
361
|
+
column: null,
|
|
362
|
+
control: 'ok',
|
|
363
|
+
text: null,
|
|
364
|
+
nth: null,
|
|
365
|
+
option: false,
|
|
366
|
+
});
|
|
367
|
+
expect(validateTraceRecord({ record: click })).toEqual({});
|
|
368
|
+
expect(formatSessionLog({ records }).lines).toContain('click delete_modal control ok');
|
|
369
|
+
});
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { type } from '@lowdefy/helpers';
|
|
18
|
-
|
|
19
|
-
import readRoutineSteps from './readRoutineSteps.js';
|
|
18
|
+
import { readRoutineSteps } from '@lowdefy/node-utils';
|
|
20
19
|
|
|
21
20
|
// The browser never sees a routine's CallApi, in-process or detached, so the
|
|
22
21
|
// endpoints a journey reached through one are added from config: every
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import addNestedEndpoints from './addNestedEndpoints.js';
|
|
18
18
|
import addWriteFlags from './addWriteFlags.js';
|
|
19
19
|
import collectExercised from './collectExercised.js';
|
|
20
|
-
import readRoutineSteps from '
|
|
20
|
+
import { readRoutineSteps } from '@lowdefy/node-utils';
|
|
21
21
|
import { expect, test } from 'vitest';
|
|
22
22
|
|
|
23
23
|
function callApi({ id, endpointId, detached }) {
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { type } from '@lowdefy/helpers';
|
|
18
|
-
|
|
19
|
-
import readRoutineSteps from './readRoutineSteps.js';
|
|
18
|
+
import { readRoutineSteps } from '@lowdefy/node-utils';
|
|
20
19
|
|
|
21
20
|
// A request writes when its type declares meta.checkWrite: true. An endpoint
|
|
22
21
|
// writes when a step of its routine has such a type, or when an endpoint it
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { type } from '@lowdefy/helpers';
|
|
18
|
-
import { getStepKey, normaliseBlockId } from '@lowdefy/node-utils';
|
|
18
|
+
import { getStepKey, normaliseBlockId, pageBlocks } from '@lowdefy/node-utils';
|
|
19
19
|
|
|
20
20
|
import getPageConfig from './getPageConfig.js';
|
|
21
21
|
import JourneyStepError from './JourneyStepError.js';
|
|
22
|
-
import pageBlocks from './pageBlocks.js';
|
|
23
22
|
import readBuildArtifact from './readBuildArtifact.js';
|
|
24
23
|
import readPageArtifact from './readPageArtifact.js';
|
|
25
24
|
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
redactErrorResponse,
|
|
25
25
|
runDetachedEndpoint,
|
|
26
26
|
runWebhookEndpoint,
|
|
27
|
+
sendDetachedRequest,
|
|
27
28
|
} from '@lowdefy/api';
|
|
28
29
|
import { expectedAnswers, isExpectedError, isForcedFailure } from '@lowdefy/errors';
|
|
29
30
|
import { buildPagePath, serializer, type } from '@lowdefy/helpers';
|
|
@@ -34,6 +35,7 @@ import { findSessionDocuments } from '@lowdefy/test-utils/dataSets';
|
|
|
34
35
|
import buildPageIfNeeded from '../server/jitPageBuilder.js';
|
|
35
36
|
import createInProcessRequest from './createInProcessRequest.js';
|
|
36
37
|
import readBuildArtifact from './readBuildArtifact.js';
|
|
38
|
+
import readConnectionPlugins from './readConnectionPlugins.js';
|
|
37
39
|
import { JOURNEY_COOKIES, writeJourneyCookie } from '../server/journeyCookies.js';
|
|
38
40
|
import recordingCookiePayload from '../server/recording/recordingCookiePayload.js';
|
|
39
41
|
import resolveHeadlessUser from '../server/auth/resolveHeadlessUser.js';
|
|
@@ -52,7 +54,7 @@ function createErrorSink() {
|
|
|
52
54
|
|
|
53
55
|
// The answer to a call that threw, as the server's error handler answers it: an expected outcome
|
|
54
56
|
// with its status and { name, message }, or a fault, logged and answered 500.
|
|
55
|
-
async function answerError({ context, error, faults }) {
|
|
57
|
+
async function answerError({ context, detached, error, faults }) {
|
|
56
58
|
if (isExpectedError(error)) {
|
|
57
59
|
const { status } = expectedAnswers[error.name] ?? expectedAnswers.UserError;
|
|
58
60
|
const refusal = new Error(error.message);
|
|
@@ -64,6 +66,7 @@ async function answerError({ context, error, faults }) {
|
|
|
64
66
|
error: refusal,
|
|
65
67
|
body: { name: error.name, message: error.message },
|
|
66
68
|
faults,
|
|
69
|
+
detached,
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
await context.handleError(error);
|
|
@@ -75,18 +78,19 @@ async function answerError({ context, error, faults }) {
|
|
|
75
78
|
error: serializer.deserializeFromString(text),
|
|
76
79
|
body: JSON.parse(text),
|
|
77
80
|
faults,
|
|
81
|
+
detached,
|
|
78
82
|
};
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// The answer a call gets, as the server's routes and error handler answer it (and as
|
|
82
86
|
// @lowdefy/test-utils' answerCall answers for a build): a 200 with the call's result, or what
|
|
83
87
|
// answerError answers when it threw.
|
|
84
|
-
async function answer({ context, faults, run }) {
|
|
88
|
+
async function answer({ context, detached, faults, run }) {
|
|
85
89
|
let result;
|
|
86
90
|
try {
|
|
87
91
|
result = await run(context);
|
|
88
92
|
} catch (error) {
|
|
89
|
-
return answerError({ context, error, faults });
|
|
93
|
+
return answerError({ context, detached, error, faults });
|
|
90
94
|
}
|
|
91
95
|
const text = JSON.stringify(result);
|
|
92
96
|
const read = serializer.deserializeFromString(text);
|
|
@@ -97,6 +101,7 @@ async function answer({ context, faults, run }) {
|
|
|
97
101
|
error: read.error ?? null,
|
|
98
102
|
body: JSON.parse(text),
|
|
99
103
|
faults,
|
|
104
|
+
detached,
|
|
100
105
|
};
|
|
101
106
|
}
|
|
102
107
|
|
|
@@ -190,7 +195,16 @@ async function createDevServerHost({
|
|
|
190
195
|
}
|
|
191
196
|
return handleError(error, options);
|
|
192
197
|
};
|
|
193
|
-
|
|
198
|
+
// The detached CallApi calls the call makes, as answerCall's detached: the build host takes
|
|
199
|
+
// them and never runs their targets, while the dev server sends each over its own
|
|
200
|
+
// /api/detached route as it always does (sendDetachedRequest), and records it once sent, so
|
|
201
|
+
// expect.calls reads a journey's detached calls the same on either host.
|
|
202
|
+
const detached = [];
|
|
203
|
+
context.sendDetached = (callerContext, args) => {
|
|
204
|
+
sendDetachedRequest(callerContext, args);
|
|
205
|
+
detached.push({ endpointId: args.endpointId, payload: serializer.copy(args.payload) });
|
|
206
|
+
};
|
|
207
|
+
return { context, detached, faults };
|
|
194
208
|
}
|
|
195
209
|
|
|
196
210
|
const root = await createContext({ method: 'GET', requestPath: '/api/root' });
|
|
@@ -247,12 +261,17 @@ async function createDevServerHost({
|
|
|
247
261
|
counter.recordCall({ url: `${origin}${requestPath}`, method: 'POST' });
|
|
248
262
|
const body = kind === 'request' ? { actionId, blockId, payload } : { blockId, pageId, payload };
|
|
249
263
|
const parsed = parseRequestBody({ text: JSON.stringify(body) });
|
|
250
|
-
const { context, faults } = await createContext({
|
|
264
|
+
const { context, detached, faults } = await createContext({
|
|
265
|
+
callUser,
|
|
266
|
+
method: 'POST',
|
|
267
|
+
requestPath,
|
|
268
|
+
});
|
|
251
269
|
if (kind === 'request') {
|
|
252
270
|
// As the request route does: the page's request artifact is built before it is read.
|
|
253
271
|
await buildPageIfNeeded({ pageId, buildDirectory, configDirectory });
|
|
254
272
|
return answer({
|
|
255
273
|
context,
|
|
274
|
+
detached,
|
|
256
275
|
faults,
|
|
257
276
|
run: (callContext) =>
|
|
258
277
|
callRequest(callContext, {
|
|
@@ -265,6 +284,7 @@ async function createDevServerHost({
|
|
|
265
284
|
}
|
|
266
285
|
return answer({
|
|
267
286
|
context,
|
|
287
|
+
detached,
|
|
268
288
|
faults,
|
|
269
289
|
run: (callContext) =>
|
|
270
290
|
callEndpoint(callContext, {
|
|
@@ -283,13 +303,14 @@ async function createDevServerHost({
|
|
|
283
303
|
const requestPath = `/api/detached/${endpointId}`;
|
|
284
304
|
counter.recordCall({ url: `${origin}${requestPath}`, method: 'POST' });
|
|
285
305
|
const parsed = parseRequestBody({ text: JSON.stringify({ payload }) });
|
|
286
|
-
const { context, faults } = await createContext({
|
|
306
|
+
const { context, detached, faults } = await createContext({
|
|
287
307
|
callUser: 'none',
|
|
288
308
|
method: 'POST',
|
|
289
309
|
requestPath,
|
|
290
310
|
});
|
|
291
311
|
return answer({
|
|
292
312
|
context,
|
|
313
|
+
detached,
|
|
293
314
|
faults,
|
|
294
315
|
run: (callContext) =>
|
|
295
316
|
runDetachedEndpoint(callContext, {
|
|
@@ -302,12 +323,12 @@ async function createDevServerHost({
|
|
|
302
323
|
|
|
303
324
|
// A webhook step: posted as the endpoints route runs a webhook endpoint, through
|
|
304
325
|
// runWebhookEndpoint with no caller, so its verify gate runs against rawBody. Answers what the
|
|
305
|
-
// route sends, { status, body, contentType, faults, rid }, as @lowdefy/test-utils'
|
|
306
|
-
// does: rid is the call's request id, by which a forced failure's message is read.
|
|
326
|
+
// route sends, { status, body, contentType, faults, detached, rid }, as @lowdefy/test-utils'
|
|
327
|
+
// callWebhook does: rid is the call's request id, by which a forced failure's message is read.
|
|
307
328
|
async function webhook({ endpointId, headers, query, rawBody }) {
|
|
308
329
|
const requestPath = `/api/endpoints/${endpointId}`;
|
|
309
330
|
counter.recordCall({ url: `${origin}${requestPath}`, method: 'POST' });
|
|
310
|
-
const { context, faults } = await createContext({
|
|
331
|
+
const { context, detached, faults } = await createContext({
|
|
311
332
|
callUser: 'none',
|
|
312
333
|
method: 'POST',
|
|
313
334
|
requestPath,
|
|
@@ -320,6 +341,7 @@ async function createDevServerHost({
|
|
|
320
341
|
body: sent.body,
|
|
321
342
|
contentType: 'text/plain',
|
|
322
343
|
faults,
|
|
344
|
+
detached,
|
|
323
345
|
rid: context.rid,
|
|
324
346
|
};
|
|
325
347
|
}
|
|
@@ -328,11 +350,12 @@ async function createDevServerHost({
|
|
|
328
350
|
body: JSON.parse(JSON.stringify(sent.body)),
|
|
329
351
|
contentType: 'application/json',
|
|
330
352
|
faults,
|
|
353
|
+
detached,
|
|
331
354
|
rid: context.rid,
|
|
332
355
|
};
|
|
333
356
|
} catch (error) {
|
|
334
|
-
const { body, status } = await answerError({ context, error, faults });
|
|
335
|
-
return { status, body, contentType: 'application/json', faults, rid: context.rid };
|
|
357
|
+
const { body, status } = await answerError({ context, detached, error, faults });
|
|
358
|
+
return { status, body, contentType: 'application/json', faults, detached, rid: context.rid };
|
|
336
359
|
}
|
|
337
360
|
}
|
|
338
361
|
|
|
@@ -370,6 +393,7 @@ async function createDevServerHost({
|
|
|
370
393
|
call,
|
|
371
394
|
// The data session belongs to the journey run, which closes it (runJourneyHeadless).
|
|
372
395
|
close: async () => {},
|
|
396
|
+
connections: await readConnectionPlugins(),
|
|
373
397
|
dataSetName: dataSet?.name ?? null,
|
|
374
398
|
dataSession: session?.session ?? null,
|
|
375
399
|
errorSink: createErrorSink(),
|
|
@@ -27,6 +27,7 @@ vi.doMock('../server/createLowdefyContext.js', () => ({
|
|
|
27
27
|
}));
|
|
28
28
|
const mockCallEndpoint = vi.fn();
|
|
29
29
|
const mockRunWebhookEndpoint = vi.fn();
|
|
30
|
+
const mockSendDetachedRequest = vi.fn();
|
|
30
31
|
vi.doMock('@lowdefy/api', () => ({
|
|
31
32
|
callEndpoint: mockCallEndpoint,
|
|
32
33
|
callRequest: vi.fn(),
|
|
@@ -36,6 +37,7 @@ vi.doMock('@lowdefy/api', () => ({
|
|
|
36
37
|
redactErrorResponse: (context, error) => ({ name: error.name, message: error.message }),
|
|
37
38
|
runDetachedEndpoint: vi.fn(),
|
|
38
39
|
runWebhookEndpoint: mockRunWebhookEndpoint,
|
|
40
|
+
sendDetachedRequest: mockSendDetachedRequest,
|
|
39
41
|
}));
|
|
40
42
|
vi.doMock('@lowdefy/journey-headless', () => ({
|
|
41
43
|
createHeadlessHost: (host) => host,
|
|
@@ -44,6 +46,7 @@ vi.doMock('@lowdefy/journey-headless', () => ({
|
|
|
44
46
|
vi.doMock('@lowdefy/test-utils/dataSets', () => ({ findSessionDocuments: vi.fn() }));
|
|
45
47
|
vi.doMock('../server/jitPageBuilder.js', () => ({ default: vi.fn() }));
|
|
46
48
|
vi.doMock('./readBuildArtifact.js', () => ({ default: vi.fn() }));
|
|
49
|
+
vi.doMock('./readConnectionPlugins.js', () => ({ default: vi.fn(async () => ({})) }));
|
|
47
50
|
vi.doMock('../server/auth/resolveHeadlessUser.js', () => ({ default: vi.fn() }));
|
|
48
51
|
|
|
49
52
|
const { default: createDevServerHost } = await import('./createDevServerHost.js');
|
|
@@ -68,6 +71,7 @@ beforeEach(() => {
|
|
|
68
71
|
mockHandleError.mockClear();
|
|
69
72
|
mockCallEndpoint.mockReset();
|
|
70
73
|
mockRunWebhookEndpoint.mockReset();
|
|
74
|
+
mockSendDetachedRequest.mockReset();
|
|
71
75
|
});
|
|
72
76
|
|
|
73
77
|
test('the dev server host marks a fault a :catch handled caught on a webhook answer', async () => {
|
|
@@ -108,3 +112,46 @@ test('the dev server host marks a fault a :catch handled caught on a call answer
|
|
|
108
112
|
{ caught: undefined, message: 'Escaped on purpose' },
|
|
109
113
|
]);
|
|
110
114
|
});
|
|
115
|
+
|
|
116
|
+
// A detached CallApi on the dev server is sent over its own /api/detached route, as always
|
|
117
|
+
// (sendDetachedRequest), and listed on the answer once sent, as the build host lists the ones it
|
|
118
|
+
// takes, so expect.calls reads them the same on either host.
|
|
119
|
+
test('the dev server host sends a detached call for real and lists it on the answer', async () => {
|
|
120
|
+
mockCallEndpoint.mockImplementation(async (context) => {
|
|
121
|
+
context.sendDetached(context, {
|
|
122
|
+
endpointId: 'detached_log',
|
|
123
|
+
payload: { source: 'notify' },
|
|
124
|
+
step: { stepId: 'call_detached_log' },
|
|
125
|
+
});
|
|
126
|
+
return { success: true, response: { notified: true } };
|
|
127
|
+
});
|
|
128
|
+
const host = await createHost();
|
|
129
|
+
const answer = await host.call({ endpointId: 'notify', kind: 'endpoint', payload: {} });
|
|
130
|
+
expect(answer.response).toEqual({ notified: true });
|
|
131
|
+
expect(mockSendDetachedRequest).toHaveBeenCalledTimes(1);
|
|
132
|
+
expect(mockSendDetachedRequest.mock.calls[0][1]).toMatchObject({
|
|
133
|
+
endpointId: 'detached_log',
|
|
134
|
+
payload: { source: 'notify' },
|
|
135
|
+
});
|
|
136
|
+
expect(answer.detached).toEqual([{ endpointId: 'detached_log', payload: { source: 'notify' } }]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('the dev server host lists no detached call whose send failed', async () => {
|
|
140
|
+
mockSendDetachedRequest.mockImplementation(() => {
|
|
141
|
+
throw new Error('CallApi with "detached: true" requires the CRON_SECRET environment variable.');
|
|
142
|
+
});
|
|
143
|
+
mockCallEndpoint.mockImplementation(async (context) => {
|
|
144
|
+
try {
|
|
145
|
+
context.sendDetached(context, { endpointId: 'detached_log', payload: {}, step: {} });
|
|
146
|
+
} catch (error) {
|
|
147
|
+
await context.handleError(error);
|
|
148
|
+
}
|
|
149
|
+
return { success: true, response: { notified: false } };
|
|
150
|
+
});
|
|
151
|
+
const host = await createHost();
|
|
152
|
+
const answer = await host.call({ endpointId: 'notify', kind: 'endpoint', payload: {} });
|
|
153
|
+
expect(answer.detached).toEqual([]);
|
|
154
|
+
expect(answer.faults.map(({ message }) => message)).toEqual([
|
|
155
|
+
'CallApi with "detached: true" requires the CRON_SECRET environment variable.',
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
@@ -27,7 +27,9 @@ function createInProcessRequest({ cookies, method, origin, path }) {
|
|
|
27
27
|
get: () => undefined,
|
|
28
28
|
req: {
|
|
29
29
|
header: (name) =>
|
|
30
|
-
name === undefined
|
|
30
|
+
name === undefined
|
|
31
|
+
? Object.fromEntries(headers.entries())
|
|
32
|
+
: (headers.get(name) ?? undefined),
|
|
31
33
|
method,
|
|
32
34
|
path,
|
|
33
35
|
raw: { headers, signal: new AbortController().signal },
|
|
@@ -27,14 +27,17 @@ function describeTarget(target) {
|
|
|
27
27
|
return parts.join(' ');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// A fault a :catch of the routine handled (`caught`) explains no 5xx: the routine went on and
|
|
31
|
+
// answered, so a 5xx from the same call came from something else.
|
|
30
32
|
function isExplained({ response, serverEntries, basePath }) {
|
|
31
33
|
const called = parseAppApiUrl({ url: response.url, basePath });
|
|
32
34
|
return serverEntries.some(
|
|
33
35
|
(entry) =>
|
|
34
|
-
|
|
36
|
+
entry.caught !== true &&
|
|
37
|
+
((!type.isNone(called?.requestId) &&
|
|
35
38
|
entry.requestId === called.requestId &&
|
|
36
39
|
entry.pageId === called.pageId) ||
|
|
37
|
-
|
|
40
|
+
(!type.isNone(called?.endpointId) && entry.endpointId === called.endpointId))
|
|
38
41
|
);
|
|
39
42
|
}
|
|
40
43
|
|
|
@@ -234,6 +234,34 @@ test('a 5xx from an app route is request-failed unless a server error entry for
|
|
|
234
234
|
expect(explainedRequest.map((finding) => finding.kind)).toEqual(['server-error']);
|
|
235
235
|
});
|
|
236
236
|
|
|
237
|
+
test('a fault a :catch of the routine handled is no server-error and explains no 5xx', async () => {
|
|
238
|
+
const response = {
|
|
239
|
+
url: `${origin}/api/endpoints/assign_ticket`,
|
|
240
|
+
method: 'POST',
|
|
241
|
+
status: 500,
|
|
242
|
+
};
|
|
243
|
+
const findings = await evaluate({
|
|
244
|
+
window: quietWindow({
|
|
245
|
+
requests: [response],
|
|
246
|
+
responses: [response],
|
|
247
|
+
errors: [
|
|
248
|
+
{
|
|
249
|
+
store: 'server',
|
|
250
|
+
message: 'Caught operator fault.',
|
|
251
|
+
caught: true,
|
|
252
|
+
endpointId: 'assign_ticket',
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
}),
|
|
256
|
+
});
|
|
257
|
+
expect(findings).toEqual([
|
|
258
|
+
expect.objectContaining({
|
|
259
|
+
kind: 'request-failed',
|
|
260
|
+
message: 'POST /api/endpoints/assign_ticket answered 500.',
|
|
261
|
+
}),
|
|
262
|
+
]);
|
|
263
|
+
});
|
|
264
|
+
|
|
237
265
|
test("a page request a test's fail gate failed is no app error: no action-error, server-error or request-failed", async () => {
|
|
238
266
|
const response = {
|
|
239
267
|
url: `${origin}/api/request/tickets/save_ticket`,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { type } from '@lowdefy/helpers';
|
|
18
|
+
import { RAILED_STEPS } from '@lowdefy/node-utils';
|
|
18
19
|
|
|
19
20
|
import JourneyStepError from '../JourneyStepError.js';
|
|
20
21
|
import authEngineMethods from './authEngineMethods.js';
|
|
@@ -24,7 +25,7 @@ import readAuthActionRecorder from './readAuthActionRecorder.js';
|
|
|
24
25
|
const RECORDER_KEY = '__lowdefyAuthActions';
|
|
25
26
|
|
|
26
27
|
// On a data-set run (journey.dataSetRails), starts recording the auth-engine
|
|
27
|
-
// actions the page executes, before a
|
|
28
|
+
// actions the page executes, before a step acts. Journeys without a data set
|
|
28
29
|
// record nothing.
|
|
29
30
|
async function armAuthActionRecorder({ journey, page }) {
|
|
30
31
|
if (type.isUndefined(journey.dataSetRails)) {
|
|
@@ -36,12 +37,16 @@ async function armAuthActionRecorder({ journey, page }) {
|
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
40
|
+
function capitalise(text) {
|
|
41
|
+
return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// After a step (a click, open, fill, select or press, see railedSteps) on a data-set run has
|
|
45
|
+
// settled, fails it when an auth-engine action executed: its callers are injected and have no
|
|
46
|
+
// auth session, so it fails for a harness reason. An action the chain skipped (a validation that
|
|
47
|
+
// stopped it, a skip: condition) never runs, so a step that only might reach one is fine.
|
|
48
|
+
// blockId is the block the step acted on, when known.
|
|
49
|
+
async function checkAuthActionsRan({ journey, page, blockId, step }) {
|
|
45
50
|
if (type.isUndefined(journey.dataSetRails)) {
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
@@ -50,14 +55,16 @@ async function checkAuthActionsRan({ journey, page, blockId }) {
|
|
|
50
55
|
if (actions.length === 0) {
|
|
51
56
|
return;
|
|
52
57
|
}
|
|
53
|
-
const
|
|
58
|
+
const words = RAILED_STEPS[step];
|
|
59
|
+
const subject = type.isNone(blockId) ? capitalise(words.step) : `Block "${blockId}"`;
|
|
60
|
+
const named = actions.join(', ');
|
|
54
61
|
throw new JourneyStepError(
|
|
55
|
-
`${subject} ran the auth action ${
|
|
56
|
-
|
|
57
|
-
)}
|
|
62
|
+
`${subject} ran the auth action ${named}, which a data-set journey cannot run: its users are injected and have no auth session. ${capitalise(
|
|
63
|
+
words.step
|
|
64
|
+
)} that skips the action (a failed validation, a skip condition) is fine.`,
|
|
58
65
|
{
|
|
59
|
-
expected:
|
|
60
|
-
actual:
|
|
66
|
+
expected: `${words.step} that runs no auth action`,
|
|
67
|
+
actual: `${words.step} that ran the auth action ${named}`,
|
|
61
68
|
}
|
|
62
69
|
);
|
|
63
70
|
}
|
|
@@ -69,7 +69,7 @@ test('a click whose auth actions were skipped passes', async () => {
|
|
|
69
69
|
const page = createPage(window);
|
|
70
70
|
await armAuthActionRecorder({ journey, page });
|
|
71
71
|
await expect(
|
|
72
|
-
checkAuthActionsRan({ journey, page, blockId: 'create_org' })
|
|
72
|
+
checkAuthActionsRan({ journey, page, blockId: 'create_org', step: 'click' })
|
|
73
73
|
).resolves.toBeUndefined();
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -79,18 +79,18 @@ test('a click that ran an auth action fails, naming the block and the action', a
|
|
|
79
79
|
await armAuthActionRecorder({ journey, page });
|
|
80
80
|
await callAuth(window, 'setActiveOrganization', { organizationId: 'a' });
|
|
81
81
|
await callAuth(window, 'updateSession');
|
|
82
|
-
await expect(
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
82
|
+
await expect(
|
|
83
|
+
checkAuthActionsRan({ journey, page, blockId: 'create_org', step: 'click' })
|
|
84
|
+
).rejects.toMatchObject({
|
|
85
|
+
message: expect.stringMatching(
|
|
86
|
+
/^Block "create_org" ran the auth action SetActiveOrganization, UpdateSession, which a data-set journey cannot run: its users are injected and have no auth session\./
|
|
87
|
+
),
|
|
88
|
+
expected: 'a click that runs no auth action',
|
|
89
|
+
actual: 'a click that ran the auth action SetActiveOrganization, UpdateSession',
|
|
90
|
+
});
|
|
91
91
|
// The recording is cleared once read.
|
|
92
92
|
await expect(
|
|
93
|
-
checkAuthActionsRan({ journey, page, blockId: 'create_org' })
|
|
93
|
+
checkAuthActionsRan({ journey, page, blockId: 'create_org', step: 'click' })
|
|
94
94
|
).resolves.toBeUndefined();
|
|
95
95
|
});
|
|
96
96
|
|
|
@@ -107,7 +107,7 @@ test('methods that are not auth-engine methods are not recorded', async () => {
|
|
|
107
107
|
const page = createPage(window);
|
|
108
108
|
await armAuthActionRecorder({ journey, page });
|
|
109
109
|
await callAuth(window, 'notAuthEngine');
|
|
110
|
-
await expect(checkAuthActionsRan({ journey, page })).resolves.toBeUndefined();
|
|
110
|
+
await expect(checkAuthActionsRan({ journey, page, step: 'click' })).resolves.toBeUndefined();
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
test('the recording is read back after the document that made it is replaced', async () => {
|
|
@@ -118,7 +118,7 @@ test('the recording is read back after the document that made it is replaced', a
|
|
|
118
118
|
const second = createWindow();
|
|
119
119
|
second.sessionStorage = first.sessionStorage;
|
|
120
120
|
await expect(
|
|
121
|
-
checkAuthActionsRan({ journey, page: createPage(second), blockId: 'sign_in' })
|
|
121
|
+
checkAuthActionsRan({ journey, page: createPage(second), blockId: 'sign_in', step: 'click' })
|
|
122
122
|
).rejects.toMatchObject({ actual: 'a click that ran the auth action Login' });
|
|
123
123
|
});
|
|
124
124
|
|
|
@@ -127,23 +127,41 @@ test('a click with no known block says A click', async () => {
|
|
|
127
127
|
const page = createPage(window);
|
|
128
128
|
await armAuthActionRecorder({ journey, page });
|
|
129
129
|
await callAuth(window, 'login', {});
|
|
130
|
-
await expect(
|
|
130
|
+
await expect(
|
|
131
|
+
checkAuthActionsRan({ journey, page, blockId: null, step: 'click' })
|
|
132
|
+
).rejects.toMatchObject({
|
|
131
133
|
message: expect.stringMatching(/^A click ran the auth action Login,/),
|
|
132
134
|
});
|
|
133
135
|
});
|
|
134
136
|
|
|
137
|
+
test.each([
|
|
138
|
+
['open', /^An open ran the auth action Login,.* An open that skips the action/, 'an open'],
|
|
139
|
+
['fill', /^A fill ran the auth action Login,.* A fill that skips the action/, 'a fill'],
|
|
140
|
+
['select', /^A select ran the auth action Login,.* A select that skips the action/, 'a select'],
|
|
141
|
+
])('%s that ran an auth action fails in its own words', async (step, message, noun) => {
|
|
142
|
+
const window = createWindow();
|
|
143
|
+
const page = createPage(window);
|
|
144
|
+
await armAuthActionRecorder({ journey, page });
|
|
145
|
+
await callAuth(window, 'login', {});
|
|
146
|
+
await expect(checkAuthActionsRan({ journey, page, blockId: null, step })).rejects.toMatchObject({
|
|
147
|
+
message: expect.stringMatching(message),
|
|
148
|
+
expected: `${noun} that runs no auth action`,
|
|
149
|
+
actual: `${noun} that ran the auth action Login`,
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
135
153
|
test('a journey without a data set is not recorded or checked', async () => {
|
|
136
154
|
const window = createWindow();
|
|
137
155
|
const page = createPage(window);
|
|
138
156
|
await armAuthActionRecorder({ journey: {}, page });
|
|
139
157
|
await callAuth(window, 'login', {});
|
|
140
158
|
expect(window.sessionStorage.getItem('__lowdefyAuthActions')).toBeNull();
|
|
141
|
-
await expect(checkAuthActionsRan({ journey: {}, page })).resolves.toBeUndefined();
|
|
159
|
+
await expect(checkAuthActionsRan({ journey: {}, page, step: 'click' })).resolves.toBeUndefined();
|
|
142
160
|
});
|
|
143
161
|
|
|
144
162
|
test('a page with no auth methods records nothing and does not fail', async () => {
|
|
145
163
|
const page = createPage({ lowdefy: {}, sessionStorage: createWindow().sessionStorage });
|
|
146
164
|
await armAuthActionRecorder({ journey, page });
|
|
147
|
-
await expect(checkAuthActionsRan({ journey, page })).resolves.toBeUndefined();
|
|
165
|
+
await expect(checkAuthActionsRan({ journey, page, step: 'click' })).resolves.toBeUndefined();
|
|
148
166
|
expect(Object.keys(authEngineMethods).length).toBeGreaterThan(0);
|
|
149
167
|
});
|