38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
const {models} = require('vn-loopback/server/server');
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
describe('toggleStarredModule()', () => {
|
|
const activeCtx = {
|
|
accessToken: {userId: 9},
|
|
http: {
|
|
req: {
|
|
headers: {origin: 'http://localhost'}
|
|
}
|
|
}
|
|
};
|
|
const ctx = {
|
|
req: activeCtx
|
|
};
|
|
|
|
beforeEach(() => {
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
active: activeCtx
|
|
});
|
|
});
|
|
|
|
it('should create a new starred module and then remove it by calling the method again with same args', async() => {
|
|
const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order');
|
|
let starredModules = await models.StarredModule.getStarredModules(ctx);
|
|
|
|
expect(starredModules.length).toEqual(1);
|
|
expect(starredModule.moduleFk).toEqual('order');
|
|
expect(starredModule.workerFk).toEqual(activeCtx.accessToken.userId);
|
|
expect(starredModule.position).toEqual(starredModules.length);
|
|
|
|
await models.StarredModule.toggleStarredModule(ctx, 'order');
|
|
starredModules = await models.StarredModule.getStarredModules(ctx);
|
|
|
|
expect(starredModules.length).toEqual(0);
|
|
});
|
|
});
|