Skip to content

Commit dceb3e2

Browse files
authored
Merge pull request #796 from rust-lang/crates-route-mirage
Tweaks mirage response for /crates
2 parents 5194d62 + f94ffef commit dceb3e2

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

mirage/config.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,19 @@ export default function() {
1717
this.get('/summary', () => summaryFixture);
1818

1919
this.get('/api/v1/crates', (db, request) => {
20-
if (request.queryParams.q) {
21-
const { start, end } = pageParams(request);
22-
return {
23-
crates: searchFixture.crates.slice(start, end),
24-
meta: searchFixture.meta,
25-
};
26-
} else if (request.queryParams.team_id) {
27-
const { start, end } = pageParams(request);
28-
return {
29-
team: teamFixture.team,
30-
crates: searchFixture.crates.slice(start, end),
31-
meta: searchFixture.meta,
32-
};
20+
const { start, end } = pageParams(request);
21+
const payload = {
22+
crates: searchFixture.crates.slice(start, end),
23+
meta: searchFixture.meta,
24+
};
25+
26+
if (request.queryParams.team_id) {
27+
payload.team = teamFixture.team;
3328
} else if (request.queryParams.user_id) {
34-
const { start, end } = pageParams(request);
35-
return {
36-
user: userFixture.user,
37-
crates: searchFixture.crates.slice(start, end),
38-
meta: searchFixture.meta,
39-
};
29+
payload.user = userFixture.user;
4030
}
31+
32+
return payload;
4133
});
4234

4335
this.get('/api/v1/categories', () => categoriesFixture);

tests/acceptance/crates-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import hasText from 'cargo/tests/helpers/has-text';
4+
5+
moduleForAcceptance('Acceptance | crates page');
6+
7+
test('visiting the crates page from the front page', async function(assert) {
8+
await visit('/');
9+
await click('a[href="/crates"]');
10+
11+
assert.equal(currentURL(), '/crates');
12+
assert.equal(document.title, 'Crates - Cargo: packages for Rust');
13+
});
14+
15+
test('visiting the crates page directly', async function(assert) {
16+
await visit('/crates');
17+
await click('a[href="/crates"]');
18+
19+
assert.equal(currentURL(), '/crates');
20+
assert.equal(document.title, 'Crates - Cargo: packages for Rust');
21+
});
22+
23+
test('listing crates', async function(assert) {
24+
await visit('/crates');
25+
26+
hasText(assert, '.amt.small .cur', '1-10');
27+
hasText(assert, '.amt.small .total', '18');
28+
});
29+
30+
test('navigating to next page of crates', async function(assert) {
31+
await visit('/crates');
32+
await click('.pagination .next');
33+
34+
assert.equal(currentURL(), '/crates?page=2');
35+
hasText(assert, '.amt.small .cur', '11-18');
36+
hasText(assert, '.amt.small .total', '18');
37+
});

yarn.lock

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
22
# yarn lockfile v1
3-
# yarn v0.25.1
4-
# node v6.9.2
53

64

75
abbrev@1:
@@ -5141,11 +5139,11 @@ route-recognizer@^0.2.3:
51415139
version "0.2.9"
51425140
resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.2.9.tgz#fbe06d7b7a52185d85c945a4782a18361f886d15"
51435141

5144-
rsvp@^3.0.14, rsvp@^3.0.16, rsvp@^3.0.17, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.1.0, rsvp@^3.2.1, rsvp@^3.4.0:
5142+
rsvp@^3.0.14, rsvp@^3.0.16, rsvp@^3.0.17, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.1.0, rsvp@^3.4.0:
51455143
version "3.5.0"
51465144
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.5.0.tgz#a62c573a4ae4e1dfd0697ebc6242e79c681eaa34"
51475145

5148-
rsvp@^3.0.6, rsvp@^3.3.3:
5146+
rsvp@^3.0.6, rsvp@^3.2.1, rsvp@^3.3.3:
51495147
version "3.3.3"
51505148
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.3.3.tgz#34633caaf8bc66ceff4be3c2e1dffd032538a813"
51515149

0 commit comments

Comments
 (0)