50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
const {models} = require('vn-loopback/server/server');
|
|
describe('Renew Token', () => {
|
|
const startingTime = Date.now();
|
|
let ctx = null;
|
|
beforeAll(async() => {
|
|
const unAuthCtx = {
|
|
req: {
|
|
headers: {},
|
|
connection: {
|
|
remoteAddress: '127.0.0.1'
|
|
},
|
|
getLocale: () => 'en'
|
|
},
|
|
args: {}
|
|
};
|
|
let login = await models.VnUser.signIn(unAuthCtx, 'salesAssistant', 'nightmare');
|
|
let accessToken = await models.AccessToken.findById(login.token);
|
|
ctx = {req: {accessToken: accessToken}};
|
|
});
|
|
|
|
beforeEach(() => {
|
|
jasmine.clock().install();
|
|
jasmine.clock().mockDate(new Date(startingTime));
|
|
});
|
|
|
|
afterEach(() => {
|
|
jasmine.clock().uninstall();
|
|
});
|
|
|
|
it('should renew process', async() => {
|
|
jasmine.clock().mockDate(new Date(startingTime + 21600000));
|
|
const {id} = await models.VnUser.renewToken(ctx);
|
|
|
|
expect(id).not.toEqual(ctx.req.accessToken.id);
|
|
});
|
|
|
|
it('NOT should renew', async() => {
|
|
let error;
|
|
let response;
|
|
try {
|
|
response = await models.VnUser.renewToken(ctx);
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
expect(error).toBeUndefined();
|
|
expect(response.id).toEqual(ctx.req.accessToken.id);
|
|
});
|
|
});
|