2021-03-01 11:15:13 +00:00
|
|
|
const app = 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 app.models.StarredModule.toggleStarredModule(ctx, 'Orders');
|
|
|
|
let starredModules = await app.models.StarredModule.getStarredModules(ctx);
|
|
|
|
|
|
|
|
expect(starredModules.length).toEqual(1);
|
|
|
|
expect(starredModule.moduleFk).toEqual('Orders');
|
|
|
|
expect(starredModule.workerFk).toEqual(activeCtx.accessToken.userId);
|
2021-06-01 20:18:13 +00:00
|
|
|
expect(starredModule.position).toEqual(starredModules.length);
|
2021-03-01 11:15:13 +00:00
|
|
|
|
|
|
|
await app.models.StarredModule.toggleStarredModule(ctx, 'Orders');
|
|
|
|
starredModules = await app.models.StarredModule.getStarredModules(ctx);
|
|
|
|
|
|
|
|
expect(starredModules.length).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|