Skip to content

Commit 55691de

Browse files
committed
msw: Migrate QUnit test suite to new @msw/data API
1 parent 8000f7d commit 55691de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+833
-848
lines changed

tests/acceptance/api-token-test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,42 @@ import { visit } from '../helpers/visit-ignoring-abort';
1111
module('Acceptance | api-tokens', function (hooks) {
1212
setupApplicationTest(hooks);
1313

14-
function prepare(context) {
15-
let user = context.db.user.create({
14+
async function prepare(context) {
15+
let user = await context.db.user.create({
1616
login: 'johnnydee',
1717
name: 'John Doe',
1818
email: 'john@doe.com',
1919
avatar: 'https://avatars2.githubusercontent.com/u/1234567?v=4',
2020
});
2121

22-
context.db.apiToken.create({
22+
await context.db.apiToken.create({
2323
user,
2424
name: 'foo',
2525
createdAt: '2017-08-01T12:34:56',
2626
lastUsedAt: '2017-11-02T01:45:14',
2727
});
2828

29-
context.db.apiToken.create({
29+
await context.db.apiToken.create({
3030
user,
3131
name: 'BAR',
3232
createdAt: '2017-11-19T17:59:22',
3333
lastUsedAt: null,
3434
expiredAt: '2017-12-19T17:59:22',
3535
});
3636

37-
context.db.apiToken.create({
37+
await context.db.apiToken.create({
3838
user,
3939
name: 'recently expired',
4040
createdAt: '2017-08-01T12:34:56',
4141
lastUsedAt: '2017-11-02T01:45:14',
4242
expiredAt: '2017-11-19T17:59:22',
4343
});
4444

45-
context.authenticateAs(user);
45+
await context.authenticateAs(user);
4646
}
4747

4848
test('/me is showing the list of active API tokens', async function (assert) {
49-
prepare(this);
49+
await prepare(this);
5050

5151
await visit('/settings/tokens');
5252
assert.strictEqual(currentURL(), '/settings/tokens');
@@ -85,7 +85,7 @@ module('Acceptance | api-tokens', function (hooks) {
8585
});
8686

8787
test('API tokens can be revoked', async function (assert) {
88-
prepare(this);
88+
await prepare(this);
8989

9090
await visit('/settings/tokens');
9191
assert.strictEqual(currentURL(), '/settings/tokens');
@@ -104,7 +104,7 @@ module('Acceptance | api-tokens', function (hooks) {
104104
});
105105

106106
test('API tokens can be regenerated', async function (assert) {
107-
prepare(this);
107+
await prepare(this);
108108

109109
await visit('/settings/tokens');
110110
assert.strictEqual(currentURL(), '/settings/tokens');
@@ -124,7 +124,7 @@ module('Acceptance | api-tokens', function (hooks) {
124124
});
125125

126126
test('failed API tokens revocation shows an error', async function (assert) {
127-
prepare(this);
127+
await prepare(this);
128128

129129
this.worker.use(
130130
http.delete('/api/v1/me/tokens/:id', function () {
@@ -146,7 +146,7 @@ module('Acceptance | api-tokens', function (hooks) {
146146
});
147147

148148
test('new API tokens can be created', async function (assert) {
149-
prepare(this);
149+
await prepare(this);
150150

151151
await visit('/settings/tokens');
152152
assert.strictEqual(currentURL(), '/settings/tokens');
@@ -161,7 +161,7 @@ module('Acceptance | api-tokens', function (hooks) {
161161

162162
await click('[data-test-generate]');
163163

164-
let token = this.db.apiToken.findFirst({ where: { name: { equals: 'the new token' } } });
164+
let token = this.db.apiToken.findFirst(q => q.where({ name: 'the new token' }));
165165
assert.ok(Boolean(token), 'API token has been created in the backend database');
166166

167167
assert.dom('[data-test-api-token="4"] [data-test-name]').hasText('the new token');
@@ -173,15 +173,15 @@ module('Acceptance | api-tokens', function (hooks) {
173173
});
174174

175175
test('API tokens are only visible in plaintext until the page is left', async function (assert) {
176-
prepare(this);
176+
await prepare(this);
177177

178178
await visit('/settings/tokens');
179179
await click('[data-test-new-token-button]');
180180
await fillIn('[data-test-name]', 'the new token');
181181
await click('[data-test-scope="publish-update"]');
182182
await click('[data-test-generate]');
183183

184-
let token = this.db.apiToken.findFirst({ where: { name: { equals: 'the new token' } } });
184+
let token = this.db.apiToken.findFirst(q => q.where({ name: 'the new token' }));
185185
assert.dom('[data-test-token]').hasText(token.token);
186186

187187
// leave the API tokens page
@@ -193,7 +193,7 @@ module('Acceptance | api-tokens', function (hooks) {
193193
});
194194

195195
test('navigating away while creating a token does not keep it in the list', async function (assert) {
196-
prepare(this);
196+
await prepare(this);
197197

198198
await visit('/settings/tokens');
199199
assert.dom('[data-test-api-token]').exists({ count: 3 });

tests/acceptance/categories-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ module('Acceptance | categories', function (hooks) {
1414
test('listing categories', async function (assert) {
1515
this.owner.lookup('service:intl').locale = 'en';
1616

17-
this.db.category.create({ category: 'API bindings' });
18-
let algos = this.db.category.create({ category: 'Algorithms' });
19-
this.db.crate.create({ categories: [algos] });
20-
let async = this.db.category.create({ category: 'Asynchronous' });
17+
await this.db.category.create({ category: 'API bindings' });
18+
let algos = await this.db.category.create({ category: 'Algorithms' });
19+
await this.db.crate.create({ categories: [algos] });
20+
let async = await this.db.category.create({ category: 'Asynchronous' });
2121
Array.from({ length: 15 }, () => this.db.crate.create({ categories: [async] }));
22-
this.db.category.create({ category: 'Everything', crates_cnt: 1234 });
22+
await this.db.category.create({ category: 'Everything', crates_cnt: 1234 });
2323

2424
await visit('/categories');
2525

@@ -35,14 +35,14 @@ module('Acceptance | categories', function (hooks) {
3535
test('listing categories (locale: de)', async function (assert) {
3636
this.owner.lookup('service:intl').locale = 'de';
3737

38-
this.db.category.create({ category: 'Everything', crates_cnt: 1234 });
38+
await this.db.category.create({ category: 'Everything', crates_cnt: 1234 });
3939

4040
await visit('/categories');
4141
assert.dom('[data-test-category="everything"] [data-test-crate-count]').hasText('1.234 crates');
4242
});
4343

4444
test('category/:category_id index default sort is recent-downloads', async function (assert) {
45-
this.db.category.create({ category: 'Algorithms' });
45+
await this.db.category.create({ category: 'Algorithms' });
4646

4747
await visit('/categories/algorithms');
4848

@@ -53,8 +53,8 @@ module('Acceptance | categories', function (hooks) {
5353
});
5454

5555
test('listing category slugs', async function (assert) {
56-
this.db.category.create({ category: 'Algorithms', description: 'Crates for algorithms' });
57-
this.db.category.create({ category: 'Asynchronous', description: 'Async crates' });
56+
await this.db.category.create({ category: 'Algorithms', description: 'Crates for algorithms' });
57+
await this.db.category.create({ category: 'Asynchronous', description: 'Async crates' });
5858

5959
await visit('/category_slugs');
6060

tests/acceptance/crate-deletion-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ module('Acceptance | crate deletion', function (hooks) {
99
setupApplicationTest(hooks);
1010

1111
test('happy path', async function (assert) {
12-
let user = this.db.user.create();
13-
this.authenticateAs(user);
12+
let user = await this.db.user.create();
13+
await this.authenticateAs(user);
1414

15-
let crate = this.db.crate.create({ name: 'foo' });
16-
this.db.version.create({ crate });
17-
this.db.crateOwnership.create({ crate, user });
15+
let crate = await this.db.crate.create({ name: 'foo' });
16+
await this.db.version.create({ crate });
17+
await this.db.crateOwnership.create({ crate, user });
1818

1919
await visit('/crates/foo');
2020
assert.strictEqual(currentURL(), '/crates/foo');
@@ -39,7 +39,7 @@ module('Acceptance | crate deletion', function (hooks) {
3939
let message = 'Crate foo has been successfully deleted.';
4040
assert.dom('[data-test-notification-message="success"]').hasText(message);
4141

42-
crate = this.db.crate.findFirst({ where: { name: { equals: 'foo' } } });
43-
assert.strictEqual(crate, null);
42+
crate = this.db.crate.findFirst(q => q.where({ name: 'foo' }));
43+
assert.strictEqual(crate, undefined);
4444
});
4545
});

tests/acceptance/crate-dependencies-test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module('Acceptance | crate dependencies page', function (hooks) {
1616
setupApplicationTest(hooks);
1717

1818
test('shows the lists of dependencies', async function (assert) {
19-
loadFixtures(this.db);
19+
await loadFixtures(this.db);
2020

2121
await visit('/crates/nanomsg/dependencies');
2222
assert.strictEqual(currentURL(), '/crates/nanomsg/0.6.1/dependencies');
@@ -31,8 +31,8 @@ module('Acceptance | crate dependencies page', function (hooks) {
3131
});
3232

3333
test('empty list case', async function (assert) {
34-
let crate = this.db.crate.create({ name: 'nanomsg' });
35-
this.db.version.create({ crate, num: '0.6.1' });
34+
let crate = await this.db.crate.create({ name: 'nanomsg' });
35+
await this.db.version.create({ crate, num: '0.6.1' });
3636

3737
await visit('/crates/nanomsg/dependencies');
3838

@@ -63,8 +63,8 @@ module('Acceptance | crate dependencies page', function (hooks) {
6363
});
6464

6565
test('shows an error page if version is not found', async function (assert) {
66-
let crate = this.db.crate.create({ name: 'foo' });
67-
this.db.version.create({ crate, num: '2.0.0' });
66+
let crate = await this.db.crate.create({ name: 'foo' });
67+
await this.db.version.create({ crate, num: '2.0.0' });
6868

6969
await visit('/crates/foo/1.0.0/dependencies');
7070
assert.strictEqual(currentURL(), '/crates/foo/1.0.0/dependencies');
@@ -75,8 +75,8 @@ module('Acceptance | crate dependencies page', function (hooks) {
7575
});
7676

7777
test('shows error message if loading of dependencies fails', async function (assert) {
78-
let crate = this.db.crate.create({ name: 'foo' });
79-
this.db.version.create({ crate, num: '1.0.0' });
78+
let crate = await this.db.crate.create({ name: 'foo' });
79+
await this.db.version.create({ crate, num: '1.0.0' });
8080

8181
this.worker.use(
8282
http.get('/api/v1/crates/:crate_name/:version_num/dependencies', () => HttpResponse.json({}, { status: 500 })),
@@ -91,16 +91,16 @@ module('Acceptance | crate dependencies page', function (hooks) {
9191
});
9292

9393
test('hides description if loading of dependency details fails', async function (assert) {
94-
let crate = this.db.crate.create({ name: 'nanomsg' });
95-
let version = this.db.version.create({ crate, num: '0.6.1' });
94+
let crate = await this.db.crate.create({ name: 'nanomsg' });
95+
let version = await this.db.version.create({ crate, num: '0.6.1' });
9696

97-
let foo = this.db.crate.create({ name: 'foo', description: 'This is the foo crate' });
98-
this.db.version.create({ crate: foo, num: '1.0.0' });
99-
this.db.dependency.create({ crate: foo, version, req: '^1.0.0', kind: 'normal' });
97+
let foo = await this.db.crate.create({ name: 'foo', description: 'This is the foo crate' });
98+
await this.db.version.create({ crate: foo, num: '1.0.0' });
99+
await this.db.dependency.create({ crate: foo, version, req: '^1.0.0', kind: 'normal' });
100100

101-
let bar = this.db.crate.create({ name: 'bar', description: 'This is the bar crate' });
102-
this.db.version.create({ crate: bar, num: '2.3.4' });
103-
this.db.dependency.create({ crate: bar, version, req: '^2.0.0', kind: 'normal' });
101+
let bar = await this.db.crate.create({ name: 'bar', description: 'This is the bar crate' });
102+
await this.db.version.create({ crate: bar, num: '2.3.4' });
103+
await this.db.dependency.create({ crate: bar, version, req: '^2.0.0', kind: 'normal' });
104104

105105
this.worker.use(http.get('/api/v1/crates', () => HttpResponse.json({}, { status: 500 })));
106106

tests/acceptance/crate-following-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ import { setupApplicationTest } from 'crates-io/tests/helpers';
1010
module('Acceptance | Crate following', function (hooks) {
1111
setupApplicationTest(hooks);
1212

13-
function prepare(context, { loggedIn = true, following = false } = {}) {
13+
async function prepare(context, { loggedIn = true, following = false } = {}) {
1414
let { db } = context;
1515

16-
let crate = db.crate.create({ name: 'nanomsg' });
17-
db.version.create({ crate, num: '0.6.0' });
16+
let crate = await db.crate.create({ name: 'nanomsg' });
17+
await db.version.create({ crate, num: '0.6.0' });
1818

1919
if (loggedIn) {
2020
let followedCrates = following ? [crate] : [];
21-
let user = db.user.create({ followedCrates });
22-
context.authenticateAs(user);
21+
let user = await db.user.create({ followedCrates });
22+
await context.authenticateAs(user);
2323
}
2424
}
2525

2626
test("unauthenticated users don't see the follow button", async function (assert) {
27-
prepare(this, { loggedIn: false });
27+
await prepare(this, { loggedIn: false });
2828

2929
await visit('/crates/nanomsg');
3030
assert.dom('[data-test-follow-button]').doesNotExist();
3131
});
3232

3333
test('authenticated users see a loading spinner and can follow/unfollow crates', async function (assert) {
34-
prepare(this);
34+
await prepare(this);
3535

3636
let followingDeferred = defer();
3737
this.worker.use(http.get('/api/v1/crates/:crate_id/following', () => followingDeferred.promise));
@@ -74,7 +74,7 @@ module('Acceptance | Crate following', function (hooks) {
7474
});
7575

7676
test('error handling when loading following state fails', async function (assert) {
77-
prepare(this);
77+
await prepare(this);
7878

7979
this.worker.use(http.get('/api/v1/crates/:crate_id/following', () => HttpResponse.json({}, { status: 500 })));
8080

@@ -88,7 +88,7 @@ module('Acceptance | Crate following', function (hooks) {
8888
});
8989

9090
test('error handling when follow fails', async function (assert) {
91-
prepare(this);
91+
await prepare(this);
9292

9393
this.worker.use(http.put('/api/v1/crates/:crate_id/follow', () => HttpResponse.json({}, { status: 500 })));
9494

@@ -100,7 +100,7 @@ module('Acceptance | Crate following', function (hooks) {
100100
});
101101

102102
test('error handling when unfollow fails', async function (assert) {
103-
prepare(this, { following: true });
103+
await prepare(this, { following: true });
104104

105105
this.worker.use(http.delete('/api/v1/crates/:crate_id/follow', () => HttpResponse.json({}, { status: 500 })));
106106

tests/acceptance/crate-navtabs-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module('Acceptance | crate navigation tabs', function (hooks) {
1313
setupApplicationTest(hooks);
1414

1515
test('basic navigation between tabs works as expected', async function (assert) {
16-
let crate = this.db.crate.create({ name: 'nanomsg' });
17-
this.db.version.create({ crate, num: '0.6.1' });
16+
let crate = await this.db.crate.create({ name: 'nanomsg' });
17+
await this.db.version.create({ crate, num: '0.6.1' });
1818

1919
await visit('/crates/nanomsg');
2020
assert.strictEqual(currentURL(), '/crates/nanomsg');

0 commit comments

Comments
 (0)