Skip to content

Commit ba15b2c

Browse files
committed
mirage: Inline single-use responsePayload variables
1 parent da63600 commit ba15b2c

31 files changed

+87
-260
lines changed

tests/mirage/categories/get-by-id-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | GET /api/v1/categories/:id', function (hooks) {
1212
test('returns 404 for unknown categories', async function (assert) {
1313
let response = await fetch('/api/v1/categories/foo');
1414
assert.equal(response.status, 404);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
15+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
1816
});
1917

2018
test('returns a category object for known categories', async function (assert) {
@@ -25,9 +23,7 @@ module('Mirage | GET /api/v1/categories/:id', function (hooks) {
2523

2624
let response = await fetch('/api/v1/categories/no-std');
2725
assert.equal(response.status, 200);
28-
29-
let responsePayload = await response.json();
30-
assert.deepEqual(responsePayload, {
26+
assert.deepEqual(await response.json(), {
3127
category: {
3228
id: 'no-std',
3329
category: 'no-std',
@@ -47,9 +43,7 @@ module('Mirage | GET /api/v1/categories/:id', function (hooks) {
4743

4844
let response = await fetch('/api/v1/categories/cli');
4945
assert.equal(response.status, 200);
50-
51-
let responsePayload = await response.json();
52-
assert.deepEqual(responsePayload, {
46+
assert.deepEqual(await response.json(), {
5347
category: {
5448
category: 'cli',
5549
crates_cnt: 7,

tests/mirage/categories/list-test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | GET /api/v1/categories', function (hooks) {
1212
test('empty case', async function (assert) {
1313
let response = await fetch('/api/v1/categories');
1414
assert.equal(response.status, 200);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, {
15+
assert.deepEqual(await response.json(), {
1816
categories: [],
1917
meta: {
2018
total: 0,
@@ -31,9 +29,7 @@ module('Mirage | GET /api/v1/categories', function (hooks) {
3129

3230
let response = await fetch('/api/v1/categories');
3331
assert.equal(response.status, 200);
34-
35-
let responsePayload = await response.json();
36-
assert.deepEqual(responsePayload, {
32+
assert.deepEqual(await response.json(), {
3733
categories: [
3834
{
3935
id: 'category-1',

tests/mirage/category-slugs/list-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | GET /api/v1/category_slugs', function (hooks) {
1212
test('empty case', async function (assert) {
1313
let response = await fetch('/api/v1/category_slugs');
1414
assert.equal(response.status, 200);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, {
15+
assert.deepEqual(await response.json(), {
1816
category_slugs: [],
1917
});
2018
});
@@ -28,9 +26,7 @@ module('Mirage | GET /api/v1/category_slugs', function (hooks) {
2826

2927
let response = await fetch('/api/v1/category_slugs');
3028
assert.equal(response.status, 200);
31-
32-
let responsePayload = await response.json();
33-
assert.deepEqual(responsePayload, {
29+
assert.deepEqual(await response.json(), {
3430
category_slugs: [
3531
{
3632
description: 'This is the description for the category called "Category 1"',
@@ -56,8 +52,6 @@ module('Mirage | GET /api/v1/category_slugs', function (hooks) {
5652

5753
let response = await fetch('/api/v1/category_slugs');
5854
assert.equal(response.status, 200);
59-
60-
let responsePayload = await response.json();
61-
assert.equal(responsePayload.category_slugs.length, 25);
55+
assert.equal((await response.json()).category_slugs.length, 25);
6256
});
6357
});

tests/mirage/confirm/put-by-id-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ module('Mirage | PUT /api/v1/confirm/:token', function (hooks) {
1515

1616
let response = await fetch('/api/v1/confirm/foo', { method: 'PUT' });
1717
assert.equal(response.status, 200);
18-
19-
let responsePayload = await response.json();
20-
assert.deepEqual(responsePayload, { ok: true });
18+
assert.deepEqual(await response.json(), { ok: true });
2119

2220
user.reload();
2321
assert.strictEqual(user.emailVerified, true);
@@ -31,9 +29,7 @@ module('Mirage | PUT /api/v1/confirm/:token', function (hooks) {
3129

3230
let response = await fetch('/api/v1/confirm/foo', { method: 'PUT' });
3331
assert.equal(response.status, 200);
34-
35-
let responsePayload = await response.json();
36-
assert.deepEqual(responsePayload, { ok: true });
32+
assert.deepEqual(await response.json(), { ok: true });
3733

3834
user.reload();
3935
assert.strictEqual(user.emailVerified, true);
@@ -42,9 +38,7 @@ module('Mirage | PUT /api/v1/confirm/:token', function (hooks) {
4238
test('returns an error for unknown tokens', async function (assert) {
4339
let response = await fetch('/api/v1/confirm/unknown', { method: 'PUT' });
4440
assert.equal(response.status, 400);
45-
46-
let responsePayload = await response.json();
47-
assert.deepEqual(responsePayload, {
41+
assert.deepEqual(await response.json(), {
4842
errors: [{ detail: 'Email belonging to token not found.' }],
4943
});
5044
});

tests/mirage/crates/downloads-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ module('Mirage | GET /api/v1/crates/:id/downloads', function (hooks) {
1212
test('returns 404 for unknown crates', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/downloads');
1414
assert.equal(response.status, 404);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
15+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
1816
});
1917

2018
test('empty case', async function (assert) {
2119
this.server.create('crate', { name: 'rand' });
2220

2321
let response = await fetch('/api/v1/crates/rand/downloads');
2422
assert.equal(response.status, 200);
25-
26-
let responsePayload = await response.json();
27-
assert.deepEqual(responsePayload, {
23+
assert.deepEqual(await response.json(), {
2824
version_downloads: [],
2925
meta: {
3026
extra_downloads: [],
@@ -41,9 +37,7 @@ module('Mirage | GET /api/v1/crates/:id/downloads', function (hooks) {
4137

4238
let response = await fetch('/api/v1/crates/rand/downloads');
4339
assert.equal(response.status, 200);
44-
45-
let responsePayload = await response.json();
46-
assert.deepEqual(responsePayload, {
40+
assert.deepEqual(await response.json(), {
4741
version_downloads: [
4842
{
4943
date: '2020-01-13',

tests/mirage/crates/follow/delete-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | DELETE /api/v1/crates/:crateId/follow', function (hooks) {
1212
test('returns 403 if unauthenticated', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/follow', { method: 'DELETE' });
1414
assert.equal(response.status, 403);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, {
15+
assert.deepEqual(await response.json(), {
1816
errors: [{ detail: 'must be logged in to perform that action' }],
1917
});
2018
});
@@ -25,9 +23,7 @@ module('Mirage | DELETE /api/v1/crates/:crateId/follow', function (hooks) {
2523

2624
let response = await fetch('/api/v1/crates/foo/follow', { method: 'DELETE' });
2725
assert.equal(response.status, 404);
28-
29-
let responsePayload = await response.json();
30-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
26+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
3127
});
3228

3329
test('makes the authenticated user unfollow the crate', async function (assert) {
@@ -40,9 +36,7 @@ module('Mirage | DELETE /api/v1/crates/:crateId/follow', function (hooks) {
4036

4137
let response = await fetch('/api/v1/crates/rand/follow', { method: 'DELETE' });
4238
assert.equal(response.status, 200);
43-
44-
let responsePayload = await response.json();
45-
assert.deepEqual(responsePayload, { ok: true });
39+
assert.deepEqual(await response.json(), { ok: true });
4640

4741
user.reload();
4842
assert.deepEqual(user.followedCrateIds, []);

tests/mirage/crates/follow/get-test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | GET /api/v1/crates/:crateId/following', function (hooks) {
1212
test('returns 403 if unauthenticated', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/following');
1414
assert.equal(response.status, 403);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, {
15+
assert.deepEqual(await response.json(), {
1816
errors: [{ detail: 'must be logged in to perform that action' }],
1917
});
2018
});
@@ -25,9 +23,7 @@ module('Mirage | GET /api/v1/crates/:crateId/following', function (hooks) {
2523

2624
let response = await fetch('/api/v1/crates/foo/following');
2725
assert.equal(response.status, 404);
28-
29-
let responsePayload = await response.json();
30-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
26+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
3127
});
3228

3329
test('returns true if the authenticated user follows the crate', async function (assert) {
@@ -38,9 +34,7 @@ module('Mirage | GET /api/v1/crates/:crateId/following', function (hooks) {
3834

3935
let response = await fetch('/api/v1/crates/rand/following');
4036
assert.equal(response.status, 200);
41-
42-
let responsePayload = await response.json();
43-
assert.deepEqual(responsePayload, { following: true });
37+
assert.deepEqual(await response.json(), { following: true });
4438
});
4539

4640
test('returns false if the authenticated user is not following the crate', async function (assert) {
@@ -51,8 +45,6 @@ module('Mirage | GET /api/v1/crates/:crateId/following', function (hooks) {
5145

5246
let response = await fetch('/api/v1/crates/rand/following');
5347
assert.equal(response.status, 200);
54-
55-
let responsePayload = await response.json();
56-
assert.deepEqual(responsePayload, { following: false });
48+
assert.deepEqual(await response.json(), { following: false });
5749
});
5850
});

tests/mirage/crates/follow/put-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | PUT /api/v1/crates/:crateId/follow', function (hooks) {
1212
test('returns 403 if unauthenticated', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/follow', { method: 'PUT' });
1414
assert.equal(response.status, 403);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, {
15+
assert.deepEqual(await response.json(), {
1816
errors: [{ detail: 'must be logged in to perform that action' }],
1917
});
2018
});
@@ -25,9 +23,7 @@ module('Mirage | PUT /api/v1/crates/:crateId/follow', function (hooks) {
2523

2624
let response = await fetch('/api/v1/crates/foo/follow', { method: 'PUT' });
2725
assert.equal(response.status, 404);
28-
29-
let responsePayload = await response.json();
30-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
26+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
3127
});
3228

3329
test('makes the authenticated user follow the crate', async function (assert) {
@@ -40,9 +36,7 @@ module('Mirage | PUT /api/v1/crates/:crateId/follow', function (hooks) {
4036

4137
let response = await fetch('/api/v1/crates/rand/follow', { method: 'PUT' });
4238
assert.equal(response.status, 200);
43-
44-
let responsePayload = await response.json();
45-
assert.deepEqual(responsePayload, { ok: true });
39+
assert.deepEqual(await response.json(), { ok: true });
4640

4741
user.reload();
4842
assert.deepEqual(user.followedCrateIds, [crate.id]);

tests/mirage/crates/get-by-id-test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | GET /api/v1/crates/:id', function (hooks) {
1212
test('returns 404 for unknown crates', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo');
1414
assert.equal(response.status, 404);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
15+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
1816
});
1917

2018
test('returns a crate object for known crates', async function (assert) {
@@ -23,9 +21,7 @@ module('Mirage | GET /api/v1/crates/:id', function (hooks) {
2321

2422
let response = await fetch('/api/v1/crates/rand');
2523
assert.equal(response.status, 200);
26-
27-
let responsePayload = await response.json();
28-
assert.deepEqual(responsePayload, {
24+
assert.deepEqual(await response.json(), {
2925
categories: [],
3026
crate: {
3127
badges: [],

tests/mirage/crates/list-test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module('Mirage | GET /api/v1/crates', function (hooks) {
1212
test('empty case', async function (assert) {
1313
let response = await fetch('/api/v1/crates');
1414
assert.equal(response.status, 200);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, {
15+
assert.deepEqual(await response.json(), {
1816
crates: [],
1917
meta: {
2018
total: 0,
@@ -39,9 +37,7 @@ module('Mirage | GET /api/v1/crates', function (hooks) {
3937

4038
let response = await fetch('/api/v1/crates');
4139
assert.equal(response.status, 200);
42-
43-
let responsePayload = await response.json();
44-
assert.deepEqual(responsePayload, {
40+
assert.deepEqual(await response.json(), {
4541
crates: [
4642
{
4743
id: 'rand',

tests/mirage/crates/owner-team-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ module('Mirage | GET /api/v1/crates/:id/owner_team', function (hooks) {
1212
test('returns 404 for unknown crates', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/owner_team');
1414
assert.equal(response.status, 404);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
15+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
1816
});
1917

2018
test('empty case', async function (assert) {
2119
this.server.create('crate', { name: 'rand' });
2220

2321
let response = await fetch('/api/v1/crates/rand/owner_team');
2422
assert.equal(response.status, 200);
25-
26-
let responsePayload = await response.json();
27-
assert.deepEqual(responsePayload, {
23+
assert.deepEqual(await response.json(), {
2824
teams: [],
2925
});
3026
});
@@ -36,9 +32,7 @@ module('Mirage | GET /api/v1/crates/:id/owner_team', function (hooks) {
3632

3733
let response = await fetch('/api/v1/crates/rand/owner_team');
3834
assert.equal(response.status, 200);
39-
40-
let responsePayload = await response.json();
41-
assert.deepEqual(responsePayload, {
35+
assert.deepEqual(await response.json(), {
4236
teams: [
4337
{
4438
id: 1,

tests/mirage/crates/owner-user-test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ module('Mirage | GET /api/v1/crates/:id/owner_user', function (hooks) {
1212
test('returns 404 for unknown crates', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/owner_user');
1414
assert.equal(response.status, 404);
15-
16-
let responsePayload = await response.json();
17-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
15+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
1816
});
1917

2018
test('empty case', async function (assert) {
2119
this.server.create('crate', { name: 'rand' });
2220

2321
let response = await fetch('/api/v1/crates/rand/owner_user');
2422
assert.equal(response.status, 200);
25-
26-
let responsePayload = await response.json();
27-
assert.deepEqual(responsePayload, {
23+
assert.deepEqual(await response.json(), {
2824
users: [],
2925
});
3026
});
@@ -36,9 +32,7 @@ module('Mirage | GET /api/v1/crates/:id/owner_user', function (hooks) {
3632

3733
let response = await fetch('/api/v1/crates/rand/owner_user');
3834
assert.equal(response.status, 200);
39-
40-
let responsePayload = await response.json();
41-
assert.deepEqual(responsePayload, {
35+
assert.deepEqual(await response.json(), {
4236
users: [
4337
{
4438
id: 1,

0 commit comments

Comments
 (0)