Skip to content

Commit da63600

Browse files
committed
mirage: Collapse nested test modules
1 parent 4ce3c80 commit da63600

31 files changed

+1791
-1853
lines changed

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

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,59 @@ import fetch from 'fetch';
55
import { setupTest } from '../../helpers';
66
import setupMirage from '../../helpers/setup-mirage';
77

8-
module('Mirage | Categories', function (hooks) {
8+
module('Mirage | GET /api/v1/categories/:id', function (hooks) {
99
setupTest(hooks);
1010
setupMirage(hooks);
1111

12-
module('GET /api/v1/categories/:id', function () {
13-
test('returns 404 for unknown categories', async function (assert) {
14-
let response = await fetch('/api/v1/categories/foo');
15-
assert.equal(response.status, 404);
12+
test('returns 404 for unknown categories', async function (assert) {
13+
let response = await fetch('/api/v1/categories/foo');
14+
assert.equal(response.status, 404);
1615

17-
let responsePayload = await response.json();
18-
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
16+
let responsePayload = await response.json();
17+
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
18+
});
19+
20+
test('returns a category object for known categories', async function (assert) {
21+
this.server.create('category', {
22+
category: 'no-std',
23+
description: 'Crates that are able to function without the Rust standard library.',
1924
});
2025

21-
test('returns a category object for known categories', async function (assert) {
22-
this.server.create('category', {
26+
let response = await fetch('/api/v1/categories/no-std');
27+
assert.equal(response.status, 200);
28+
29+
let responsePayload = await response.json();
30+
assert.deepEqual(responsePayload, {
31+
category: {
32+
id: 'no-std',
2333
category: 'no-std',
34+
crates_cnt: 0,
35+
created_at: '2010-06-16T21:30:45Z',
2436
description: 'Crates that are able to function without the Rust standard library.',
25-
});
26-
27-
let response = await fetch('/api/v1/categories/no-std');
28-
assert.equal(response.status, 200);
29-
30-
let responsePayload = await response.json();
31-
assert.deepEqual(responsePayload, {
32-
category: {
33-
id: 'no-std',
34-
category: 'no-std',
35-
crates_cnt: 0,
36-
created_at: '2010-06-16T21:30:45Z',
37-
description: 'Crates that are able to function without the Rust standard library.',
38-
slug: 'no-std',
39-
},
40-
});
37+
slug: 'no-std',
38+
},
4139
});
40+
});
4241

43-
test('calculates `crates_cnt` correctly', async function (assert) {
44-
this.server.create('category', { category: 'cli' });
45-
this.server.createList('crate', 7, { categoryIds: ['cli'] });
46-
this.server.create('category', { category: 'not-cli' });
47-
this.server.createList('crate', 3, { categoryIds: ['not-cli'] });
48-
49-
let response = await fetch('/api/v1/categories/cli');
50-
assert.equal(response.status, 200);
51-
52-
let responsePayload = await response.json();
53-
assert.deepEqual(responsePayload, {
54-
category: {
55-
category: 'cli',
56-
crates_cnt: 7,
57-
created_at: '2010-06-16T21:30:45Z',
58-
description: 'This is the description for the category called "cli"',
59-
id: 'cli',
60-
slug: 'cli',
61-
},
62-
});
42+
test('calculates `crates_cnt` correctly', async function (assert) {
43+
this.server.create('category', { category: 'cli' });
44+
this.server.createList('crate', 7, { categoryIds: ['cli'] });
45+
this.server.create('category', { category: 'not-cli' });
46+
this.server.createList('crate', 3, { categoryIds: ['not-cli'] });
47+
48+
let response = await fetch('/api/v1/categories/cli');
49+
assert.equal(response.status, 200);
50+
51+
let responsePayload = await response.json();
52+
assert.deepEqual(responsePayload, {
53+
category: {
54+
category: 'cli',
55+
crates_cnt: 7,
56+
created_at: '2010-06-16T21:30:45Z',
57+
description: 'This is the description for the category called "cli"',
58+
id: 'cli',
59+
slug: 'cli',
60+
},
6361
});
6462
});
6563
});

tests/mirage/categories/list-test.js

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,94 +5,92 @@ import fetch from 'fetch';
55
import { setupTest } from '../../helpers';
66
import setupMirage from '../../helpers/setup-mirage';
77

8-
module('Mirage | Categories', function (hooks) {
8+
module('Mirage | GET /api/v1/categories', function (hooks) {
99
setupTest(hooks);
1010
setupMirage(hooks);
1111

12-
module('GET /api/v1/categories', function () {
13-
test('empty case', async function (assert) {
14-
let response = await fetch('/api/v1/categories');
15-
assert.equal(response.status, 200);
12+
test('empty case', async function (assert) {
13+
let response = await fetch('/api/v1/categories');
14+
assert.equal(response.status, 200);
1615

17-
let responsePayload = await response.json();
18-
assert.deepEqual(responsePayload, {
19-
categories: [],
20-
meta: {
21-
total: 0,
22-
},
23-
});
16+
let responsePayload = await response.json();
17+
assert.deepEqual(responsePayload, {
18+
categories: [],
19+
meta: {
20+
total: 0,
21+
},
2422
});
23+
});
2524

26-
test('returns a paginated categories list', async function (assert) {
27-
this.server.create('category', {
28-
category: 'no-std',
29-
description: 'Crates that are able to function without the Rust standard library.',
30-
});
31-
this.server.createList('category', 2);
25+
test('returns a paginated categories list', async function (assert) {
26+
this.server.create('category', {
27+
category: 'no-std',
28+
description: 'Crates that are able to function without the Rust standard library.',
29+
});
30+
this.server.createList('category', 2);
3231

33-
let response = await fetch('/api/v1/categories');
34-
assert.equal(response.status, 200);
32+
let response = await fetch('/api/v1/categories');
33+
assert.equal(response.status, 200);
3534

36-
let responsePayload = await response.json();
37-
assert.deepEqual(responsePayload, {
38-
categories: [
39-
{
40-
id: 'category-1',
41-
category: 'Category 1',
42-
crates_cnt: 0,
43-
created_at: '2010-06-16T21:30:45Z',
44-
description: 'This is the description for the category called "Category 1"',
45-
slug: 'category-1',
46-
},
47-
{
48-
id: 'category-2',
49-
category: 'Category 2',
50-
crates_cnt: 0,
51-
created_at: '2010-06-16T21:30:45Z',
52-
description: 'This is the description for the category called "Category 2"',
53-
slug: 'category-2',
54-
},
55-
{
56-
id: 'no-std',
57-
category: 'no-std',
58-
crates_cnt: 0,
59-
created_at: '2010-06-16T21:30:45Z',
60-
description: 'Crates that are able to function without the Rust standard library.',
61-
slug: 'no-std',
62-
},
63-
],
64-
meta: {
65-
total: 3,
35+
let responsePayload = await response.json();
36+
assert.deepEqual(responsePayload, {
37+
categories: [
38+
{
39+
id: 'category-1',
40+
category: 'Category 1',
41+
crates_cnt: 0,
42+
created_at: '2010-06-16T21:30:45Z',
43+
description: 'This is the description for the category called "Category 1"',
44+
slug: 'category-1',
45+
},
46+
{
47+
id: 'category-2',
48+
category: 'Category 2',
49+
crates_cnt: 0,
50+
created_at: '2010-06-16T21:30:45Z',
51+
description: 'This is the description for the category called "Category 2"',
52+
slug: 'category-2',
53+
},
54+
{
55+
id: 'no-std',
56+
category: 'no-std',
57+
crates_cnt: 0,
58+
created_at: '2010-06-16T21:30:45Z',
59+
description: 'Crates that are able to function without the Rust standard library.',
60+
slug: 'no-std',
6661
},
67-
});
62+
],
63+
meta: {
64+
total: 3,
65+
},
6866
});
67+
});
6968

70-
test('never returns more than 10 results', async function (assert) {
71-
this.server.createList('category', 25);
69+
test('never returns more than 10 results', async function (assert) {
70+
this.server.createList('category', 25);
7271

73-
let response = await fetch('/api/v1/categories');
74-
assert.equal(response.status, 200);
72+
let response = await fetch('/api/v1/categories');
73+
assert.equal(response.status, 200);
7574

76-
let responsePayload = await response.json();
77-
assert.equal(responsePayload.categories.length, 10);
78-
assert.equal(responsePayload.meta.total, 25);
79-
});
75+
let responsePayload = await response.json();
76+
assert.equal(responsePayload.categories.length, 10);
77+
assert.equal(responsePayload.meta.total, 25);
78+
});
8079

81-
test('supports `page` and `per_page` parameters', async function (assert) {
82-
this.server.createList('category', 25, {
83-
category: i => `cat-${String(i + 1).padStart(2, '0')}`,
84-
});
80+
test('supports `page` and `per_page` parameters', async function (assert) {
81+
this.server.createList('category', 25, {
82+
category: i => `cat-${String(i + 1).padStart(2, '0')}`,
83+
});
8584

86-
let response = await fetch('/api/v1/categories?page=2&per_page=5');
87-
assert.equal(response.status, 200);
85+
let response = await fetch('/api/v1/categories?page=2&per_page=5');
86+
assert.equal(response.status, 200);
8887

89-
let responsePayload = await response.json();
90-
assert.equal(responsePayload.categories.length, 5);
91-
assert.deepEqual(
92-
responsePayload.categories.map(it => it.id),
93-
['cat-06', 'cat-07', 'cat-08', 'cat-09', 'cat-10'],
94-
);
95-
assert.equal(responsePayload.meta.total, 25);
96-
});
88+
let responsePayload = await response.json();
89+
assert.equal(responsePayload.categories.length, 5);
90+
assert.deepEqual(
91+
responsePayload.categories.map(it => it.id),
92+
['cat-06', 'cat-07', 'cat-08', 'cat-09', 'cat-10'],
93+
);
94+
assert.equal(responsePayload.meta.total, 25);
9795
});
9896
});

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

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,59 @@ import fetch from 'fetch';
55
import { setupTest } from '../../helpers';
66
import setupMirage from '../../helpers/setup-mirage';
77

8-
module('Mirage | Categories', function (hooks) {
8+
module('Mirage | GET /api/v1/category_slugs', function (hooks) {
99
setupTest(hooks);
1010
setupMirage(hooks);
1111

12-
module('GET /api/v1/category_slugs', function () {
13-
test('empty case', async function (assert) {
14-
let response = await fetch('/api/v1/category_slugs');
15-
assert.equal(response.status, 200);
12+
test('empty case', async function (assert) {
13+
let response = await fetch('/api/v1/category_slugs');
14+
assert.equal(response.status, 200);
1615

17-
let responsePayload = await response.json();
18-
assert.deepEqual(responsePayload, {
19-
category_slugs: [],
20-
});
16+
let responsePayload = await response.json();
17+
assert.deepEqual(responsePayload, {
18+
category_slugs: [],
2119
});
20+
});
2221

23-
test('returns a category slugs list', async function (assert) {
24-
this.server.create('category', {
25-
category: 'no-std',
26-
description: 'Crates that are able to function without the Rust standard library.',
27-
});
28-
this.server.createList('category', 2);
29-
30-
let response = await fetch('/api/v1/category_slugs');
31-
assert.equal(response.status, 200);
32-
33-
let responsePayload = await response.json();
34-
assert.deepEqual(responsePayload, {
35-
category_slugs: [
36-
{
37-
description: 'This is the description for the category called "Category 1"',
38-
id: 'category-1',
39-
slug: 'category-1',
40-
},
41-
{
42-
description: 'This is the description for the category called "Category 2"',
43-
id: 'category-2',
44-
slug: 'category-2',
45-
},
46-
{
47-
description: 'Crates that are able to function without the Rust standard library.',
48-
id: 'no-std',
49-
slug: 'no-std',
50-
},
51-
],
52-
});
22+
test('returns a category slugs list', async function (assert) {
23+
this.server.create('category', {
24+
category: 'no-std',
25+
description: 'Crates that are able to function without the Rust standard library.',
5326
});
27+
this.server.createList('category', 2);
28+
29+
let response = await fetch('/api/v1/category_slugs');
30+
assert.equal(response.status, 200);
31+
32+
let responsePayload = await response.json();
33+
assert.deepEqual(responsePayload, {
34+
category_slugs: [
35+
{
36+
description: 'This is the description for the category called "Category 1"',
37+
id: 'category-1',
38+
slug: 'category-1',
39+
},
40+
{
41+
description: 'This is the description for the category called "Category 2"',
42+
id: 'category-2',
43+
slug: 'category-2',
44+
},
45+
{
46+
description: 'Crates that are able to function without the Rust standard library.',
47+
id: 'no-std',
48+
slug: 'no-std',
49+
},
50+
],
51+
});
52+
});
5453

55-
test('has no pagination', async function (assert) {
56-
this.server.createList('category', 25);
54+
test('has no pagination', async function (assert) {
55+
this.server.createList('category', 25);
5756

58-
let response = await fetch('/api/v1/category_slugs');
59-
assert.equal(response.status, 200);
57+
let response = await fetch('/api/v1/category_slugs');
58+
assert.equal(response.status, 200);
6059

61-
let responsePayload = await response.json();
62-
assert.equal(responsePayload.category_slugs.length, 25);
63-
});
60+
let responsePayload = await response.json();
61+
assert.equal(responsePayload.category_slugs.length, 25);
6462
});
6563
});

0 commit comments

Comments
 (0)