43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('account logout()', () => {
|
|
it('should logout and remove token after valid login', async() => {
|
|
let loginResponse = await app.models.Account.login('employee', 'nightmare');
|
|
let accessToken = await app.models.AccessToken.findById(loginResponse.token);
|
|
let ctx = {req: {accessToken: accessToken}};
|
|
|
|
let response = await app.models.Account.logout(ctx);
|
|
let afterToken = await app.models.AccessToken.findById(loginResponse.token);
|
|
|
|
expect(response).toBeTruthy();
|
|
expect(afterToken).toBeNull();
|
|
});
|
|
|
|
it('should throw a 401 error when token is invalid', async() => {
|
|
let error;
|
|
let ctx = {req: {accessToken: {id: 'invalidToken'}}};
|
|
|
|
try {
|
|
response = await app.models.Account.logout(ctx);
|
|
} 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 {
|
|
response = await app.models.Account.logout(ctx);
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
expect(error).toBeDefined();
|
|
});
|
|
});
|