Skip to content

Commit 10b72c9

Browse files
authored
Merge pull request #46 from embermap/move-body-parser
Add an echo endpoint for testing
2 parents f2d1d5b + 59ab493 commit 10b72c9

6 files changed

Lines changed: 40 additions & 2 deletions

File tree

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ module.exports = {
4242

4343
_fastbootRenderingMiddleware(app) {
4444

45-
app.use(bodyParser.json());
46-
app.post('/__mock-request', (req, res) => {
45+
app.post('/__mock-request', bodyParser.json(), (req, res) => {
4746
let mock = nock(req.headers.origin)
4847
.persist()
4948
.intercept(req.body.path, req.body.method)
@@ -118,6 +117,13 @@ module.exports = {
118117
res.json({ err: jsonError });
119118
});
120119
});
120+
121+
if (this.app.name === "dummy") {
122+
// our dummy app has an echo endpoint!
123+
app.post('/fastboot-testing/echo', bodyParser.text(), (req, res) => {
124+
res.send(req.body);
125+
});
126+
}
121127
},
122128

123129
postBuild(result) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Controller from '@ember/controller';
2+
3+
export default Controller.extend({
4+
queryParams: ['message']
5+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Route from '@ember/routing/route';
2+
import fetch from 'fetch';
3+
4+
export default Route.extend({
5+
6+
// this endpoint is defined in index.js, it's used to represent
7+
// a url that ember-cli might already have in it's express router.
8+
9+
// we should be able to post a body to this echo endpoint and
10+
// get a reply back.
11+
model(params) {
12+
return fetch('/fastboot-testing/echo', {
13+
method: 'POST',
14+
body: params.message
15+
}).then(response => {
16+
return response.text();
17+
});
18+
}
19+
20+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div data-test-id="echo">{{model}}</div>

tests/dummy/app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Router.map(function() {
3636
this.route('other', function() {
3737
this.route('get-request');
3838
this.route('post-request');
39+
this.route('echo');
3940
});
4041
});
4142

tests/fastboot/network-mocking-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { setup, visit, mockServer } from 'ember-cli-fastboot-testing/test-suppor
44
module('Fastboot | network mocking', function(hooks) {
55
setup(hooks);
66

7+
test('it will not change an endpoint that already exists', async function(assert) {
8+
await visit('/examples/network/other/echo?message=hello%20world');
9+
assert.dom('[data-test-id="echo"]').hasText("hello world");
10+
});
11+
712
test('it can mock an array of models', async function(assert) {
813
await mockServer.get('/api/posts', {
914
data: [

0 commit comments

Comments
 (0)