Skip to content

Commit 574cb81

Browse files
committedFeb 11, 2020
Fix default options for router
1 parent 4461f2a commit 574cb81

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎__tests__/server/plural-fake.js

+17
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,29 @@ describe('Fake server', () => {
1212

1313
db.posts = [{ id: 1, body: 'foo' }, { id: 2, body: 'bar' }]
1414

15+
db.comments = [
16+
{ id: 1, body: 'foo', published: true, postId: 1, userId: 1 },
17+
{ id: 2, body: 'bar', published: false, postId: 1, userId: 2 },
18+
{ id: 3, body: 'baz', published: false, postId: 2, userId: 1 },
19+
{ id: 4, body: 'qux', published: true, postId: 2, userId: 2 },
20+
{ id: 5, body: 'quux', published: false, postId: 2, userId: 1 }
21+
]
22+
1523
server = jsonServer.create()
1624
router = jsonServer.router(db, { _isFake: true })
1725
server.use(jsonServer.defaults())
1826
server.use(router)
1927
})
2028

29+
describe('GET /:parent/:parentId/:resource', () => {
30+
test('should respond with json and corresponding nested resources', () =>
31+
request(server)
32+
.get('/posts/1/comments')
33+
.expect('Content-Type', /json/)
34+
.expect([db.comments[0], db.comments[1]])
35+
.expect(200))
36+
})
37+
2138
describe('POST /:resource', () => {
2239
test('should not create a resource', async () => {
2340
await request(server)

‎src/server/router/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const nested = require('./nested')
1212
const singular = require('./singular')
1313
const mixins = require('../mixins')
1414

15-
module.exports = (db, opts = { foreignKeySuffix: 'Id', _isFake: false }) => {
15+
module.exports = (db, opts) => {
16+
opts = Object.assign({ foreignKeySuffix: 'Id', _isFake: false }, opts)
17+
1618
if (typeof db === 'string') {
1719
db = low(new FileSync(db))
1820
} else if (!_.has(db, '__chain__') || !_.has(db, '__wrapped__')) {

0 commit comments

Comments
 (0)
Please sign in to comment.