Skip to content

Commit 0eeae1f

Browse files
authored
Merge pull request #65 from eldimious/feature/fix-broken-tests
fix tests
2 parents 02a41be + 9cff912 commit 0eeae1f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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

Lines changed: 18 additions & 13 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', () => {
@@ -77,22 +78,26 @@ describe('post routes test', () => {
7778
afterEach(() => {
7879
postsService.listUserPosts.restore();
7980
});
80-
it('should return 200 an array of posts', (done) => {
81+
it('should return 200 an array of posts', async () => {
8182
postsService.listUserPosts.resolves(postData);
82-
request(app)
83-
.get('/users/5fb02910c74ce3697859cee2/posts')
84-
.set('Authorization', `Bearer ${testToken}`)
85-
.expect(200)
86-
.then((res) => {
87-
expect(res.body.length).to.eql(postData.length);
88-
return done();
89-
});
83+
const res = await request(app)
84+
.get(`/users/${testID}/posts`)
85+
.set('Authorization', `Bearer ${testToken}`);
86+
expect(res.statusCode).to.to.eql(200);
87+
expect(res.body.length).to.to.eql(postData.length);
9088
});
91-
it('should return 403 when no token send', () => request(app)
92-
.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(403);
95+
});
96+
it('should return 401 when no token send', () => request(app)
97+
.get(`/users/${testID}/posts`)
9398
.expect(401));
9499
it('should return 401 when we send invalid token', () => request(app)
95-
.get('/users/5fb02910c74ce3697859cee2/posts')
100+
.get(`/users/${testID}/posts`)
96101
.set('Authorization', `Bearer ${testToken}test`)
97102
.expect(401));
98103
});

0 commit comments

Comments
 (0)