2023-01-24 08:04:43 +00:00
|
|
|
const {models} = require('vn-loopback/server/server');
|
2019-01-23 12:11:44 +00:00
|
|
|
|
2023-01-24 09:35:21 +00:00
|
|
|
describe('VnUser signOut()', () => {
|
2019-01-23 12:11:44 +00:00
|
|
|
it('should logout and remove token after valid login', async() => {
|
2023-01-24 09:35:21 +00:00
|
|
|
let loginResponse = await models.VnUser.signOut('buyer', 'nightmare');
|
2023-01-24 08:04:43 +00:00
|
|
|
let accessToken = await models.AccessToken.findById(loginResponse.token);
|
2019-01-23 12:11:44 +00:00
|
|
|
let ctx = {req: {accessToken: accessToken}};
|
|
|
|
|
2023-01-24 09:35:21 +00:00
|
|
|
let logoutResponse = await models.VnUser.signOut(ctx);
|
2023-01-24 08:04:43 +00:00
|
|
|
let tokenAfterLogout = await models.AccessToken.findById(loginResponse.token);
|
2019-01-23 12:11:44 +00:00
|
|
|
|
2020-10-16 09:16:24 +00:00
|
|
|
expect(logoutResponse).toBeTrue();
|
|
|
|
expect(tokenAfterLogout).toBeNull();
|
2019-01-23 12:11:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw a 401 error when token is invalid', async() => {
|
|
|
|
let error;
|
|
|
|
let ctx = {req: {accessToken: {id: 'invalidToken'}}};
|
|
|
|
|
|
|
|
try {
|
2023-01-24 09:35:21 +00:00
|
|
|
response = await models.VnUser.signOut(ctx);
|
2019-01-23 12:11:44 +00:00
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
expect(error.statusCode).toBe(401);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error when no token is passed', async() => {
|
|
|
|
let error;
|
|
|
|
let ctx = {req: {accessToken: null}};
|
|
|
|
|
|
|
|
try {
|
2023-01-24 09:35:21 +00:00
|
|
|
response = await models.VnUser.signOut(ctx);
|
2019-01-23 12:11:44 +00:00
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|