<commit_before>var Code = require('code'),
    Lab = require('lab'),
    lab = exports.lab = Lab.script(),
    describe = lab.experiment,
    before = lab.before,
    after = lab.after,
    it = lab.test,
    expect = Code.expect,
    redis = require("../../../adapters/redis-sessions"),
    server,
    sinon = require('sinon'),
    users = require('../../fixtures').users;

before(function (done) {
  require('../../mocks/server')(function (obj) {
    server = obj;
    server.methods.user.delSession = sinon.spy(server.methods.user.delSession);
    done();
  });
});

after(function (done) {
  server.methods.user.delSession.reset();
  redis.flushdb();
  server.stop(done);
});

describe('logout', function () {
  it('redirects to the homepage if there is no logged in user', function (done) {
    var options = {
      url: '/logout'
    };

    server.inject(options, function (resp) {
      expect(resp.statusCode).to.equal(302);
      expect(resp.request.response.headers.location).to.equal('/');
      done();
    });
  });

  it('deletes the session for the logged in user', function (done) {
    var options = {
      url: '/logout',
      credentials: users.bob
    };

    server.inject(options, function (resp) {
      expect(resp.statusCode).to.equal(302);
      expect(server.methods.user.delSession.called).to.be.true();
      expect(resp.request.response.headers.location).to.equal('/');
      done();
    });
  });
});<commit_msg>updates test now that logout is a POST instead of a GET<commit_after>var generateCrumb = require("../crumb"),
    Code = require('code'),
    Lab = require('lab'),
    lab = exports.lab = Lab.script(),
    describe = lab.experiment,
    before = lab.before,
    after = lab.after,
    it = lab.test,
    expect = Code.expect,
    redis = require("../../../adapters/redis-sessions"),
    server,
    sinon = require('sinon'),
    users = require('../../fixtures').users;

before(function (done) {
  require('../../mocks/server')(function (obj) {
    server = obj;
    server.methods.user.delSession = sinon.spy(server.methods.user.delSession);
    done();
  });
});

after(function (done) {
  server.methods.user.delSession.reset();
  redis.flushdb();
  server.stop(done);
});

describe('logout', function () {
  it('redirects to the homepage if there is no logged in user', function (done) {
    generateCrumb(server, function (crumb) {
      var options = {
        url: '/logout',
        method: 'POST',
        payload: {
          crumb: crumb,
        },
        headers: { cookie: 'crumb=' + crumb }
      };

      server.inject(options, function (resp) {
        expect(resp.statusCode).to.equal(302);
        expect(resp.request.response.headers.location).to.equal('/');
        done();
      });
    });
  });

  it('deletes the session for the logged in user', function (done) {
    generateCrumb(server, function (crumb) {
      var options = {
        url: '/logout',
        method: 'POST',
        payload: {
          crumb: crumb,
        },
        headers: { cookie: 'crumb=' + crumb },
        credentials: users.bob
      };

      server.inject(options, function (resp) {
        expect(resp.statusCode).to.equal(302);
        expect(server.methods.user.delSession.called).to.be.true();
        expect(resp.request.response.headers.location).to.equal('/');
        done();
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.1765054879857609, 'fraction_numerical': 0.0035597745476119848, 'mean_word_length': 2.5872340425531917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5033306', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1047, 'n_words': 211}