Skip to content

Commit

Permalink
Add user to CreateBillRunValidator (#75)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-3854

As part of initialising a new bill run, we create an 'event' record. It requires the `issuer` field to be populated with the email address of the user requesting the new bill run.

So, we'll need to include the current user's email as part of our request. This change updates the validator to include it.
  • Loading branch information
Cruikshanks authored Jan 2, 2023
1 parent 5c90a5d commit e28666f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/validators/bill-runs/create-bill-run.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function go (data) {
type: Joi.string().valid('supplementary').required(),
scheme: Joi.string().valid('sroc').required(),
region: Joi.string().guid().required(),
user: Joi.string().email().required(),
previousBillRunId: Joi.string().guid().optional()
})

Expand Down
6 changes: 4 additions & 2 deletions test/controllers/bill-runs.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('Bill Runs controller:', () => {
payload: {
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}
}

Expand All @@ -47,7 +48,8 @@ describe('Bill Runs controller:', () => {
payload: {
type: 'supplementary',
scheme: 'INVALID',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}
}

Expand Down
57 changes: 49 additions & 8 deletions test/validators/bill-runs/create-bill-run.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Create Bill Run validator', () => {
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk',
previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603'
}

Expand All @@ -26,6 +27,7 @@ describe('Create Bill Run validator', () => {
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk',
previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603'
})
})
Expand All @@ -35,15 +37,17 @@ describe('Create Bill Run validator', () => {
const validData = {
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(validData)

expect(result.value).to.equal({
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
})
})
})
Expand All @@ -54,7 +58,8 @@ describe('Create Bill Run validator', () => {
it('returns an error', async () => {
const invalidData = {
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(invalidData)
Expand All @@ -67,7 +72,8 @@ describe('Create Bill Run validator', () => {
it('returns an error', async () => {
const invalidData = {
type: 'supplementary',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(invalidData)
Expand All @@ -80,7 +86,22 @@ describe('Create Bill Run validator', () => {
it('returns an error', async () => {
const invalidData = {
type: 'supplementary',
scheme: 'sroc'
scheme: 'sroc',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(invalidData)

expect(result.error).to.not.be.empty()
})
})

describe('because `user` is missing', () => {
it('returns an error', async () => {
const invalidData = {
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c'
}

const result = await CreateBillRunValidator.go(invalidData)
Expand All @@ -93,7 +114,9 @@ describe('Create Bill Run validator', () => {
it('returns an error', async () => {
const invalidData = {
type: 'INVALID',
scheme: 'sroc'
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(invalidData)
Expand All @@ -106,7 +129,9 @@ describe('Create Bill Run validator', () => {
it('returns an error', async () => {
const invalidData = {
type: 'supplementary',
scheme: 'INVALID'
scheme: 'INVALID',
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(invalidData)
Expand All @@ -120,7 +145,23 @@ describe('Create Bill Run validator', () => {
const invalidData = {
type: 'supplementary',
scheme: 'sroc',
region: 'INVALID'
region: 'INVALID',
user: 'test.user@defra.gov.uk'
}

const result = await CreateBillRunValidator.go(invalidData)

expect(result.error).to.not.be.empty()
})
})

describe('because `user` has an invalid value', () => {
it('returns an error', async () => {
const invalidData = {
type: 'supplementary',
scheme: 'sroc',
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'INVALID'
}

const result = await CreateBillRunValidator.go(invalidData)
Expand Down

0 comments on commit e28666f

Please sign in to comment.