Skip to content

Commit fc97ddb

Browse files
committed
updating slas assertions
1 parent 03cf47b commit fc97ddb

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

packages/b2c-cli/test/functional/e2e/slas-lifecycle.test.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,30 @@ describe('SLAS Lifecycle E2E Tests', function () {
9191
});
9292
}
9393

94-
function expectFailure(result: {exitCode?: number; stdout: string; stderr: string}, stderrPatterns: RegExp[]): void {
94+
function expectFailure(
95+
result: {exitCode?: number; stdout: string; stderr: string},
96+
options: {messagePatterns?: RegExp[]; status?: number} = {},
97+
): void {
9598
const exitCode = result.exitCode ?? -1;
9699
expect(exitCode).to.not.equal(0, `Expected command to fail but it succeeded: ${result.stdout}`);
97-
expect(result.stderr).to.not.be.empty;
98-
for (const pattern of stderrPatterns) {
99-
expect(result.stderr).to.match(pattern);
100+
101+
const errorText = result.stderr || result.stdout;
102+
expect(errorText).to.not.be.empty;
103+
104+
const parsed = JSON.parse(errorText) as {
105+
error?: {message?: string; detail?: string; status?: number; code?: string};
106+
};
107+
expect(parsed.error, 'Expected JSON error object').to.exist;
108+
109+
if (typeof options.status === 'number') {
110+
expect(parsed.error?.status, 'Expected error.status to match').to.equal(options.status);
111+
}
112+
113+
if (options.messagePatterns && options.messagePatterns.length > 0) {
114+
const msg = `${parsed.error?.message ?? ''} ${parsed.error?.detail ?? ''}`;
115+
for (const pattern of options.messagePatterns) {
116+
expect(msg).to.match(pattern);
117+
}
100118
}
101119
}
102120

@@ -274,7 +292,7 @@ describe('SLAS Lifecycle E2E Tests', function () {
274292
'--json',
275293
]);
276294

277-
expectFailure(result, [/not\s*found|404/i]);
295+
expectFailure(result, {messagePatterns: [/failed\s+to\s+get/i]});
278296
});
279297
});
280298

@@ -353,7 +371,7 @@ describe('SLAS Lifecycle E2E Tests', function () {
353371
'--json',
354372
]);
355373

356-
expectFailure(result, [/not\s*found|404/i]);
374+
expectFailure(result, {messagePatterns: [/failed\s+to\s+get/i]});
357375
});
358376

359377
it('should fail to update deleted client', async function () {
@@ -371,7 +389,7 @@ describe('SLAS Lifecycle E2E Tests', function () {
371389
'--json',
372390
]);
373391

374-
expectFailure(result, [/not\s*found|404/i]);
392+
expectFailure(result, {messagePatterns: [/failed\s+to\s+fetch/i]});
375393
});
376394
});
377395
});

0 commit comments

Comments
 (0)