const { assign, set } = require('lodash')

describe('SSO bypass middleware', () => {
  beforeEach(() => {
    this.mockConfig = {}
    this.ssoBypassMiddleware = proxyquire.noCallThru().load('~/src/middleware/sso-bypass', {
      '../../config': this.mockConfig,
    })
    this.reqMock = assign({}, globalReq, {
      session: {},
    })
    this.nextSpy = sandbox.spy()
  })

  describe('without oauth bypass token', () => {
    it('should call the next middleware without setting the session token', () => {
      this.ssoBypassMiddleware()(this.reqMock, {}, this.nextSpy)

      expect(this.nextSpy.calledOnce).to.be.true
      expect(this.reqMock.session).to.be.an('object').and.empty
    })
  })

  describe('with oauth bypass token', () => {
    it('should set the session token', () => {
      const mockToken = 'mockToken'
      set(this.mockConfig, 'oauth.token', 'mockToken')
      this.ssoBypassMiddleware()(this.reqMock, {}, this.nextSpy)

      expect(this.nextSpy.calledOnce).to.be.true
      expect(this.reqMock.session.token).to.equal(mockToken)
    })
  })
})

@@ -377,44 +377,189 @@
 %0A%0A  
-describe('without 
+context('Oauth bypass token set to false', () =%3E %7B%0A    beforeEach(() =%3E %7B%0A      set(this.mockConfig, '
 oauth
- 
+.
 bypass
+SSO', false)%0A    %7D)%0A%0A    context('and without a developer
  token
+ set
 ', (
@@ -573,77 +573,398 @@
     
-it('should call the next middleware without setting the session
+  beforeEach(() =%3E %7B%0A        this.ssoBypassMiddleware()(this.reqMock, %7B%7D, this.nextSpy)%0A      %7D)%0A%0A      it('should call the next middleware', () =%3E %7B%0A        expect(this.nextSpy.calledOnce).to.be.true%0A      %7D)%0A%0A      it('should not set the session token', () =%3E %7B%0A        expect(this.reqMock.session).to.be.an('object').and.empty%0A      %7D)%0A    %7D)%0A%0A    context('and with a developer
  token
+ set
 ', (
@@ -980,117 +980,381 @@
     
-this.ssoBypassMiddleware()(this.reqMock, %7B%7D, this.nextSpy)%0A%0A      expect(this.nextSpy.calledOnce).to.be.true%0A
+beforeEach(() =%3E %7B%0A        this.mockDevToken = 'mockDevToken'%0A        set(this.mockConfig, 'oauth.devToken', this.mockDevToken)%0A        this.ssoBypassMiddleware()(this.reqMock, %7B%7D, this.nextSpy)%0A      %7D)%0A%0A      it('should call the next middleware', () =%3E %7B%0A        expect(this.nextSpy.calledOnce).to.be.true%0A      %7D)%0A%0A      it('should not set the session token', () =%3E %7B%0A  
     
@@ -1409,24 +1409,33 @@
 ).and.empty%0A
+      %7D)%0A
     %7D)%0A  %7D)%0A
@@ -1441,24 +1441,18 @@
 %0A%0A  
-describe('with o
+context('O
 auth
@@ -1460,24 +1460,36 @@
 bypass token
+ set to true
 ', () =%3E %7B%0A 
@@ -1495,40 +1495,130 @@
     
-it('should set the session
+beforeEach(() =%3E %7B%0A      set(this.mockConfig, 'oauth.bypassSSO', true)%0A    %7D)%0A%0A    context('and with a developer
  token
+ set
 ', (
@@ -1634,18 +1634,47 @@
     
-const 
+beforeEach(() =%3E %7B%0A        this.
 mock
+Dev
 Toke
@@ -1682,23 +1682,28 @@
  = 'mock
+Dev
 Token'%0A
+  
       se
@@ -1732,29 +1732,40 @@
 uth.
-t
+devT
 oken', 
-'
+this.
 mock
+Dev
 Token
-'
 )%0A
+  
     
@@ -1829,58 +1829,182 @@
 py)%0A
-%0A      expect(this.nextSpy.calledOnce).to.be.true%0A
+      %7D)%0A%0A      it('should call the next middleware', () =%3E %7B%0A        expect(this.nextSpy.calledOnce).to.be.true%0A      %7D)%0A%0A      it('should set the session token', () =%3E %7B%0A  
     
@@ -2053,19 +2053,36 @@
 ual(
+this.
 mock
+Dev
 Token)%0A
+      %7D)%0A
     

update tests with bypassSSO work, refactor tests to use context and split out in the improved way of writing tests