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

Commit 9dadd6d

Browse files
committed
Fix endpoint template
1 parent 71d30d5 commit 9dadd6d

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

generators/endpoint/templates/_endpoint.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ const SetupEndpoint = require('./setup/setup.js');
55
module.exports = SetupEndpoint({
66
name: '<%= endpoint.name %>',
77
urls: [<% endpoint.urls.forEach(function(url, index){ %>
8-
{
9-
params: '<%= url.params %>',
8+
{<% if (url.params){ %>
9+
params: '<%= url.params %>',<% } %>
1010
requests: [{
1111
method: '<%= url.requests[0].method %>',<% if (url.requests[0].responseType === 'json'){ %>
1212
response: '/json-templates/<%= url.requests[0].response %>'<% } else if (url.requests[0].responseType === 'object'){ %>
13-
response: <%- url.requests[0].response %><% } %><% if (url.requests[0].statusCode !== '200'){ %>,
13+
response: <%- url.requests[0].response %><% } %><% if (url.requests[0].statusCode !== '200' && url.requests[0].responseType !== 'error'){ %>,<% } %><% if (url.requests[0].statusCode !== '200'){ %>
1414
statusCode: <%- url.requests[0].statusCode %><% } %>
1515
}]
1616
}<% if (index + 1 !== endpoint.urls.length) { %>,<% } %><% }) %>
17-
]/*,
18-
statusCode: 401*/
17+
]
1918
});

test/endpoint.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var helper = require('../generators/endpoint/promptingHelpers');
66
var chalk = require('chalk');
77

88
describe('generator-http-fake-backend → endpoint', function () {
9-
before(function (done) {
10-
helpers.run(path.join(__dirname, '../generators/endpoint'))
9+
before(function () {
10+
return helpers.run(path.join(__dirname, '../generators/endpoint'))
1111
.withOptions({someOption: true})
1212
.withPrompts({
1313
endpointName: 'endpoint',
@@ -17,7 +17,7 @@ describe('generator-http-fake-backend → endpoint', function () {
1717
response: '{ status: \'ok\' }',
1818
anotherUrl: false
1919
})
20-
.on('end', done);
20+
.toPromise();
2121
});
2222

2323
it('should create endpoint.js', function () {
@@ -39,24 +39,27 @@ describe('generator-http-fake-backend → endpoint', function () {
3939
it('should contain the prompted response', function () {
4040
assert.fileContent('server/api/endpoint.js', /response: { status: 'ok' }/);
4141
});
42+
it('should not contain a statuscode key', function () {
43+
assert.noFileContent('server/api/endpoint.js', /statusCode/);
44+
});
4245

4346
});
4447

4548
});
4649

4750
describe('generator-http-fake-backend → endpoint → JSON file', function () {
48-
before(function (done) {
49-
helpers.run(path.join(__dirname, '../generators/endpoint'))
51+
before(function () {
52+
return helpers.run(path.join(__dirname, '../generators/endpoint'))
5053
.withOptions({someOption: true})
5154
.withPrompts({
5255
endpointName: 'endpoint',
53-
params: '/bar',
5456
method: 'GET',
5557
responseType: 'json',
5658
response: 'foo.json',
59+
statusCode: 204,
5760
anotherUrl: false
5861
})
59-
.on('end', done);
62+
.toPromise();
6063
});
6164

6265
it('should create foo.json', function () {
@@ -77,6 +80,14 @@ describe('generator-http-fake-backend → endpoint → JSON file', function () {
7780
assert.fileContent('server/api/endpoint.js', /response: '\/json-templates\/foo.json'/);
7881
});
7982

83+
it('should contain the correct statuscode', function () {
84+
assert.fileContent('server/api/endpoint.js', /statusCode: 204/);
85+
});
86+
87+
it('should not contain the params key', function () {
88+
assert.noFileContent('server/api/endpoint.js', /params/);
89+
});
90+
8091
});
8192

8293
});

0 commit comments

Comments
 (0)