How to use the @marblejs/core.createEffectMetadata function in @marblejs/core

To help you get started, we’ve selected a few @marblejs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marblejs / marble / packages / middleware-jwt / src / spec / jwt.middleware.spec.ts View on Github external
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';
github marblejs / marble / packages / middleware-cors / src / spec / middleware.spec.ts View on Github external
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);
github marblejs / marble / packages / middleware-body / src / specs / body.middleware.spec.ts View on Github external
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 }],
    ]);
  });
github marblejs / marble / packages / websockets / src / error / specs / ws-error.handler.spec.ts View on Github external
beforeEach(() => {
    defaultMetadata = createEffectMetadata({ ask: lookup(createContext()) });
  });
github marblejs / marble / packages / websockets / src / listener / websocket.listener.ts View on Github external
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),
      );