Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Orie Chinedu
committed
Aug 24, 2019
1 parent
d03c7e7
commit d5987eb
Showing
4 changed files
with
2,271 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const request = require('supertest'); | ||
const app = require('../server'); | ||
|
||
describe('Post Endpoints', () => { | ||
it('should create a new post', async () => { | ||
const res = await request(app).post('/api/posts') | ||
.send({ | ||
userId: 1, | ||
title: 'test is cool', | ||
}); | ||
expect(res.statusCode).toEqual(201); | ||
expect(res.body).toHaveProperty('post'); | ||
}); | ||
|
||
it('should fetch a single post', async () => { | ||
const postId = 1; | ||
const res = await request(app).get(`/api/posts/${postId}`); | ||
expect(res.statusCode).toEqual(200); | ||
expect(res.body).toHaveProperty('post'); | ||
}); | ||
|
||
it('should fetch all posts', async () => { | ||
const res = await request(app).get('/api/posts'); | ||
expect(res.statusCode).toEqual(200); | ||
expect(res.body).toHaveProperty('posts'); | ||
expect(res.body.posts).toHaveLength(1); | ||
}); | ||
|
||
it('should update a post', async () => { | ||
const res = await request(app).put('/api/posts/1') | ||
.send({ | ||
userId: 1, | ||
title: 'updated title', | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body).toHaveProperty('post'); | ||
expect(res.body.post).toHaveProperty('title','updated title'); | ||
}); | ||
|
||
it('should delete a post', async () => { | ||
const res = await request(app).delete('/api/posts/1'); | ||
expect(res.statusCode).toEqual(204); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
describe('Sample Test', () => { | ||
it('should test that true === true', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.