Skip to content

Commit

Permalink
Reorder unit tests after the merge messed it up
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozzey committed Jan 15, 2025
1 parent 38b9332 commit e02b109
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions test/controllers/return-logs-setup.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const ReceivedService = require('../../app/services/return-logs/setup/received.s
const ReportedService = require('../../app/services/return-logs/setup/reported.service.js')
const StartService = require('../../app/services/return-logs/setup/start.service.js')
const SubmitReceivedService = require('../../app/services/return-logs/setup/submit-received.service.js')
const SubmitStartService = require('../../app/services/return-logs/setup/submit-start.service.js')
const SubmitReportedService = require('../../app/services/return-logs/setup/submit-reported.service.js')
const SubmitStartService = require('../../app/services/return-logs/setup/submit-start.service.js')
const SubmitUnitsService = require('../../app/services/return-logs/setup/submit-units.service.js')
const UnitsService = require('../../app/services/return-logs/setup/units.service.js')

Expand Down Expand Up @@ -77,86 +77,87 @@ describe('Return Logs Setup controller', () => {
})
})

describe('/return-logs/setup/{sessionId}/start', () => {
describe('return-logs/setup/{sessionId}/received', () => {
describe('GET', () => {
beforeEach(() => {
options = {
method: 'GET',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/start',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/received',
auth: {
strategy: 'session',
credentials: { scope: ['billing'] }
}
}
})

describe('when the request succeeds', () => {
describe('when a request is valid', () => {
beforeEach(() => {
Sinon.stub(StartService, 'go').resolves({ pageTitle: 'Abstraction return' })
Sinon.stub(ReceivedService, 'go').resolves({
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5',
licenceId: '3154ea03-e232-4c66-a711-a72956b7de61',
pageTitle: 'When was the return received?'
})
})

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

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Abstraction return')
expect(response.payload).to.contain('When was the return received?')
})
})
})

describe('POST', () => {
describe('when the request succeeds', () => {
describe('when a request is valid', () => {
beforeEach(() => {
options = _postOptions('start', { journey: 'selectedOption' })
options = _postOptions('received', {})
})

describe('and an option is selected', () => {
describe('and the received date is entered', () => {
beforeEach(() => {
Sinon.stub(SubmitStartService, 'go').resolves({})
Sinon.stub(SubmitReceivedService, 'go').resolves({})
})

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

expect(response.statusCode).to.equal(302)
expect(response.headers.location).to.equal(
'/system/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/received'
'/system/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/reported'
)
})
})
})

describe('when the request succeeds', () => {
describe('when a request is invalid', () => {
beforeEach(() => {
options = _postOptions('start', {})
})
options = _postOptions('received')

describe('and the validation fails as no option has been selected', () => {
beforeEach(() => {
Sinon.stub(SubmitStartService, 'go').resolves({
pageTitle: 'Abstraction return',
error: { text: 'Select what you want to do with this return' }
})
Sinon.stub(SubmitReceivedService, 'go').resolves({
error: { message: 'Enter a real received date' },
pageTitle: 'When was the return received?',
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5'
})
})

it('returns the page successfully with the error summary banner', async () => {
const response = await server.inject(options)
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('Select what you want to do with this return')
expect(response.payload).to.contain('Abstraction return')
})
expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Enter a real received date')
expect(response.payload).to.contain('There is a problem')
})
})
})
})

describe('return-logs/setup/{sessionId}/received', () => {
describe('return-logs/setup/{sessionId}/reported', () => {
describe('GET', () => {
beforeEach(() => {
options = {
method: 'GET',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/received',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/reported',
auth: {
strategy: 'session',
credentials: { scope: ['billing'] }
Expand All @@ -166,51 +167,51 @@ describe('Return Logs Setup controller', () => {

describe('when a request is valid', () => {
beforeEach(() => {
Sinon.stub(ReceivedService, 'go').resolves({
Sinon.stub(ReportedService, 'go').resolves({
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5',
licenceId: '3154ea03-e232-4c66-a711-a72956b7de61',
pageTitle: 'When was the return received?'
pageTitle: 'How was this return reported?'
})
})

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

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('When was the return received?')
expect(response.payload).to.contain('How was this return reported?')
})
})
})

describe('POST', () => {
describe('when a request is valid', () => {
beforeEach(() => {
options = _postOptions('received', {})
options = _postOptions('reported', {})
})

describe('and the received date is entered', () => {
describe('and the reported type is entered', () => {
beforeEach(() => {
Sinon.stub(SubmitReceivedService, 'go').resolves({})
Sinon.stub(SubmitReportedService, 'go').resolves({})
})

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

expect(response.statusCode).to.equal(302)
expect(response.headers.location).to.equal(
'/system/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/reported'
'/system/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/units'
)
})
})
})

describe('when a request is invalid', () => {
beforeEach(() => {
options = _postOptions('received')
options = _postOptions('reported')

Sinon.stub(SubmitReceivedService, 'go').resolves({
error: { message: 'Enter a real received date' },
pageTitle: 'When was the return received?',
Sinon.stub(SubmitReportedService, 'go').resolves({
error: { text: 'Select how this return was reported' },
pageTitle: 'How was this return reported?',
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5'
})
})
Expand All @@ -219,83 +220,82 @@ describe('Return Logs Setup controller', () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Enter a real received date')
expect(response.payload).to.contain('Select how this return was reported')
expect(response.payload).to.contain('There is a problem')
})
})
})
})

describe('return-logs/setup/{sessionId}/reported', () => {
describe('/return-logs/setup/{sessionId}/start', () => {
describe('GET', () => {
beforeEach(() => {
options = {
method: 'GET',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/reported',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/start',
auth: {
strategy: 'session',
credentials: { scope: ['billing'] }
}
}
})

describe('when a request is valid', () => {
describe('when the request succeeds', () => {
beforeEach(() => {
Sinon.stub(ReportedService, 'go').resolves({
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5',
licenceId: '3154ea03-e232-4c66-a711-a72956b7de61',
pageTitle: 'How was this return reported?'
})
Sinon.stub(StartService, 'go').resolves({ pageTitle: 'Abstraction return' })
})

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

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('How was this return reported?')
expect(response.payload).to.contain('Abstraction return')
})
})
})

describe('POST', () => {
describe('when a request is valid', () => {
describe('when the request succeeds', () => {
beforeEach(() => {
options = _postOptions('reported', {})
options = _postOptions('start', { journey: 'selectedOption' })
})

describe('and the reported type is entered', () => {
describe('and an option is selected', () => {
beforeEach(() => {
Sinon.stub(SubmitReportedService, 'go').resolves({})
Sinon.stub(SubmitStartService, 'go').resolves({})
})

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

expect(response.statusCode).to.equal(302)
expect(response.headers.location).to.equal(
'/system/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/units'
'/system/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/received'
)
})
})
})

describe('when a request is invalid', () => {
describe('when the request succeeds', () => {
beforeEach(() => {
options = _postOptions('reported')
options = _postOptions('start', {})
})

Sinon.stub(SubmitReportedService, 'go').resolves({
error: { text: 'Select how this return was reported' },
pageTitle: 'How was this return reported?',
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5'
describe('and the validation fails as no option has been selected', () => {
beforeEach(() => {
Sinon.stub(SubmitStartService, 'go').resolves({
pageTitle: 'Abstraction return',
error: { text: 'Select what you want to do with this return' }
})
})
})

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

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Select how this return was reported')
expect(response.payload).to.contain('There is a problem')
expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Select what you want to do with this return')
expect(response.payload).to.contain('Abstraction return')
})
})
})
})
Expand Down

0 comments on commit e02b109

Please sign in to comment.