Skip to content

Commit

Permalink
feat: add /auth/validate-token e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evelinakutalo committed Aug 7, 2023
1 parent 5015d5b commit 0cd2761
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/controllers/auth.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,58 @@ describe('Auth', () => {
expect(res.body.status).toEqual(API_RESPONSE_STATUS.error);
expect(res.body.response.code).toEqual(API_ERROR_CODES.userExists);
})
})
})

describe('Validate token', () => {
it ('should validate token', async () => {
await makeRequest({
method: 'post',
url: '/auth/register',
payload: {
username: 'test_user',
password: 'test_user',
},
});

await makeRequest({
method: 'post',
url: '/auth/login',
payload: {
username: 'test_user',
password: 'test_user',
},
});

const validateTokenRes = await makeRequest({
method: 'get',
url: '/auth/validate-token',
});

expect(validateTokenRes.statusCode).toEqual(200);
})

it('Check empty token', async () => {
const validateTokenRes = await makeRequest({
method: 'get',
url: '/auth/validate-token',
headers: {
'Authorization': '',
}
});

expect(validateTokenRes.statusCode).toEqual(401);
})

it('Check invalid token', async () => {
const validateTokenRes = await makeRequest({
method: 'get',
url: '/auth/validate-token',
headers: {
'Authorization': 'Bearer random token',
}
});

expect(validateTokenRes.statusCode).toEqual(401);
})
})
})

0 comments on commit 0cd2761

Please sign in to comment.