Skip to content

Commit 9c9adda

Browse files
committed
tests/routes/crate/version/docs-link: Migrate from mirage to @crates-io/msw
1 parent 70ad207 commit 9c9adda

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

tests/routes/crate/version/docs-link-test.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,82 @@
11
import { visit } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

4+
import { http, HttpResponse } from 'msw';
5+
46
import { setupApplicationTest } from 'crates-io/tests/helpers';
57

68
module('Route | crate.version | docs link', function (hooks) {
7-
setupApplicationTest(hooks);
9+
setupApplicationTest(hooks, { msw: true });
810

911
test('shows regular documentation link', async function (assert) {
10-
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://foo.io/docs' });
11-
this.server.create('version', { crate, num: '1.0.0' });
12+
let crate = this.db.crate.create({ name: 'foo', documentation: 'https://foo.io/docs' });
13+
this.db.version.create({ crate, num: '1.0.0' });
1214

1315
await visit('/crates/foo');
1416
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://foo.io/docs');
1517
});
1618

1719
test('show no docs link if `documentation` is unspecified and there are no related docs.rs builds', async function (assert) {
18-
let crate = this.server.create('crate', { name: 'foo' });
19-
this.server.create('version', { crate, num: '1.0.0' });
20+
let crate = this.db.crate.create({ name: 'foo' });
21+
this.db.version.create({ crate, num: '1.0.0' });
2022

21-
this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'not found', 404);
23+
let error = HttpResponse.text('not found', { status: 404 });
24+
this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error));
2225

2326
await visit('/crates/foo');
2427
assert.dom('[data-test-docs-link] a').doesNotExist();
2528
});
2629

2730
test('show docs link if `documentation` is unspecified and there are related docs.rs builds', async function (assert) {
28-
let crate = this.server.create('crate', { name: 'foo' });
29-
this.server.create('version', { crate, num: '1.0.0' });
31+
let crate = this.db.crate.create({ name: 'foo' });
32+
this.db.version.create({ crate, num: '1.0.0' });
3033

31-
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {
32-
doc_status: true,
33-
version: '1.0.0',
34-
});
34+
let response = HttpResponse.json({ doc_status: true, version: '1.0.0' });
35+
this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response));
3536

3637
await visit('/crates/foo');
3738
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/1.0.0');
3839
});
3940

4041
test('show original docs link if `documentation` points to docs.rs and there are no related docs.rs builds', async function (assert) {
41-
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
42-
this.server.create('version', { crate, num: '1.0.0' });
42+
let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
43+
this.db.version.create({ crate, num: '1.0.0' });
4344

44-
this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'not found', 404);
45+
let error = HttpResponse.text('not found', { status: 404 });
46+
this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error));
4547

4648
await visit('/crates/foo');
4749
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');
4850
});
4951

5052
test('show updated docs link if `documentation` points to docs.rs and there are related docs.rs builds', async function (assert) {
51-
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
52-
this.server.create('version', { crate, num: '1.0.0' });
53+
let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
54+
this.db.version.create({ crate, num: '1.0.0' });
5355

54-
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {
55-
doc_status: true,
56-
version: '1.0.0',
57-
});
56+
let response = HttpResponse.json({ doc_status: true, version: '1.0.0' });
57+
this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response));
5858

5959
await visit('/crates/foo');
6060
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/1.0.0');
6161
});
6262

6363
test('ajax errors are ignored', async function (assert) {
64-
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
65-
this.server.create('version', { crate, num: '1.0.0' });
64+
let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
65+
this.db.version.create({ crate, num: '1.0.0' });
6666

67-
this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'error', 500);
67+
let error = HttpResponse.text('error', { status: 500 });
68+
this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error));
6869

6970
await visit('/crates/foo');
7071
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');
7172
});
7273

7374
test('empty docs.rs responses are ignored', async function (assert) {
74-
let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
75-
this.server.create('version', { crate, num: '0.6.2' });
75+
let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' });
76+
this.db.version.create({ crate, num: '0.6.2' });
7677

77-
this.server.get('https://docs.rs/crate/:crate/:version/status.json', {});
78+
let response = HttpResponse.json({});
79+
this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response));
7880

7981
await visit('/crates/foo');
8082
assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2');

0 commit comments

Comments
 (0)