2023-01-24 08:04:43 +00:00
|
|
|
const {models} = require('vn-loopback/server/server');
|
2021-03-01 11:15:13 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
|
|
|
|
describe('getStarredModules()', () => {
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
http: {
|
|
|
|
req: {
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const ctx = {req: activeCtx};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
|
|
|
});
|
2021-02-26 08:08:31 +00:00
|
|
|
|
|
|
|
it(`should return the starred modules for a given user`, async() => {
|
2023-01-24 08:04:43 +00:00
|
|
|
const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1});
|
|
|
|
const starredModules = await models.StarredModule.getStarredModules(ctx);
|
2021-03-01 11:15:13 +00:00
|
|
|
|
|
|
|
expect(starredModules.length).toEqual(1);
|
2022-12-14 13:20:41 +00:00
|
|
|
expect(starredModules[0].moduleFk).toEqual('customer');
|
2021-03-01 11:15:13 +00:00
|
|
|
|
|
|
|
// restores
|
2023-01-24 08:04:43 +00:00
|
|
|
await models.StarredModule.destroyById(newStarred.id);
|
2021-02-26 08:08:31 +00:00
|
|
|
});
|
|
|
|
});
|