<commit_before>const request = require('supertest');
const path = require('path');

describe('routing:defaults', () => {
  const origNodeEnv = process.env.NODE_ENV;

  beforeEach(() => {
  });

  afterEach(() => {
    // Restore original NODE_ENV (determines prod vs dev mode)
    process.env.NODE_ENV = origNodeEnv;

    // Force app module to reload after each test
    delete require.cache[path.resolve('js/server/app.js')];
  });

  it('handles 404s', (done) => {
    const app = require('js/server/app');
    request(app)
    .get('/blerg')
    .expect(404, done);
  });

  it('handles 500s in dev mode', (done) => {
    process.env.NODE_ENV = 'development';
    const app = require('js/server/app');
    const testroutes = require('js/server/routes/testroutes');
    testroutes.get('/500', function route500(req, res, _next) {
      throw new Error('Injected 500');
    });
    request(app)
    .get('/test/500')
    .expect(500, done);
  });

  it('handles 500s in prod mode', (done) => {
    process.env.NODE_ENV = 'production';
    const app = require('js/server/app.js');
    const testroutes = require('js/server/routes/testroutes');
    testroutes.get('/500', function route500(req, res, _next) {
      throw new Error('Injected 500');
    });
    request(app)
    .get('/test/500')
    .expect(500, done);
  });
});<commit_msg>Write server integration tests to check redirects when log in with valid/invalid creds<commit_after>const request = require('supertest');
const path = require('path');
const chai = require('chai');
const expect = chai.expect;

describe('routing:defaults', () => {
  const origNodeEnv = process.env.NODE_ENV;

  beforeEach(() => {
  });

  afterEach(() => {
    // Restore original NODE_ENV (determines prod vs dev mode)
    process.env.NODE_ENV = origNodeEnv;

    // Force app module to reload after each test
    delete require.cache[path.resolve('js/server/app.js')];
  });

  it('handles 404s', (done) => {
    const app = require('js/server/app');
    request(app)
    .get('/blerg')
    .expect(404, done);
  });

  it('handles 500s in dev mode', (done) => {
    process.env.NODE_ENV = 'development';
    const app = require('js/server/app');
    const testroutes = require('js/server/routes/testroutes');
    testroutes.get('/500', function route500(req, res, _next) {
      throw new Error('Injected 500');
    });
    request(app)
    .get('/test/500')
    .expect(500, done);
  });

  it('handles 500s in prod mode', (done) => {
    process.env.NODE_ENV = 'production';
    const app = require('js/server/app.js');
    const testroutes = require('js/server/routes/testroutes');
    testroutes.get('/500', function route500(req, res, _next) {
      throw new Error('Injected 500');
    });
    request(app)
    .get('/test/500')
    .expect(500, done);
  });

  it('redirects to the editor when access a protected url and not logged in', (done) => {
    const app = require('js/server/app.js');
    request.agent(app)
    .post('/login')
    .send({ username: 'testuser', password: '<PASSWORD>' })
    .end((err, res) => {
      expect(res.header.location).to.include('/editor');
      done();
    });
  });

  it('redirects back to the editor try logging in with bad username', (done) => {
    const app = require('js/server/app.js');
    request.agent(app)
    .post('/login')
    .send({ username: 'baduser', password: '<PASSWORD>' })
    .end((err, res) => {
      expect(res.header.location).to.include('/login');
      done();
    });
  });

  it('redirects back to the editor try logging in with bad password', (done) => {
    const app = require('js/server/app.js');
    request.agent(app)
    .post('/login')
    .send({ username: 'testuser', password: '<PASSWORD>' })
    .end((err, res) => {
      expect(res.header.location).to.include('/login');
      done();
    });
  });
});
{'fraction_non_alphanumeric': 0.1833810888252149, 'fraction_numerical': 0.02188069809846314, 'mean_word_length': 3.19672131147541, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 24, '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': '5865866', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1240, 'n_words': 290}