Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Fix endpoint template
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah committed Oct 6, 2016
1 parent 71d30d5 commit 9dadd6d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
9 changes: 4 additions & 5 deletions generators/endpoint/templates/_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
]
});
25 changes: 18 additions & 7 deletions test/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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/);
});

});

});
Expand Down

0 comments on commit 9dadd6d

Please sign in to comment.