const request = require('supertest');
const passportStub = require('passport-stub');

describe('When not authenticated', () => {
  let app;

  before(() => {
    app = require('./server');
  });

  it('returns 302 for /', done => {
    request(app)
      .get('/')
      .expect(302, done);
  });

  it('returns 302 for /callback', done => {
    request(app)
      .get('/callback')
      .expect(302, done);
  });

  it('returns 302 for /login', done => {
    request(app)
      .get('/login')
      .expect(302, done);
  });
});

describe('When authenticated', () => {
  let app;

  before(() => {
    app = require('./server');
    passportStub.install(app);

    passportStub.login({ username: 'test@example.org' });
  });

  it('returns expected content for /', done => {
    request(app)
      .get('/')
      .expect(200, done);
  });

  it('returns expected content for /2017/01/01/a-test-post.html', done => {
    request(app)
      .get('/2017/01/01/a-test-post.html')
      .expect(200, done);
  });
});

@@ -1,12 +1,46 @@
+const assert = require('assert');%0A
 const reques
@@ -177,32 +177,61 @@
  before(() =%3E %7B%0A
+    setupTestEnvironment();%0A%0A
     app = requir
@@ -262,27 +262,41 @@
 it('returns 
-302
+expected response
  for /', don
@@ -327,32 +327,114 @@
       .get('/')%0A
+      .expect('Location', '/login')%0A      .expect('Found. Redirecting to /login')%0A
       .expect(30
@@ -460,27 +460,41 @@
 it('returns 
-302
+expected response
  for /callba
@@ -549,16 +549,309 @@
 lback')%0A
+      .expect(res =%3E %7B%0A        assert.ok(res.headers.location.startsWith(%0A          %60$%7Bprocess.env.AUTHORIZATION_URL%7D?response_type=code&client_id=$%7Bprocess.env.CLIENT_ID%7D&redirect_uri=$%7BencodeURIComponent(process.env.CALLBACK_URL)%7D&scope=openid%2520openid%2520profile%2520email&state=%60));%0A      %7D)%0A
       .e
@@ -889,19 +889,33 @@
 returns 
-302
+expected response
  for /lo
@@ -960,32 +960,325 @@
  .get('/login')%0A
+      .expect(res =%3E %7B%0A        assert.ok(res.headers.location.startsWith(%0A          %60$%7Bprocess.env.AUTHORIZATION_URL%7D?response_type=code&client_id=$%7Bprocess.env.CLIENT_ID%7D&redirect_uri=$%7BencodeURIComponent(process.env.CALLBACK_URL)%7D&scope=openid%2520openid%2520profile%2520email&state=%60));%0A      %7D)%0A
       .expect(30
@@ -1362,24 +1362,53 @@
 ore(() =%3E %7B%0A
+    setupTestEnvironment();%0A%0A
     app = re
@@ -1542,31 +1542,32 @@
 ns expected 
-content
+response
  for /', don
@@ -1598,32 +1598,76 @@
       .get('/')%0A
+      .expect('Content-Type', /text%5C/html/)%0A
       .expect(20
@@ -1710,15 +1710,16 @@
 ted 
-content
+response
  for
@@ -1838,26 +1838,556 @@
 ect(
-200, done);%0A  %7D);%0A%7D);
+'Content-Type', /text%5C/html/)%0A%0A      .expect(200, done);%0A  %7D);%0A%7D);%0A%0Afunction setupTestEnvironment() %7B%0A  process.env.ISSUER = 'https://example.org';%0A  process.env.AUTHORIZATION_URL = 'https://example.org/connect/authorize';%0A  process.env.TOKEN_URL = 'https://example.org/connect/token';%0A  process.env.USER_INFO_URL = 'https://example.org/connect/userinfo';%0A  process.env.CLIENT_ID = 'TestClient';%0A  process.env.CLIENT_SECRET = 'the_secret';%0A  process.env.CALLBACK_URL = 'https://example.com/callback';%0A  process.env.EXPRESS_SESSION_SECRET = 'abc123';%0A%7D
 %0A

Update tests