From 9dadd6d6762333bd6cc4ca008e7f3f3dc3bddc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Ku=CC=88hnel?= Date: Fri, 7 Oct 2016 01:09:59 +0200 Subject: [PATCH] Fix endpoint template --- generators/endpoint/templates/_endpoint.js | 9 ++++---- test/endpoint.js | 25 ++++++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/generators/endpoint/templates/_endpoint.js b/generators/endpoint/templates/_endpoint.js index d3d531b..96b8a2c 100644 --- a/generators/endpoint/templates/_endpoint.js +++ b/generators/endpoint/templates/_endpoint.js @@ -5,15 +5,14 @@ const SetupEndpoint = require('./setup/setup.js'); module.exports = SetupEndpoint({ name: '<%= endpoint.name %>', urls: [<% endpoint.urls.forEach(function(url, index){ %> - { - params: '<%= url.params %>', + {<% if (url.params){ %> + params: '<%= url.params %>',<% } %> requests: [{ method: '<%= url.requests[0].method %>',<% if (url.requests[0].responseType === 'json'){ %> response: '/json-templates/<%= url.requests[0].response %>'<% } else if (url.requests[0].responseType === 'object'){ %> - response: <%- url.requests[0].response %><% } %><% if (url.requests[0].statusCode !== '200'){ %>, + response: <%- url.requests[0].response %><% } %><% if (url.requests[0].statusCode !== '200' && url.requests[0].responseType !== 'error'){ %>,<% } %><% if (url.requests[0].statusCode !== '200'){ %> statusCode: <%- url.requests[0].statusCode %><% } %> }] }<% if (index + 1 !== endpoint.urls.length) { %>,<% } %><% }) %> - ]/*, - statusCode: 401*/ + ] }); diff --git a/test/endpoint.js b/test/endpoint.js index 8ae9053..18dce4a 100644 --- a/test/endpoint.js +++ b/test/endpoint.js @@ -6,8 +6,8 @@ var helper = require('../generators/endpoint/promptingHelpers'); var chalk = require('chalk'); describe('generator-http-fake-backend → endpoint', function () { - before(function (done) { - helpers.run(path.join(__dirname, '../generators/endpoint')) + before(function () { + return helpers.run(path.join(__dirname, '../generators/endpoint')) .withOptions({someOption: true}) .withPrompts({ endpointName: 'endpoint', @@ -17,7 +17,7 @@ describe('generator-http-fake-backend → endpoint', function () { response: '{ status: \'ok\' }', anotherUrl: false }) - .on('end', done); + .toPromise(); }); it('should create endpoint.js', function () { @@ -39,24 +39,27 @@ describe('generator-http-fake-backend → endpoint', function () { it('should contain the prompted response', function () { assert.fileContent('server/api/endpoint.js', /response: { status: 'ok' }/); }); + it('should not contain a statuscode key', function () { + assert.noFileContent('server/api/endpoint.js', /statusCode/); + }); }); }); describe('generator-http-fake-backend → endpoint → JSON file', function () { - before(function (done) { - helpers.run(path.join(__dirname, '../generators/endpoint')) + before(function () { + return helpers.run(path.join(__dirname, '../generators/endpoint')) .withOptions({someOption: true}) .withPrompts({ endpointName: 'endpoint', - params: '/bar', method: 'GET', responseType: 'json', response: 'foo.json', + statusCode: 204, anotherUrl: false }) - .on('end', done); + .toPromise(); }); it('should create foo.json', function () { @@ -77,6 +80,14 @@ describe('generator-http-fake-backend → endpoint → JSON file', function () { assert.fileContent('server/api/endpoint.js', /response: '\/json-templates\/foo.json'/); }); + it('should contain the correct statuscode', function () { + assert.fileContent('server/api/endpoint.js', /statusCode: 204/); + }); + + it('should not contain the params key', function () { + assert.noFileContent('server/api/endpoint.js', /params/); + }); + }); });