Skip to content

Commit 32a5201

Browse files
committed
Add tests for GET /api/v1/summary mirage request handler
1 parent 0f11af4 commit 32a5201

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

tests/mirage/summary-test.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import { setupTest } from 'ember-qunit';
2+
import { module, test } from 'qunit';
3+
4+
import setupMirage from '../helpers/setup-mirage';
5+
import fetch from 'fetch';
6+
7+
module('Mirage | Summary', function(hooks) {
8+
setupTest(hooks);
9+
setupMirage(hooks);
10+
11+
module('GET /api/v1/summary', function() {
12+
test('empty case', async function(assert) {
13+
let response = await fetch('/api/v1/summary');
14+
assert.equal(response.status, 200);
15+
16+
let responsePayload = await response.json();
17+
assert.deepEqual(responsePayload, {
18+
just_updated: [],
19+
most_downloaded: [],
20+
most_recently_downloaded: [],
21+
new_crates: [],
22+
num_crates: 0,
23+
num_downloads: 0,
24+
popular_categories: [],
25+
popular_keywords: [],
26+
});
27+
});
28+
29+
test('returns the data for the front page', async function(assert) {
30+
this.server.createList('category', 15);
31+
this.server.createList('keyword', 25);
32+
this.server.createList('crate', 20);
33+
34+
let response = await fetch('/api/v1/summary');
35+
assert.equal(response.status, 200);
36+
37+
let responsePayload = await response.json();
38+
39+
assert.equal(responsePayload.just_updated.length, 10);
40+
assert.deepEqual(responsePayload.just_updated[0], {
41+
id: 'crate-0',
42+
badges: [],
43+
categories: [],
44+
created_at: '2010-06-16T21:30:45Z',
45+
description: 'This is the description for the crate called "crate-0"',
46+
documentation: null,
47+
downloads: 0,
48+
homepage: null,
49+
keywords: [],
50+
links: {
51+
owner_team: '/api/v1/crates/crate-0/owner_team',
52+
owner_user: '/api/v1/crates/crate-0/owner_user',
53+
reverse_dependencies: '/api/v1/crates/crate-0/reverse_dependencies',
54+
version_downloads: '/api/v1/crates/crate-0/downloads',
55+
versions: '/api/v1/crates/crate-0/versions',
56+
},
57+
max_version: '1.0.0',
58+
name: 'crate-0',
59+
newest_version: '1.0.0',
60+
repository: null,
61+
updated_at: '2017-02-24T12:34:56Z',
62+
versions: null,
63+
});
64+
65+
assert.equal(responsePayload.most_downloaded.length, 10);
66+
assert.deepEqual(responsePayload.most_downloaded[0], {
67+
id: 'crate-4',
68+
badges: [],
69+
categories: [],
70+
created_at: '2010-06-16T21:30:45Z',
71+
description: 'This is the description for the crate called "crate-4"',
72+
documentation: null,
73+
downloads: 148140,
74+
homepage: null,
75+
keywords: [],
76+
links: {
77+
owner_team: '/api/v1/crates/crate-4/owner_team',
78+
owner_user: '/api/v1/crates/crate-4/owner_user',
79+
reverse_dependencies: '/api/v1/crates/crate-4/reverse_dependencies',
80+
version_downloads: '/api/v1/crates/crate-4/downloads',
81+
versions: '/api/v1/crates/crate-4/versions',
82+
},
83+
max_version: '1.0.0',
84+
name: 'crate-4',
85+
newest_version: '1.0.0',
86+
repository: null,
87+
updated_at: '2017-02-24T12:34:56Z',
88+
versions: null,
89+
});
90+
91+
assert.equal(responsePayload.most_recently_downloaded.length, 10);
92+
assert.deepEqual(responsePayload.most_recently_downloaded[0], {
93+
id: 'crate-0',
94+
badges: [],
95+
categories: [],
96+
created_at: '2010-06-16T21:30:45Z',
97+
description: 'This is the description for the crate called "crate-0"',
98+
documentation: null,
99+
downloads: 0,
100+
homepage: null,
101+
keywords: [],
102+
links: {
103+
owner_team: '/api/v1/crates/crate-0/owner_team',
104+
owner_user: '/api/v1/crates/crate-0/owner_user',
105+
reverse_dependencies: '/api/v1/crates/crate-0/reverse_dependencies',
106+
version_downloads: '/api/v1/crates/crate-0/downloads',
107+
versions: '/api/v1/crates/crate-0/versions',
108+
},
109+
max_version: '1.0.0',
110+
name: 'crate-0',
111+
newest_version: '1.0.0',
112+
repository: null,
113+
updated_at: '2017-02-24T12:34:56Z',
114+
versions: null,
115+
});
116+
117+
assert.equal(responsePayload.new_crates.length, 10);
118+
assert.deepEqual(responsePayload.new_crates[0], {
119+
id: 'crate-0',
120+
badges: [],
121+
categories: [],
122+
created_at: '2010-06-16T21:30:45Z',
123+
description: 'This is the description for the crate called "crate-0"',
124+
documentation: null,
125+
downloads: 0,
126+
homepage: null,
127+
keywords: [],
128+
links: {
129+
owner_team: '/api/v1/crates/crate-0/owner_team',
130+
owner_user: '/api/v1/crates/crate-0/owner_user',
131+
reverse_dependencies: '/api/v1/crates/crate-0/reverse_dependencies',
132+
version_downloads: '/api/v1/crates/crate-0/downloads',
133+
versions: '/api/v1/crates/crate-0/versions',
134+
},
135+
max_version: '1.0.0',
136+
name: 'crate-0',
137+
newest_version: '1.0.0',
138+
repository: null,
139+
updated_at: '2017-02-24T12:34:56Z',
140+
versions: null,
141+
});
142+
143+
assert.equal(responsePayload.num_crates, 20);
144+
assert.equal(responsePayload.num_downloads, 1419675);
145+
146+
assert.equal(responsePayload.popular_categories.length, 10);
147+
assert.deepEqual(responsePayload.popular_categories[0], {
148+
id: 'category-0',
149+
category: 'Category 0',
150+
crates_cnt: 0,
151+
created_at: '2010-06-16T21:30:45Z',
152+
description: 'This is the description for the category called "Category 0"',
153+
slug: 'category-0',
154+
});
155+
156+
assert.equal(responsePayload.popular_keywords.length, 10);
157+
assert.deepEqual(responsePayload.popular_keywords[0], {
158+
id: 'keyword-1',
159+
crates_cnt: 0,
160+
keyword: 'keyword-1',
161+
});
162+
});
163+
});
164+
});

0 commit comments

Comments
 (0)