Skip to content
This repository was archived by the owner on Mar 13, 2021. It is now read-only.

Commit 286faf9

Browse files
committed
Polish
- handle Not Accepted case, treating the response as plain text - remove redudent specification of content types and status codes - add EditorConfig profile
1 parent 1b2101b commit 286faf9

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

.editorconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
# Indentation override for all JS
13+
[*.js]
14+
charset = utf-8
15+
indent_style = space
16+
indent_size = 4
17+
18+
# Matches the exact files either package.json or .travis.yml
19+
[{package.json,.travis.yml}]
20+
indent_style = space
21+
indent_size = 2
22+
23+
# Ignore node_modules
24+
[/src/main/node/node_modules/**]
25+
end_of_line = ignore
26+
insert_final_newline = ignore
27+
trim_trailing_whitespace = ignore
28+
charset = ignore
29+
indent_style = ignore
30+
indent_size = ignore

src/main/node/lib/app.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ function makeApp(fn) {
2929

3030
switch (negotiator.mediaType(SUPPORTED_MEDIA_TYPES)) { // returns the most preferred Accept'ed type intersected with our list
3131
case 'application/json':
32-
res.type("application/json").json(resultx);
32+
res.json(resultx);
3333
break;
3434
case 'text/plain':
3535
// Force text/plain before calling send, as it defaults to html for strings
36-
res.type("text/plain").send("" + resultx);
36+
res.type('text/plain').send('' + resultx);
37+
break;
38+
default:
39+
res.status(406).type('text/plain').send('' + resultx);
3740
break;
38-
3941
}
40-
41-
res.status(200);
4242
}));
4343

4444
// handle errors
@@ -50,4 +50,4 @@ function makeApp(fn) {
5050
return app;
5151
}
5252

53-
module.exports = makeApp;
53+
module.exports = makeApp;

src/main/node/spec/appSpec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('app', () => {
6262
beforeEach(() => {
6363
app = makeApp(name => `Hello ${name}!`);
6464
});
65-
65+
6666
it('should respond with plain text', () => {
6767
return request(app)
6868
.post('/')
@@ -121,4 +121,23 @@ describe('app', () => {
121121
});
122122
});
123123
});
124+
125+
describe('when nothing is accepted', () => {
126+
beforeEach(() => {
127+
app = makeApp(name => `Hello ${name}!`);
128+
});
129+
130+
it('should respond with a 406', () => {
131+
return request(app)
132+
.post('/')
133+
.accept('application/vnd.projectriff.bogus')
134+
.type('text/plain')
135+
.send('riff')
136+
.expect(406)
137+
.expect('content-type', /plain/)
138+
.expect(res => {
139+
expect(res.text).toBe('Hello riff!');
140+
});
141+
});
142+
});
124143
});

0 commit comments

Comments
 (0)