Skip to content

Commit 46a5259

Browse files
committed
Add stricter tests
1 parent f2f9651 commit 46a5259

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/server/router/plural.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ module.exports = (db, name) => {
253253
function update (req, res, next) {
254254
const id = req.params.id
255255
let chain = db.get(name)
256+
console.log(req.body)
256257

257258
chain = req.method === 'PATCH'
258259
? chain.updateById(id, req.body)

test/server/plural.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,23 @@ describe('Server', () => {
551551
})
552552

553553
describe('PUT /:resource/:id', () => {
554-
it('should respond with json and replace resource', (done) => {
554+
it.only('should respond with json and replace resource', (done) => {
555555
var post = {id: 1, booleanValue: true, integerValue: 1}
556556
request(server)
557557
.put('/posts/1')
558+
.set('Accept', 'application/json')
558559
// body property omitted to test that the resource is replaced
559560
.send(post)
560561
.expect('Content-Type', /json/)
561562
.expect(post)
562563
.expect(200)
563564
.end((err, res) => {
564565
if (err) return done(err)
566+
// TODO find a "supertest" way to test this
567+
// https://github.com/typicode/json-server/issues/396
568+
assert.deepStrictEqual(res.body, post)
565569
// assert it was created in database too
566-
assert.deepEqual(db.posts[0], post)
570+
assert.deepStrictEqual(db.posts[0], post)
567571
done()
568572
})
569573
})
@@ -588,8 +592,9 @@ describe('Server', () => {
588592
.expect(200)
589593
.end((err, res) => {
590594
if (err) return done(err)
595+
assert.deepStrictEqual(res.body, post)
591596
// assert it was created in database too
592-
assert.deepEqual(db.posts[0], {id: 1, body: 'bar'})
597+
assert.deepStrictEqual(db.posts[0], {id: 1, body: 'bar'})
593598
done()
594599
})
595600
})

0 commit comments

Comments
 (0)