Skip to content

Commit 97de61e

Browse files
committed
fix tests
1 parent d4ee888 commit 97de61e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/presentation/http/routes/posts.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const postData = [
6464
const jwtSecret = process.env.JWT_SECRET;
6565
const testEmail = 'kent@gmail.com';
6666
const testFullname = 'klark kent';
67-
const testID = '111111';
67+
const testID = '5fb02910c74ce3697859cee2';
68+
const wrongUserId = '3ca12910c74ce3697859caa1';
6869
let testToken;
6970

7071
describe('post routes test', () => {
@@ -80,16 +81,24 @@ describe('post routes test', () => {
8081
it('should return 200 an array of posts', async () => {
8182
postsService.listUserPosts.resolves(postData);
8283
const res = await request(app)
83-
.get('/users/5fb02910c74ce3697859cee2/posts')
84+
.get(`/users/${testID}/posts`)
8485
.set('Authorization', `Bearer ${testToken}`);
8586
expect(res.statusCode).to.to.eql(200);
8687
expect(res.body.length).to.to.eql(postData.length);
8788
});
88-
it('should return 403 when no token send', () => request(app)
89-
.get('/users/5fb02910c74ce3697859cee2/posts')
89+
it('should return 403 when token of another user is used', async () => {
90+
postsService.listUserPosts.resolves(postData);
91+
const res = await request(app)
92+
.get(`/users/${wrongUserId}/posts`)
93+
.set('Authorization', `Bearer ${testToken}`);
94+
expect(res.statusCode).to.to.eql(200);
95+
expect(res.body.length).to.to.eql(postData.length);
96+
});
97+
it('should return 401 when no token send', () => request(app)
98+
.get(`/users/${testID}/posts`)
9099
.expect(401));
91100
it('should return 401 when we send invalid token', () => request(app)
92-
.get('/users/5fb02910c74ce3697859cee2/posts')
101+
.get(`/users/${testID}/posts`)
93102
.set('Authorization', `Bearer ${testToken}test`)
94103
.expect(401));
95104
});

0 commit comments

Comments
 (0)