|
1 | | -import { module, test } from 'qunit'; |
2 | | -import { setup, visit, mockServer } from 'ember-cli-fastboot-testing/test-support'; |
3 | | - |
4 | | -module('Fastboot | network mocking', function(hooks) { |
| 1 | +import { module, test } from "qunit"; |
| 2 | +import { |
| 3 | + setup, |
| 4 | + visit, |
| 5 | + mockServer |
| 6 | +} from "ember-cli-fastboot-testing/test-support"; |
| 7 | + |
| 8 | +module("Fastboot | network mocking", function(hooks) { |
5 | 9 | setup(hooks); |
6 | 10 |
|
7 | | - test('it will not change an endpoint that already exists', async function(assert) { |
8 | | - await visit('/examples/network/other/echo?message=hello%20world'); |
| 11 | + test("it will not change an endpoint that already exists", async function(assert) { |
| 12 | + await visit("/examples/network/other/echo?message=hello%20world"); |
9 | 13 | assert.dom('[data-test-id="echo"]').hasText("hello world"); |
10 | 14 | }); |
11 | 15 |
|
12 | | - test('it can mock an array of models', async function(assert) { |
13 | | - await mockServer.get('/api/notes', { |
| 16 | + test("it can mock an array of models", async function(assert) { |
| 17 | + await mockServer.get("/api/notes", { |
14 | 18 | data: [ |
15 | 19 | { |
16 | | - type: 'note', |
17 | | - id: '1', |
| 20 | + type: "note", |
| 21 | + id: "1", |
18 | 22 | attributes: { |
19 | | - title: 'test note' |
| 23 | + title: "test note" |
20 | 24 | } |
21 | 25 | }, |
22 | 26 | { |
23 | | - type: 'note', |
24 | | - id: '2', |
| 27 | + type: "note", |
| 28 | + id: "2", |
25 | 29 | attributes: { |
26 | | - title: 'test 2' |
| 30 | + title: "test 2" |
27 | 31 | } |
28 | 32 | } |
29 | 33 | ] |
30 | 34 | }); |
31 | 35 |
|
32 | | - await visit('/examples/network/notes'); |
| 36 | + await visit("/examples/network/notes"); |
33 | 37 |
|
34 | | - assert.dom('[data-test-id="title-1"]').hasText("test note") |
35 | | - assert.dom('[data-test-id="title-2"]').hasText("test 2") |
| 38 | + assert.dom('[data-test-id="title-1"]').hasText("test note"); |
| 39 | + assert.dom('[data-test-id="title-2"]').hasText("test 2"); |
36 | 40 | }); |
37 | 41 |
|
38 | | - test('it can mock a single model', async function(assert) { |
39 | | - await mockServer.get('/api/notes/1', { |
| 42 | + test("it can mock a single model", async function(assert) { |
| 43 | + await mockServer.get("/api/notes/1", { |
40 | 44 | data: { |
41 | 45 | type: "note", |
42 | 46 | id: "1", |
43 | 47 | attributes: { |
44 | | - title: 'test note' |
| 48 | + title: "test note" |
45 | 49 | } |
46 | 50 | } |
47 | 51 | }); |
48 | 52 |
|
49 | | - await visit('/examples/network/notes/1'); |
| 53 | + await visit("/examples/network/notes/1"); |
50 | 54 |
|
51 | 55 | assert.dom('[data-test-id="title"]').hasText("test note"); |
52 | 56 | }); |
53 | 57 |
|
54 | | - test('it can mock 404s', async function(assert) { |
| 58 | + test("it can mock 404s", async function(assert) { |
55 | 59 | await mockServer.get( |
56 | | - '/api/notes/1', |
| 60 | + "/api/notes/1", |
57 | 61 | { |
58 | | - errors: [ |
59 | | - { title: "Not found" } |
60 | | - ] |
| 62 | + errors: [{ title: "Not found" }] |
61 | 63 | }, |
62 | 64 | 404 |
63 | 65 | ); |
64 | 66 |
|
65 | | - await visit('/examples/network/notes/1'); |
| 67 | + await visit("/examples/network/notes/1"); |
66 | 68 |
|
67 | | - assert.dom().includesText('Ember Data Request GET /api/notes/1 returned a 404'); |
| 69 | + assert |
| 70 | + .dom() |
| 71 | + .includesText("Ember Data Request GET /api/notes/1 returned a 404"); |
68 | 72 | }); |
69 | 73 |
|
70 | | - test('it can mock a get request', async function(assert) { |
71 | | - await mockServer.get('/api/notes', [ |
72 | | - { id: 1, title: 'get note'}, |
73 | | - ]); |
| 74 | + test("it can mock a get request", async function(assert) { |
| 75 | + await mockServer.get("/api/notes", [{ id: 1, title: "get note" }]); |
74 | 76 |
|
75 | | - await visit('/examples/network/other/get-request'); |
| 77 | + await visit("/examples/network/other/get-request"); |
76 | 78 |
|
77 | | - assert.dom('[data-test-id="title-1"]').hasText("get note") |
| 79 | + assert.dom('[data-test-id="title-1"]').hasText("get note"); |
78 | 80 | }); |
79 | 81 |
|
80 | | - test('it can mock a post request', async function(assert) { |
81 | | - await mockServer.post('/api/notes', [ |
82 | | - { id: 1, title: 'post note'}, |
83 | | - ]); |
| 82 | + test("it can mock a post request", async function(assert) { |
| 83 | + await mockServer.post("/api/notes", [{ id: 1, title: "post note" }]); |
84 | 84 |
|
85 | | - await visit('/examples/network/other/post-request'); |
| 85 | + await visit("/examples/network/other/post-request"); |
86 | 86 |
|
87 | | - assert.dom('[data-test-id="title-1"]').hasText("post note") |
| 87 | + assert.dom('[data-test-id="title-1"]').hasText("post note"); |
88 | 88 | }); |
89 | 89 |
|
90 | | - test('it can mock a large response', async function(assert) { |
91 | | - let title = 'a'.repeat(1024 * 1024 * 5); // 5 MB |
| 90 | + test("it can mock a large response", async function(assert) { |
| 91 | + let title = "a".repeat(1024 * 1024 * 5); // 5 MB |
92 | 92 |
|
93 | | - await mockServer.get('/api/notes', [ |
94 | | - { id: 1, title }, |
95 | | - ]); |
| 93 | + await mockServer.get("/api/notes", [{ id: 1, title }]); |
96 | 94 |
|
97 | | - await visit('/examples/network/other/get-request'); |
| 95 | + await visit("/examples/network/other/get-request"); |
98 | 96 |
|
99 | 97 | assert.dom('[data-test-id="title-1"]').exists(); |
100 | 98 | }); |
|
0 commit comments