Skip to content

Commit

Permalink
test: fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Aug 2, 2021
1 parent 9f8b394 commit edfdddd
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 146 deletions.
19 changes: 10 additions & 9 deletions __tests__/server/plural-fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ describe('Fake server', () => {
request(server)
.get('/posts/1/comments')
.expect('Content-Type', /json/)
.expect([db.comments[0], db.comments[1]])
.expect(200))
.expect(200, [db.comments[0], db.comments[1]]))
})

describe('POST /:resource', () => {
Expand All @@ -46,8 +45,12 @@ describe('Fake server', () => {
.expect('Access-Control-Expose-Headers', 'Location')
.expect('Location', /posts\/3$/)
.expect('Content-Type', /json/)
.expect({ id: 3, body: 'foo', booleanValue: true, integerValue: 1 })
.expect(201)
.expect(201, {
id: 3,
body: 'foo',
booleanValue: true,
integerValue: 1,
})
assert.strictEqual(db.posts.length, 2)
})
})
Expand All @@ -61,8 +64,7 @@ describe('Fake server', () => {
// body property omitted to test that the resource is replaced
.send(post)
.expect('Content-Type', /json/)
.expect(post)
.expect(200)
.expect(200, post)
// TODO find a "supertest" way to test this
// https://github.com/typicode/json-server/issues/396
assert.deepStrictEqual(res.body, post)
Expand All @@ -78,16 +80,15 @@ describe('Fake server', () => {
.patch('/posts/1')
.send(partial)
.expect('Content-Type', /json/)
.expect(post)
.expect(200)
.expect(200, post)
assert.deepStrictEqual(res.body, post)
assert.notDeepStrictEqual(db.posts[0], post)
})
})

describe('DELETE /:resource/:id', () => {
test('should not destroy resource', async () => {
await request(server).del('/posts/1').expect({}).expect(200)
await request(server).del('/posts/1').expect(200, {})
assert.strictEqual(db.posts.length, 2)
})
})
Expand Down
21 changes: 7 additions & 14 deletions __tests__/server/plural-with-custom-foreign-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ describe('Server with custom foreign key', () => {
request(server)
.get('/posts/1/comments')
.expect('Content-Type', /json/)
.expect([db.comments[0], db.comments[1]])
.expect(200))
.expect(200, [db.comments[0], db.comments[1]]))
})

describe('GET /:resource/:id', () => {
test('should respond with json and corresponding resource', () =>
request(server)
.get('/posts/1')
.expect('Content-Type', /json/)
.expect(db.posts[0])
.expect(200))
.expect(200, db.posts[0]))
})

describe('GET /:resource?_embed=', () => {
Expand All @@ -54,8 +52,7 @@ describe('Server with custom foreign key', () => {
return request(server)
.get('/posts?_embed=comments')
.expect('Content-Type', /json/)
.expect(posts)
.expect(200)
.expect(200, posts)
})
})

Expand All @@ -66,8 +63,7 @@ describe('Server with custom foreign key', () => {
return request(server)
.get('/posts/1?_embed=comments')
.expect('Content-Type', /json/)
.expect(post)
.expect(200)
.expect(200, post)
})
})

Expand All @@ -80,8 +76,7 @@ describe('Server with custom foreign key', () => {
return request(server)
.get('/comments?_expand=post')
.expect('Content-Type', /json/)
.expect(comments)
.expect(200)
.expect(200, comments)
})
})

Expand All @@ -92,8 +87,7 @@ describe('Server with custom foreign key', () => {
return request(server)
.get('/comments/1?_expand=post')
.expect('Content-Type', /json/)
.expect(comment)
.expect(200)
.expect(200, comment)
})
})

Expand All @@ -103,8 +97,7 @@ describe('Server with custom foreign key', () => {
.post('/posts/1/comments')
.send({ body: 'foo' })
.expect('Content-Type', /json/)
.expect({ id: 4, post_id: '1', body: 'foo' })
.expect(201))
.expect(201, { id: 4, post_id: '1', body: 'foo' }))
})

describe('DELETE /:resource/:id', () => {
Expand Down
Loading

0 comments on commit edfdddd

Please sign in to comment.