mirror of
https://github.com/typicode/json-server.git
synced 2025-08-01 09:13:32 +08:00
Add stricter tests
This commit is contained in:
@ -253,6 +253,7 @@ module.exports = (db, name) => {
|
|||||||
function update (req, res, next) {
|
function update (req, res, next) {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
let chain = db.get(name)
|
let chain = db.get(name)
|
||||||
|
console.log(req.body)
|
||||||
|
|
||||||
chain = req.method === 'PATCH'
|
chain = req.method === 'PATCH'
|
||||||
? chain.updateById(id, req.body)
|
? chain.updateById(id, req.body)
|
||||||
|
@ -551,10 +551,11 @@ describe('Server', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('PUT /:resource/:id', () => {
|
describe('PUT /:resource/:id', () => {
|
||||||
it('should respond with json and replace resource', (done) => {
|
it.only('should respond with json and replace resource', (done) => {
|
||||||
var post = {id: 1, booleanValue: true, integerValue: 1}
|
var post = {id: 1, booleanValue: true, integerValue: 1}
|
||||||
request(server)
|
request(server)
|
||||||
.put('/posts/1')
|
.put('/posts/1')
|
||||||
|
.set('Accept', 'application/json')
|
||||||
// body property omitted to test that the resource is replaced
|
// body property omitted to test that the resource is replaced
|
||||||
.send(post)
|
.send(post)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
@ -562,8 +563,11 @@ describe('Server', () => {
|
|||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
// TODO find a "supertest" way to test this
|
||||||
|
// https://github.com/typicode/json-server/issues/396
|
||||||
|
assert.deepStrictEqual(res.body, post)
|
||||||
// assert it was created in database too
|
// assert it was created in database too
|
||||||
assert.deepEqual(db.posts[0], post)
|
assert.deepStrictEqual(db.posts[0], post)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -588,8 +592,9 @@ describe('Server', () => {
|
|||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
assert.deepStrictEqual(res.body, post)
|
||||||
// assert it was created in database too
|
// assert it was created in database too
|
||||||
assert.deepEqual(db.posts[0], {id: 1, body: 'bar'})
|
assert.deepStrictEqual(db.posts[0], {id: 1, body: 'bar'})
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user