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

Commit 05e234d

Browse files
authored
feat: Update fake backend to 4.0.2
> # http-fake-backend 4.0.2 > > ## Bug Fixes > > * update minimum node version in package.json > >*Change `engines.node` to `>=6.0.0` to reflect the minimum node version which is needed since http-fake-backend 4.0.0.* > > # http-fake-backend 4.0.1 > > ## Bug Fixes > > * encoding of binary files send via endpoints > > # http-fake-backend 4.0.0 > > ## Bug Fixes > > * **dependencies:** Apply changes of boom update > * **dependencies:** Update dependencies > > ## Code Refactoring > > * Refactor existing codebase > > ## Documentation > > * Update required minimum Node version in readme > > ## Features > > * Add support for other response content-types, closes [#7](micromata/http-fake-backend#7) > * Add support for sending files as response, closes [#11](micromata/http-fake-backend#11) > > ## BREAKING CHANGES > > * The transitive dependency punycode@2.1.0 needs Node version ">=6". > * The setup.js is divided to multiple files. Therefore you need to change the import of the setup in your endpoint files like the following: > > ```javascript > // before > const SetupEndpoint = require('./setup/setup.js'); > > // now > const SetupEndpoint = require('./setup/index.js'); > > // or: > const SetupEndpoint = require('./setup/'); > ```
1 parent 4df3ba1 commit 05e234d

File tree

25 files changed

+2334
-1080
lines changed

25 files changed

+2334
-1080
lines changed

__tests__/app.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ describe('generator-http-fake-backend → server', () => {
2020
assert.file([
2121
'.editorconfig',
2222
'.env',
23-
'.eslintrc',
2423
'.gitattributes',
2524
'.gitignore'
2625
]);
@@ -54,15 +53,18 @@ describe('generator-http-fake-backend → server', () => {
5453
]);
5554
});
5655

57-
it('should create json-templates directory', () => {
56+
it('should create response-files directory', () => {
5857
assert.file([
59-
'json-templates/.gitkeep'
58+
'response-files/.gitkeep'
6059
]);
6160
});
6261

6362
it('should create server files', () => {
6463
assert.file([
65-
'server/api/setup/setup.js',
64+
'server/api/setup/lib/getContentDisposition.js',
65+
'server/api/setup/index.js',
66+
'server/api/setup/supportedMethod.js',
67+
'server/api/setup/unsupportedMethods.js',
6668
'server/web/index.js',
6769
'server/web/public/assets/css/styles.css',
6870
'server/web/public.js',
@@ -83,7 +85,11 @@ describe('generator-http-fake-backend → server', () => {
8385
'test/manifest.js',
8486
'test/server/api/endpoint.js',
8587
'test/server/api/fakeStatusCode.js',
88+
'test/server/api/fileTypes.js',
89+
'test/server/api/fixtures/example.pdf',
90+
'test/server/api/fixtures/response.html',
8691
'test/server/api/fixtures/response.json',
92+
'test/server/api/fixtures/response.txt',
8793
'test/server/web/index.js'
8894
]);
8995
});

__tests__/endpoint.js

Lines changed: 156 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('generator-http-fake-backend → endpoint', () => {
1313
endpointName: 'endpoint',
1414
params: '/bar',
1515
method: 'GET',
16-
responseType: 'object',
16+
responseType: 'objectLiteral',
1717
response: '{ status: \'ok\' }',
1818
anotherUrl: false
1919
})
@@ -52,7 +52,8 @@ describe('generator-http-fake-backend → endpoint → JSON file', () => {
5252
.withPrompts({
5353
endpointName: 'endpoint',
5454
method: 'GET',
55-
responseType: 'json',
55+
responseType: 'fileContent',
56+
contentType: 'json',
5657
response: 'foo.json',
5758
statusCode: 204,
5859
anotherUrl: false
@@ -62,7 +63,7 @@ describe('generator-http-fake-backend → endpoint → JSON file', () => {
6263

6364
it('should create foo.json', () => {
6465
assert.file([
65-
'json-templates/foo.json'
66+
'response-files/foo.json'
6667
]);
6768
});
6869

@@ -72,9 +73,23 @@ describe('generator-http-fake-backend → endpoint → JSON file', () => {
7273
]);
7374
});
7475

76+
describe('foo.json', () => {
77+
it('should contain the content off the template', () => {
78+
assert.fileContent('response-files/foo.json', /{ "success": true }/);
79+
});
80+
});
81+
7582
describe('endpoint.js', () => {
7683
it('should contain the prompted response', () => {
77-
assert.fileContent('server/api/endpoint.js', /response: '\/json-templates\/foo.json'/);
84+
assert.fileContent('server/api/endpoint.js', /response: '\/response-files\/foo.json'/);
85+
});
86+
87+
it('should not have a mimeType key ', () => {
88+
assert.noFileContent('server/api/endpoint.js', /mimeType:/);
89+
});
90+
91+
it('should not have a sendFile key ', () => {
92+
assert.noFileContent('server/api/endpoint.js', /sendFile:/);
7893
});
7994

8095
it('should contain the correct statuscode', () => {
@@ -87,11 +102,146 @@ describe('generator-http-fake-backend → endpoint → JSON file', () => {
87102
});
88103
});
89104

105+
describe('generator-http-fake-backend → endpoint → Text file', () => {
106+
beforeAll(() => {
107+
return helpers.run(path.join(__dirname, '../generators/endpoint'))
108+
.withOptions({someOption: true})
109+
.withPrompts({
110+
endpointName: 'endpoint',
111+
method: 'GET',
112+
responseType: 'fileContent',
113+
contentType: 'txt',
114+
response: 'foo.txt',
115+
statusCode: 204,
116+
anotherUrl: false
117+
})
118+
.toPromise();
119+
});
120+
121+
it('should create foo.txt', () => {
122+
assert.file([
123+
'response-files/foo.txt'
124+
]);
125+
});
126+
127+
it('should create endpoint.js', () => {
128+
assert.file([
129+
'server/api/endpoint.js'
130+
]);
131+
});
132+
133+
describe('foo.txt', () => {
134+
it('should contain the content off the template', () => {
135+
assert.fileContent('response-files/foo.txt', /Success/);
136+
});
137+
});
138+
139+
describe('endpoint.js', () => {
140+
it('should contain the prompted response', () => {
141+
assert.fileContent('server/api/endpoint.js', /response: '\/response-files\/foo.txt'/);
142+
});
143+
144+
it('should have the correct mimeType', () => {
145+
assert.fileContent('server/api/endpoint.js', /mimeType: 'text\/plain'/);
146+
});
147+
148+
it('should not have a sendFile key ', () => {
149+
assert.noFileContent('server/api/endpoint.js', /sendFile:/);
150+
});
151+
});
152+
});
153+
154+
describe('generator-http-fake-backend → endpoint → HTML file', () => {
155+
beforeAll(() => {
156+
return helpers.run(path.join(__dirname, '../generators/endpoint'))
157+
.withOptions({someOption: true})
158+
.withPrompts({
159+
endpointName: 'endpoint',
160+
method: 'GET',
161+
responseType: 'fileContent',
162+
contentType: 'html',
163+
response: 'foo.html',
164+
statusCode: 204,
165+
anotherUrl: false
166+
})
167+
.toPromise();
168+
});
169+
170+
it('should create foo.html', () => {
171+
assert.file([
172+
'response-files/foo.html'
173+
]);
174+
});
175+
176+
it('should create endpoint.js', () => {
177+
assert.file([
178+
'server/api/endpoint.js'
179+
]);
180+
});
181+
182+
describe('foo.html', () => {
183+
it('should contain the content off the template', () => {
184+
assert.fileContent('response-files/foo.html', /<a href="https:\/\/github\.com">GitHub<\/a>/);
185+
});
186+
});
187+
188+
describe('endpoint.js', () => {
189+
it('should contain the prompted response', () => {
190+
assert.fileContent('server/api/endpoint.js', /response: '\/response-files\/foo.html'/);
191+
});
192+
193+
it('should have the correct mimeType', () => {
194+
assert.fileContent('server/api/endpoint.js', /mimeType: 'text\/html'/);
195+
});
196+
197+
it('should not have a sendFile key ', () => {
198+
assert.noFileContent('server/api/endpoint.js', /sendFile:/);
199+
});
200+
});
201+
});
202+
203+
describe('generator-http-fake-backend → endpoint → send file', () => {
204+
beforeAll(() => {
205+
return helpers.run(path.join(__dirname, '../generators/endpoint'))
206+
.withOptions({someOption: true})
207+
.withPrompts({
208+
endpointName: 'endpoint',
209+
method: 'GET',
210+
responseType: 'fileAttachment',
211+
response: 'foo.pdf',
212+
statusCode: 204,
213+
anotherUrl: false
214+
})
215+
.toPromise();
216+
});
217+
218+
it('should create endpoint.js', () => {
219+
assert.file([
220+
'server/api/endpoint.js'
221+
]);
222+
});
223+
224+
describe('endpoint.js', () => {
225+
it('should contain the prompted response', () => {
226+
assert.fileContent('server/api/endpoint.js', /response: '\/response-files\/foo.pdf'/);
227+
});
228+
229+
it('should not have a mimeType key', () => {
230+
assert.noFileContent('server/api/endpoint.js', /mimeType: 'text\/html'/);
231+
});
232+
233+
it('should have a sendFile key ', () => {
234+
assert.fileContent('server/api/endpoint.js', /sendFile: true/);
235+
});
236+
});
237+
});
238+
90239
describe('generator-http-fake-backend → endpoint → prompting helpers', () => {
91240
describe('→ filterResponseType()', () => {
92241
it('should return correct outputs', () => {
93-
assert.equal(helper.filterResponseType('The content of a JSON file'), 'json');
94-
assert.equal(helper.filterResponseType('A JavaScript object literal'), 'object');
242+
assert.equal(helper.filterResponseType('The content of a file'), 'fileContent');
243+
assert.equal(helper.filterResponseType('A file via Content-Disposition: attachment'), 'fileAttachment');
244+
assert.equal(helper.filterResponseType('A JavaScript object literal as JSON'), 'objectLiteral');
95245
assert.equal(helper.filterResponseType('An error object'), 'error');
96246
});
97247
});

generators/app/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ module.exports = class extends Generator {
5353
apiPrefix: this.props.apiPrefix
5454
}
5555
);
56-
this.fs.copy(
57-
this.templatePath('eslintrc'),
58-
this.destinationPath('.eslintrc')
59-
);
6056
this.fs.copy(
6157
this.templatePath('gitattributes'),
6258
this.destinationPath('.gitattributes')
@@ -108,10 +104,10 @@ module.exports = class extends Generator {
108104
this.destinationPath('server.js')
109105
);
110106

111-
// JSON templates
107+
// Directory for response files
112108
this.fs.copy(
113-
this.templatePath('json-templates/gitkeep'),
114-
this.destinationPath('json-templates/.gitkeep')
109+
this.templatePath('response-files/gitkeep'),
110+
this.destinationPath('response-files/.gitkeep')
115111
);
116112

117113
// Server files

0 commit comments

Comments
 (0)