const request = require('supertest');
const express = require('express');
const session = require('express-session');
const auth = require('../index');
const { Issuer } = require('openid-client');

Issuer.discover = () => new Issuer({
  issuer: process.env.SDF_OIDC_PROVIDER,
  authorization_endpoint: `${process.env.SDF_OIDC_PROVIDER}/authorize`,
});

let server;
let app;

async function getApp() {
  server = express();
  server.use(session({
    resave: true,
    saveUninitialized: true,
    secret: 'super secret',
  }));

  return auth(server);
}

describe('auth', () => {
  beforeAll(async () => {
    app = await getApp();
  });

  it.skip('redirects to auth provider when hitting /login', async () => {
    process.env.SDF_OIDC_PROVIDER = 'http://example.org/openid';
    process.env.SDF_OIDC_CLIENT_ID = '123456';
    const response = await request(app).get('/auth');
    expect(response.statusCode).toEqual(302);
    expect(response.header).toEqual(
      expect.objectContaining({
        location: expect.stringContaining(process.env.SDF_OIDC_PROVIDER),
      }),
    );
  });

  it('redirects to base page after logging out', async () => {
    const response = await request(app).get('/logout');
    expect(response.statusCode).toEqual(302);
    expect(response.header).toEqual(
      expect.objectContaining({
        location: '/',
      }),
    );
  });
});

describe('openid enabled', () => {
  beforeEach(async () => {
    process.env.SDF_OIDC_PROVIDER = 'http://example.org/openid';
    process.env.SDF_OIDC_CLIENT_ID = '123456';
  });

  afterEach(() => {
    process.env.SDF_OIDC_PROVIDER = '';
    process.env.SDF_OIDC_CLIENT_ID = '';
  });

  it('redirects to OpenID provider when OIDC enabled', async () => {
    app = await getApp();
    const response = await request(app).get('/login');
    expect(response.statusCode).toEqual(302);
    expect(response.header).toEqual(
      expect.objectContaining({
        location: expect.stringContaining(process.env.SDF_OIDC_PROVIDER),
      }),
    );
  });
});

@@ -640,1368 +640,259 @@
   it
-.skip('redirects to auth provider when hitting /login', async () =%3E %7B%0A    process.env.SDF_OIDC_PROVIDER = 'http://example.org/openid';%0A    process.env.SDF_OIDC_CLIENT_ID = '123456';%0A    const response = await request(app).get('/auth');%0A    expect(response.statusCode).toEqual(302);%0A    expect(response.header).toEqual(%0A      expect.objectContaining(%7B%0A        location: expect.stringContaining(process.env.SDF_OIDC_PROVIDER),%0A      %7D),%0A    );%0A  %7D);%0A%0A  it('redirects to base page after logging out', async () =%3E %7B%0A    const response = await request(app).get('/logout');%0A    expect(response.statusCode).toEqual(302);%0A    expect(response.header).toEqual(%0A      expect.objectContaining(%7B%0A        location: '/',%0A      %7D),%0A    );%0A  %7D);%0A%7D);%0A%0Adescribe('openid enabled', () =%3E %7B%0A  beforeEach(async () =%3E %7B%0A    process.env.SDF_OIDC_PROVIDER = 'http://example.org/openid';%0A    process.env.SDF_OIDC_CLIENT_ID = '123456';%0A  %7D);%0A%0A  afterEach(() =%3E %7B%0A    process.env.SDF_OIDC_PROVIDER = '';%0A    process.env.SDF_OIDC_CLIENT_ID = '';%0A  %7D);%0A%0A  it('redirects to OpenID provider when OIDC enabled', async () =%3E %7B%0A    app = await getApp();%0A    const response = await request(app).get('/login');%0A    expect(response.statusCode).toEqual(302);%0A    expect(response.header).toEqual(%0A      expect.objectContaining(%7B%0A        location: expect.stringContaining(process.env.SDF_OIDC_PROVIDER)
+('redirects to base page after logging out', async () =%3E %7B%0A    const response = await request(app).get('/logout');%0A    expect(response.statusCode).toEqual(302);%0A    expect(response.header).toEqual(%0A      expect.objectContaining(%7B%0A        location: '/'
 ,%0A  

Remove test of oidc-client login redirect logic