Skip to content

Commit 4a8dc2e

Browse files
committed
mirage: Inline single-use responsePayload variables
1 parent aeecbed commit 4a8dc2e

29 files changed

+86
-257
lines changed

tests/mirage/categories/list-test.js

Lines changed: 7 additions & 21 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',
@@ -99,9 +95,7 @@ module('GET /api/v1/categories/:id', function () {
9995
test('returns 404 for unknown categories', async function (assert) {
10096
let response = await fetch('/api/v1/categories/foo');
10197
assert.equal(response.status, 404);
102-
103-
let responsePayload = await response.json();
104-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
98+
assert.deepEqual(await response.json(), { errors: [{ detail: 'Not Found' }] });
10599
});
106100

107101
test('returns a category object for known categories', async function (assert) {
@@ -112,9 +106,7 @@ module('GET /api/v1/categories/:id', function () {
112106

113107
let response = await fetch('/api/v1/categories/no-std');
114108
assert.equal(response.status, 200);
115-
116-
let responsePayload = await response.json();
117-
assert.deepEqual(responsePayload, {
109+
assert.deepEqual(await response.json(), {
118110
category: {
119111
id: 'no-std',
120112
category: 'no-std',
@@ -134,9 +126,7 @@ module('GET /api/v1/categories/:id', function () {
134126

135127
let response = await fetch('/api/v1/categories/cli');
136128
assert.equal(response.status, 200);
137-
138-
let responsePayload = await response.json();
139-
assert.deepEqual(responsePayload, {
129+
assert.deepEqual(await response.json(), {
140130
category: {
141131
category: 'cli',
142132
crates_cnt: 7,
@@ -153,9 +143,7 @@ module('GET /api/v1/category_slugs', function () {
153143
test('empty case', async function (assert) {
154144
let response = await fetch('/api/v1/category_slugs');
155145
assert.equal(response.status, 200);
156-
157-
let responsePayload = await response.json();
158-
assert.deepEqual(responsePayload, {
146+
assert.deepEqual(await response.json(), {
159147
category_slugs: [],
160148
});
161149
});
@@ -169,9 +157,7 @@ module('GET /api/v1/category_slugs', function () {
169157

170158
let response = await fetch('/api/v1/category_slugs');
171159
assert.equal(response.status, 200);
172-
173-
let responsePayload = await response.json();
174-
assert.deepEqual(responsePayload, {
160+
assert.deepEqual(await response.json(), {
175161
category_slugs: [
176162
{
177163
description: 'This is the description for the category called "Category 1"',

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,

tests/mirage/crates/reverse-dependencies-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/reverse_dependencies', function (hooks)
1212
test('returns 404 for unknown crates', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/reverse_dependencies');
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/reverse_dependencies');
2422
assert.equal(response.status, 200);
25-
26-
let responsePayload = await response.json();
27-
assert.deepEqual(responsePayload, {
23+
assert.deepEqual(await response.json(), {
2824
dependencies: [],
2925
versions: [],
3026
meta: {
@@ -52,9 +48,7 @@ module('Mirage | GET /api/v1/crates/:id/reverse_dependencies', function (hooks)
5248

5349
let response = await fetch('/api/v1/crates/foo/reverse_dependencies');
5450
assert.equal(response.status, 200);
55-
56-
let responsePayload = await response.json();
57-
assert.deepEqual(responsePayload, {
51+
assert.deepEqual(await response.json(), {
5852
dependencies: [
5953
{
6054
id: '1',

0 commit comments

Comments
 (0)