diff --git a/index.js b/index.js index e85a93cc..128bd29b 100644 --- a/index.js +++ b/index.js @@ -42,8 +42,7 @@ module.exports = { _fastbootRenderingMiddleware(app) { - app.use(bodyParser.json()); - app.post('/__mock-request', (req, res) => { + app.post('/__mock-request', bodyParser.json(), (req, res) => { let mock = nock(req.headers.origin) .persist() .intercept(req.body.path, req.body.method) @@ -118,6 +117,13 @@ module.exports = { res.json({ err: jsonError }); }); }); + + if (this.app.name === "dummy") { + // our dummy app has an echo endpoint! + app.post('/fastboot-testing/echo', bodyParser.text(), (req, res) => { + res.send(req.body); + }); + } }, postBuild(result) { diff --git a/tests/dummy/app/pods/examples/network/other/echo/controller.js b/tests/dummy/app/pods/examples/network/other/echo/controller.js new file mode 100644 index 00000000..72c4bc3f --- /dev/null +++ b/tests/dummy/app/pods/examples/network/other/echo/controller.js @@ -0,0 +1,5 @@ +import Controller from '@ember/controller'; + +export default Controller.extend({ + queryParams: ['message'] +}); diff --git a/tests/dummy/app/pods/examples/network/other/echo/route.js b/tests/dummy/app/pods/examples/network/other/echo/route.js new file mode 100644 index 00000000..c59fac70 --- /dev/null +++ b/tests/dummy/app/pods/examples/network/other/echo/route.js @@ -0,0 +1,20 @@ +import Route from '@ember/routing/route'; +import fetch from 'fetch'; + +export default Route.extend({ + + // this endpoint is defined in index.js, it's used to represent + // a url that ember-cli might already have in it's express router. + + // we should be able to post a body to this echo endpoint and + // get a reply back. + model(params) { + return fetch('/fastboot-testing/echo', { + method: 'POST', + body: params.message + }).then(response => { + return response.text(); + }); + } + +}); diff --git a/tests/dummy/app/pods/examples/network/other/echo/template.hbs b/tests/dummy/app/pods/examples/network/other/echo/template.hbs new file mode 100644 index 00000000..fb6e7c6a --- /dev/null +++ b/tests/dummy/app/pods/examples/network/other/echo/template.hbs @@ -0,0 +1 @@ +
{{model}}
diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 09ecb68c..40077fb8 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -36,6 +36,7 @@ Router.map(function() { this.route('other', function() { this.route('get-request'); this.route('post-request'); + this.route('echo'); }); }); diff --git a/tests/fastboot/network-mocking-test.js b/tests/fastboot/network-mocking-test.js index 00ef8b87..22a70661 100644 --- a/tests/fastboot/network-mocking-test.js +++ b/tests/fastboot/network-mocking-test.js @@ -4,6 +4,11 @@ import { setup, visit, mockServer } from 'ember-cli-fastboot-testing/test-suppor module('Fastboot | network mocking', 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 mockServer.get('/api/posts', { data: [