Skip to content

Commit ce1a38f

Browse files
committed
tests/acceptance/dashboard: Migrate from mirage to @crates-io/msw
1 parent 547a1d1 commit ce1a38f

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

tests/acceptance/dashboard-test.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { currentURL } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import percySnapshot from '@percy/ember';
5+
import { http, HttpResponse } from 'msw';
56

67
import { setupApplicationTest } from 'crates-io/tests/helpers';
78

89
import { visit } from '../helpers/visit-ignoring-abort';
910

1011
module('Acceptance | Dashboard', function (hooks) {
11-
setupApplicationTest(hooks);
12+
setupApplicationTest(hooks, { msw: true });
1213

1314
test('shows "page requires authentication" error when not logged in', async function (assert) {
1415
await visit('/dashboard');
@@ -18,7 +19,7 @@ module('Acceptance | Dashboard', function (hooks) {
1819
});
1920

2021
test('shows the dashboard when logged in', async function (assert) {
21-
let user = this.server.create('user', {
22+
let user = this.db.user.create({
2223
login: 'johnnydee',
2324
name: 'John Doe',
2425
@@ -28,31 +29,35 @@ module('Acceptance | Dashboard', function (hooks) {
2829
this.authenticateAs(user);
2930

3031
{
31-
let crate = this.server.create('crate', { name: 'rand' });
32-
this.server.create('version', { crate, num: '0.5.0' });
33-
this.server.create('version', { crate, num: '0.6.0' });
34-
this.server.create('version', { crate, num: '0.7.0' });
35-
this.server.create('version', { crate, num: '0.7.1' });
36-
this.server.create('version', { crate, num: '0.7.2' });
37-
this.server.create('version', { crate, num: '0.7.3' });
38-
this.server.create('version', { crate, num: '0.8.0' });
39-
this.server.create('version', { crate, num: '0.8.1' });
40-
this.server.create('version', { crate, num: '0.9.0' });
41-
this.server.create('version', { crate, num: '1.0.0' });
42-
this.server.create('version', { crate, num: '1.1.0' });
43-
user.followedCrates.add(crate);
32+
let crate = this.db.crate.create({ name: 'rand' });
33+
this.db.version.create({ crate, num: '0.5.0' });
34+
this.db.version.create({ crate, num: '0.6.0' });
35+
this.db.version.create({ crate, num: '0.7.0' });
36+
this.db.version.create({ crate, num: '0.7.1' });
37+
this.db.version.create({ crate, num: '0.7.2' });
38+
this.db.version.create({ crate, num: '0.7.3' });
39+
this.db.version.create({ crate, num: '0.8.0' });
40+
this.db.version.create({ crate, num: '0.8.1' });
41+
this.db.version.create({ crate, num: '0.9.0' });
42+
this.db.version.create({ crate, num: '1.0.0' });
43+
this.db.version.create({ crate, num: '1.1.0' });
44+
user = this.db.user.update({
45+
where: { id: { equals: user.id } },
46+
data: { followedCrates: [...user.followedCrates, crate] },
47+
});
4448
}
4549

4650
{
47-
let crate = this.server.create('crate', { name: 'nanomsg' });
48-
this.server.create('crate-ownership', { crate, user });
49-
this.server.create('version', { crate, num: '0.1.0' });
50-
user.followedCrates.add(crate);
51+
let crate = this.db.crate.create({ name: 'nanomsg' });
52+
this.db.crateOwnership.create({ crate, user });
53+
this.db.version.create({ crate, num: '0.1.0' });
54+
user = this.db.user.update({
55+
where: { id: { equals: user.id } },
56+
data: { followedCrates: [...user.followedCrates, crate] },
57+
});
5158
}
5259

53-
user.save();
54-
55-
this.server.get(`/api/v1/users/${user.id}/stats`, { total_downloads: 3892 });
60+
this.worker.use(http.get(`/api/v1/users/${user.id}/stats`, () => HttpResponse.json({ total_downloads: 3892 })));
5661

5762
await visit('/dashboard');
5863
assert.strictEqual(currentURL(), '/dashboard');

0 commit comments

Comments
 (0)