salix/back/vn-jasmine.js

49 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-04-01 08:58:04 +00:00
const LoopBackContext = require('loopback-context');
2024-06-14 06:39:57 +00:00
const getAccessToken = (userId = 9) => {
return {accessToken: {userId}};
};
2024-04-01 08:58:04 +00:00
const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}};
2024-06-14 06:39:57 +00:00
const default_before_all = userId => {
return {
2024-04-01 08:58:04 +00:00
req: {
2024-06-14 06:39:57 +00:00
...getAccessToken(userId),
...DEFAULT_HEADERS,
...{__: value => value}
2024-04-01 08:58:04 +00:00
},
args: {}
2024-06-14 06:39:57 +00:00
};
2024-04-01 08:58:04 +00:00
};
2024-06-14 06:39:57 +00:00
const default_loopback_ctx = userId => {
return {
...getAccessToken(userId),
...default_before_all(userId),
http: {
...default_before_all(userId)
},
args: {}
};
2024-04-01 08:58:04 +00:00
};
2024-06-14 06:39:57 +00:00
function vnBeforeAll() {
Object.assign(beforeAll, {getCtx: default_before_all, mockLoopBackContext});
2024-04-01 08:58:04 +00:00
}
2024-06-14 06:39:57 +00:00
const mockLoopBackContext = userId => {
const activeCtx = default_loopback_ctx(userId);
beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
2024-04-01 08:58:04 +00:00
});
return activeCtx;
};
module.exports = {
mockLoopBackContext
2024-04-01 08:58:04 +00:00
};
(function init() {
vnBeforeAll();
})();