-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathnock-proxy-test.js
More file actions
95 lines (78 loc) · 2.48 KB
/
nock-proxy-test.js
File metadata and controls
95 lines (78 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { module, test } from 'qunit';
import { setup, visit, nock } from 'ember-cli-fastboot-testing/test-support';
module('Fastboot | nock proxy', function(hooks) {
setup(hooks);
test('it will not change an endpoint that already exists', async function(assert) {
await visit('/examples/network/other/echo?message=hello%20world');
assert.dom('[data-test-id="echo"]').hasText("hello world");
});
test('it can mock an array of models', async function(assert) {
await nock('http://localhost:7357')
.intercept('/api/notes', 'GET')
.reply(200, {
data: [
{
type: 'note',
id: '1',
attributes: {
title: 'test note'
}
},
{
type: 'note',
id: '2',
attributes: {
title: 'test 2'
}
}
]
});
await visit('/examples/network/notes');
assert.dom('[data-test-id="title-1"]').hasText("test note")
assert.dom('[data-test-id="title-2"]').hasText("test 2")
});
test('it can mock a single model', async function(assert) {
await nock('http://localhost:7357')
.intercept('/api/notes/1', 'GET')
.reply(200, {
data: {
type: "notes",
id: "1",
attributes: {
title: 'test note'
}
}
});
await visit('/examples/network/notes/1');
assert.dom('[data-test-id="title"]').hasText("test note");
});
test('it can mock 404s', async function(assert) {
await nock('http://localhost:7357')
.intercept('/api/notes/1', 'GET')
.reply(404, {
errors: [
{ title: "Not found" }
]
});
await visit('/examples/network/notes/1');
assert.dom().includesText('Ember Data Request GET /api/notes/1 returned a 404');
});
test('it can mock a get request', async function(assert) {
await nock('http://localhost:7357')
.intercept('/api/notes', 'GET')
.reply(200, [
{ id: 1, title: 'get note' },
]);
await visit('/examples/network/other/get-request');
assert.dom('[data-test-id="title-1"]').hasText("get note")
});
test('it can mock a post request', async function(assert) {
await nock('http://localhost:7357')
.intercept('/api/notes', 'POST')
.reply(200, [
{ id: 1, title: 'post note' },
]);
await visit('/examples/network/other/post-request');
assert.dom('[data-test-id="title-1"]').hasText("post note")
});
});