Skip to content

Commit

Permalink
Doh! Again! Add missed controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks committed Apr 4, 2024
1 parent 81f37a0 commit e9c36d6
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/controllers/data.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { expect } = Code

// Things we need to stub
const SeedService = require('../../app/services/data/seed/seed.service.js')
const SubmitDeduplicateService = require('../../app/services/data/deduplicate/submit-deduplicate.service.js')
const TearDownService = require('../../app/services/data/tear-down/tear-down.service.js')

// For running our service
Expand All @@ -34,6 +35,79 @@ describe('Data controller', () => {
Sinon.restore()
})

describe('/data/deduplicate', () => {
const auth = {
strategy: 'session',
credentials: { scope: ['billing'] }
}

let options

describe('GET', () => {
beforeEach(() => {
options = {
method: 'GET',
url: '/data/deduplicate',
auth
}
})

describe('when the request succeeds', () => {
it('returns the page successfully', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('De-duplicate a licence')
})
})
})

describe('POST', () => {
const licenceRef = '01/120'

beforeEach(() => {
options = {
method: 'POST',
url: '/data/deduplicate',
auth
}
})

describe('when a request is valid', () => {
beforeEach(async () => {
options.payload = { 'licence-ref': licenceRef }

Sinon.stub(SubmitDeduplicateService, 'go').resolves({ licenceRef })
})

it('redirects to the search page', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(302)
expect(response.headers.location).to.equal(`/licences?query=${licenceRef}`)
})
})

describe('when a request is invalid', () => {
beforeEach(async () => {
options.payload = {}

Sinon.stub(SubmitDeduplicateService, 'go').resolves({
error: { text: 'Enter a licence reference to de-dupe' }
})
})

it('re-renders the page with an error message', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('There is a problem')
expect(response.payload).to.contain('Enter a licence reference to de-dupe')
})
})
})
})

describe('/data/seed', () => {
describe('POST', () => {
const options = {
Expand Down

0 comments on commit e9c36d6

Please sign in to comment.