How to use the fusion-test-utils.request function in fusion-test-utils

To help you get started, we’ve selected a few fusion-test-utils 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 fusionjs / fusionjs / fusion-plugin-csrf-protection / src / __tests__ / index.node.js View on Github external
test('fails with session and invalid token', async t => {
  const Session = getSession();
  const app = new App('fake-element', el => el);
  app.plugin(CsrfToken, {Session});

  await request(app, '/csrf-token', {method: 'POST'});

  try {
    await request(app, '/test', {
      method: 'POST',
      headers: {'x-csrf-token': 'invalid'},
    });
    t.fail('should fail');
  } catch (e) {
    t.equal(e.status, 403);
  }

  t.end();
});
github fusionjs / fusionjs / fusion-plugin-csrf-protection / src / __tests__ / index.node.js View on Github external
test('does not verify ignored paths', async t => {
  const Session = getSession();
  const app = new App('fake-element', el => el);
  const CSRF = app.plugin(CsrfToken, {Session});
  CSRF.of().ignore('/test');
  const ctx = await request(app, '/test', {
    method: 'POST',
  });
  t.equal(ctx.response.status, 200);
  t.end();
});
github fusionjs / fusionjs / fusion-plugin-universal-events / src / __tests__ / __node__ / index.js View on Github external
app.plugin(() => async (ctx, next) => {
    const emitter = Emitter.of(ctx);
    emitter.on('test-timeout', ({x, lol}) => {
      t.equals(x, 1, 'payload is correct');
      t.ok(lol, 'runs mappers');
      flags.timeout = true;
    });
    setTimeout(() => {
      t.ok(emitter.flushed, 'has flushed events');
      emitter.emit('test-timeout', {x: 1});
      t.ok(flags.timeout, 'emits events immediately after flushing');
    }, 100);
    return next();
  });

  await request(app, '/lol', {method: 'POST'});

  t.ok(flags.preawait, 'flushes batch from pre-await emitted events');
  t.ok(flags.postawait, 'flushes batch from post-await emitted events');
  t.ok(flags.postend, 'flushes batch from post-end emitted events');

  setTimeout(() => {
    t.ok(flags.timeout, 'supports emitting events after batch has flushed');
    t.end();
  }, 150);
});
github fusionjs / fusionjs / fusion-plugin-csrf-protection / src / __tests__ / index.node.js View on Github external
test('creates a session on a GET request', async t => {
  const Session = getSession();
  const app = new App('fake-element', el => el);
  app.plugin(CsrfToken, {Session});

  const ctx = await request(app, '/');
  t.notok(
    ctx.response.headers['x-csrf-token'],
    'does not set x-csrf-token header'
  );
  t.equals(ctx.response.status, 200, 'has right status');
  t.ok(Session.of(ctx).get('csrf-secret'), 'sets the session');
  t.end();
});

fusion-test-utils

Test utilities for FusionJS

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis

Similar packages