49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
|
|
const LoopBackContext = require('loopback-context');
|
|
const getAccessToken = (userId = 9) => {
|
|
return {accessToken: {userId}};
|
|
};
|
|
const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}};
|
|
const default_before_all = userId => {
|
|
return {
|
|
req: {
|
|
...getAccessToken(userId),
|
|
...DEFAULT_HEADERS,
|
|
...{__: value => value}
|
|
|
|
},
|
|
args: {}
|
|
};
|
|
};
|
|
const default_loopback_ctx = userId => {
|
|
return {
|
|
...getAccessToken(userId),
|
|
...default_before_all(userId),
|
|
http: {
|
|
...default_before_all(userId)
|
|
},
|
|
args: {}
|
|
};
|
|
};
|
|
|
|
function vnBeforeAll() {
|
|
Object.assign(beforeAll, {getCtx: default_before_all, mockLoopBackContext});
|
|
}
|
|
|
|
const mockLoopBackContext = userId => {
|
|
const activeCtx = default_loopback_ctx(userId);
|
|
beforeAll(() => {
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
active: activeCtx
|
|
});
|
|
});
|
|
return activeCtx;
|
|
};
|
|
module.exports = {
|
|
mockLoopBackContext
|
|
};
|
|
|
|
(function init() {
|
|
vnBeforeAll();
|
|
})();
|