Skip to content

Commit 3154631

Browse files
author
CI Bot
committed
test: assert response status before calling .json() in server tests
Swap the order so SyntaxError from non-JSON error responses doesn't mask the real status code failure during CI.
1 parent f1ab75e commit 3154631

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

test/server.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ describe('Server API (Integration)', () => {
251251
headers: { 'Content-Type': 'application/json' },
252252
body: JSON.stringify({ slug: 'srv-showver', title: 'First', body: 'first body' }),
253253
});
254-
const v1 = await snap1.json();
255254
expect(snap1.status).toBe(200);
255+
const v1 = await snap1.json();
256256
const snap2 = await fetch(`${baseUrl}/api/cms/snapshot`, {
257257
method: 'POST',
258258
headers: { 'Content-Type': 'application/json' },
@@ -261,8 +261,8 @@ describe('Server API (Integration)', () => {
261261
expect(snap2.status).toBe(200);
262262

263263
const res = await fetch(`${baseUrl}/api/cms/show-version?slug=srv-showver&sha=${v1.sha}`);
264-
const data = await res.json();
265264
expect(res.status).toBe(200);
265+
const data = await res.json();
266266
expect(data.title).toBe('First');
267267
expect(data.body).toContain('first body');
268268
});
@@ -273,8 +273,8 @@ describe('Server API (Integration)', () => {
273273
headers: { 'Content-Type': 'application/json' },
274274
body: JSON.stringify({ slug: 'srv-restore', title: 'Original', body: 'original body' }),
275275
});
276-
const v1 = await snap1.json();
277276
expect(snap1.status).toBe(200);
277+
const v1 = await snap1.json();
278278
const snap2 = await fetch(`${baseUrl}/api/cms/snapshot`, {
279279
method: 'POST',
280280
headers: { 'Content-Type': 'application/json' },
@@ -287,8 +287,8 @@ describe('Server API (Integration)', () => {
287287
headers: { 'Content-Type': 'application/json' },
288288
body: JSON.stringify({ slug: 'srv-restore', sha: v1.sha }),
289289
});
290-
const data = await res.json();
291290
expect(res.status).toBe(200);
291+
const data = await res.json();
292292
expect(data.sha).toBeDefined();
293293

294294
// Verify content was restored

0 commit comments

Comments
 (0)