All files / server/tests/helpers persist.js

100% Statements 12/12
50% Branches 3/6
100% Functions 4/4
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27    1x   4x   5x       5x 5x 5x     1x         1x 1x 1x   4x    
// Persist - make request in a persistent way
 
const supertest = require('supertest');
 
module.exports = ctx => ({
  getter: async (path) => {
    const res = await supertest(ctx.server)
      .get(path)
      .set('Cookie', ctx.prev || '');
 
    ctx.prev = res.headers['set-cookie'];
    res.body = res.text;
    return res;
  },
  poster: async (path = '/', data = {}) => {
    const res = await supertest(ctx.server)
      .post(path)
      .send(data)
      .set('Cookie', ctx.prev || '');
 
    ctx.prev = res.headers['set-cookie'];
    res.body = res.text;
    return res;
  },
  close: () => ctx.close()
});