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() {
|
2024-06-26 07:35:18 +00:00
|
|
|
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 = {
|
2024-06-26 07:35:18 +00:00
|
|
|
mockLoopBackContext
|
2024-04-01 08:58:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
(function init() {
|
|
|
|
vnBeforeAll();
|
|
|
|
})();
|