How to use the @marblejs/core.createContext 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 / websockets / src / listener / specs / websocket.listener.spec.ts View on Github external
test('triggers connection error', done => {
      // given
      const error = new WebSocketConnectionError('Unauthorized', HttpStatus.UNAUTHORIZED);
      const connection$: WsConnectionEffect = req$ => req$.pipe(mergeMapTo(throwError(error)));
      const webSocketServer = webSocketListener({ connection$ });
      const targetClient1 = testBed.getClient(0);
      const targetClient2 = testBed.getClient(1);
      const server = testBed.getServer();
      const context = createContext();

      // when
      webSocketServer({ server }).run(context);

      // then
      merge(
        fromEvent(targetClient1, 'unexpected-response'),
        fromEvent(targetClient2, 'unexpected-response'),
      )
      .pipe(take(2), toArray())
      .subscribe(
        (data) => {
          expect(data[0][1].statusCode).toEqual(error.status);
          expect(data[1][1].statusCode).toEqual(error.status);
          expect(data[0][1].statusMessage).toEqual(error.message);
          expect(data[1][1].statusMessage).toEqual(error.message);
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';
github marblejs / example / src / api / common / effects / version.effect.spec.ts View on Github external
describe('versionEffect$', () => {
  const app = httpListener.run(createContext());

  test('GET api/v1 responds with 200', async () =>
    request(app)
      .get('/api/v1')
      .expect(200, '"API version: v1"'));
});
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 / example / src / api / common / effects / notFound.effect.spec.ts View on Github external
describe('notFoundEffect$', () => {
  const app = httpListener.run(createContext());

  test('GET api/v1/undefined responds with 400', async () =>
    request(app)
      .get('/api/v1/undefined')
      .expect(404, { error: { status: 404, message: 'Route not found' } }));
});
github marblejs / example / src / api / users / effects / getMe.effect.spec.ts View on Github external
describe('getMeEffect$', () => {
  const app = httpListener.run(createContext());

  test('GET /api/v1/users/me returns 200 and currently logged user details', async () => {
    const user = await mockUser();
    const token = await mockAuthorizationFor(user)(app);

    return request(app)
      .get('/api/v1/users/me')
      .set('Authorization', `Bearer ${token}`)
      .expect(200)
      .then(({ body }) => {
        expect(body._id).toEqual(String(user._id));
        expect(body.email).toEqual(user.email);
        expect(body.firstName).toEqual(user.firstName);
        expect(body.lastName).toEqual(user.lastName);
        expect(body.roles).toBeDefined();
        expect(body.password).toBeUndefined();
github marblejs / example / src / api / common / effects / getFile.effect.spec.ts View on Github external
describe('getFileEffect$', () => {
  const app = httpListener.run(createContext());

  test('GET api/v1/assets/:dir responds with 200 for actors entity', async () =>
    request(app)
      .get('/api/v1/assets/img/actors/placeholder.jpg')
      .expect(200));

  test('GET api/v1/assets/:dir responds with 200 for movies entity', async () =>
    request(app)
      .get('/api/v1/assets/img/movies/placeholder.jpg')
      .expect(200));

  test('GET api/v1/assets/:dir responds with 404 if file is not found', async () =>
    request(app)
      .get('/api/v1/assets/img/not_found.jpg')
      .expect(404, { error: {
        status: 404,
github marblejs / example / src / index.ts View on Github external
const bootstrap = async () => {
  await Database.connect();
  await Server.create(httpListener.run(createContext()));
};
github edbzn / reactive-blog / packages / server / src / connection / server.ts View on Github external
export const create = async (httpListener: HttpListener) => {
    const httpListenerWithContext = httpListener.run(createContext());

    createServer(httpListenerWithContext)
      .listen(port)
      .on('close', onClose)
      .on('error', onError)
      .on('listening', onListen);
  };
}