Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('JWT middleware', () => {
let utilModule;
let factoryModule;
const context = createContext();
const effectMeta = createEffectMetadata({ ask: lookup(context) });
beforeEach(() => {
jest.unmock('../jwt.util.ts');
jest.unmock('../jwt.factory.ts');
utilModule = require('../jwt.util.ts');
factoryModule = require('../jwt.factory.ts');
});
afterEach(() => {
jest.clearAllMocks();
});
test('authorize$ authorizes incoming request and saves JWT payload to "req.user"', done => {
// given
const mockedSecret = 'test_secret';
const mockedToken = 'TEST_TOKEN';
setHeader: jest.fn(),
getHeader: jest.fn(),
end: jest.fn(),
} as unknown) as HttpResponse);
export const createMockRequest = (
method: HttpMethod = 'GET',
headers: any = { origin: 'fake-origin' },
) =>
(({
method,
headers: { ...headers },
} as unknown) as HttpRequest);
const context = createContext();
const metadata = createEffectMetadata({ ask: lookup(context) });
describe('CORS middleware', () => {
test('pass through non CORS requests', () => {
const request = createMockRequest('OPTIONS', { origin: null });
const middleware$ = cors$();
Marbles.assertEffect(middleware$, [
['-a-', { a: request }],
['-a-', { a: request }],
]);
});
test('handle CORS preflight request', done => {
expect.assertions(1);
describe('bodyParser$ middleware', () => {
const context = createContext();
const effectMeta = createEffectMetadata({ ask: lookup(context) });
beforeEach(() => {
spyOn(console, 'log').and.stub();
spyOn(console, 'error').and.stub();
});
test('passes through non POST || PATCH || PUT requests', () => {
const request = new MockReq({
method: 'GET',
});
Marbles.assertEffect(bodyParser$(), [
['-a-', { a: request }],
['-a-', { a: request }],
]);
});
beforeEach(() => {
defaultMetadata = createEffectMetadata({ ask: lookup(createContext()) });
});
const handleMessage: HandleMessage = (client, ask) => {
const eventSubject$ = new Subject();
const incomingEventSubject$ = new Subject();
const defaultMetadata = createEffectMetadata({ ask });
const decodedEvent$ = incomingEventSubject$.pipe(map(providedTransformer.decode));
const middlewares$ = combinedMiddlewares(decodedEvent$, client, defaultMetadata);
const effects$ = combinedEffects(eventSubject$, client, defaultMetadata);
const effectsOutput$ = output$(effects$, client, defaultMetadata);
const subscribeMiddlewares = (input$: Observable) =>
input$.subscribe(
event => eventSubject$.next(event),
error => handleEffectsError(defaultMetadata, client, providedError$)(error),
);
const subscribeEffects = (input$: Observable) =>
input$.subscribe(
event => client.sendResponse(event),
error => handleEffectsError(defaultMetadata, client, providedError$)(error),
);