const LoopBackContext = require('loopback-context'); const DEFAULT_ACCESS_TOKEN = {accessToken: {userId: 9}}; const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}}; const DEFAULT_BEFORE_ALL = { ctx: { req: { ...DEFAULT_ACCESS_TOKEN, ...DEFAULT_HEADERS }, args: {} } }; const DEFAULT_LOOPBACK_CTX = { ...DEFAULT_ACCESS_TOKEN, http: { req: { ...DEFAULT_HEADERS } }, args: {} }; function vnBeforeAll(value = DEFAULT_BEFORE_ALL) { Object.assign(beforeAll, value); } function mockBeforeAll(value = DEFAULT_BEFORE_ALL) { const origin = beforeAll.ctx; Object.assign(origin, value); return origin; } const mockLoopBackContext = (value = DEFAULT_LOOPBACK_CTX) => { const activeCtx = value; spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); return activeCtx; }; module.exports = { mockBeforeAll, mockLoopBackContext }; (function init() { vnBeforeAll(); })();