Skip to content

Commit

Permalink
Refactor the existing purpose condition types to be consistent
Browse files Browse the repository at this point in the history
As part of migrating the import service into the wabs system repo we are adding seeders to the tests which will add what we call reference data the test database.

This is currently running and adding other seeders in the test database.

This change aligns the licence version purpose condition type seeder. Mainly using a data file for us to access this static data in the tests and using the build value string function to build the values to insert into the database.

https://eaflood.atlassian.net/browse/WATER-4535
  • Loading branch information
jonathangoulding committed Jul 31, 2024
1 parent 35816f6 commit 4e95407
Show file tree
Hide file tree
Showing 6 changed files with 587 additions and 81 deletions.
18 changes: 10 additions & 8 deletions test/models/licence-version-purpose-condition-type.model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const LicenceVersionPurposeConditionModel = require('../../app/models/licence-version-purpose-condition.model.js')
const LicenceVersionPurposeConditionHelper = require('../support/helpers/licence-version-purpose-condition.helper.js')
const LicenceVersionPurposeConditionModel = require('../../app/models/licence-version-purpose-condition.model.js')
const LicenceVersionPurposesConditionsTypeSeeder = require('../support/seeders/licence-version-purpose-condition-types.seeder.js')

// Thing under test
const LicenceVersionPurposeConditionTypeModel = require('../../app/models/licence-version-purpose-condition-type.model.js')

describe('Licence Version Purposes model', () => {
const testRecordId = '4eac5d7e-21e4-475c-8108-3e0c2ece181f'
describe('Licence Version Purposes Condition Type model', () => {
const licenceVersionPurposeConditionType = LicenceVersionPurposesConditionsTypeSeeder.data[0]

describe('Basic query', () => {
it('can successfully run a basic query', async () => {
const result = await LicenceVersionPurposeConditionTypeModel.query().findById(testRecordId)
const result = await LicenceVersionPurposeConditionTypeModel
.query().findById(licenceVersionPurposeConditionType.id)

expect(result).to.be.an.instanceOf(LicenceVersionPurposeConditionTypeModel)
expect(result.id).to.equal(testRecordId)
expect(result.id).to.equal(licenceVersionPurposeConditionType.id)
})
})

Expand All @@ -32,7 +34,7 @@ describe('Licence Version Purposes model', () => {

beforeEach(async () => {
testLicenceVersionPurposeCondition = await LicenceVersionPurposeConditionHelper.add({
licenceVersionPurposeConditionTypeId: testRecordId
licenceVersionPurposeConditionTypeId: licenceVersionPurposeConditionType.id
})
})

Expand All @@ -45,11 +47,11 @@ describe('Licence Version Purposes model', () => {

it('can eager load the licence version purpose condition', async () => {
const result = await LicenceVersionPurposeConditionTypeModel.query()
.findById(testRecordId)
.findById(licenceVersionPurposeConditionType.id)
.withGraphFetched('licenceVersionPurposeConditions')

expect(result).to.be.instanceOf(LicenceVersionPurposeConditionTypeModel)
expect(result.id).to.equal(testRecordId)
expect(result.id).to.equal(licenceVersionPurposeConditionType.id)

const foundRecord = result.licenceVersionPurposeConditions.find((record) => {
return record.id === testLicenceVersionPurposeCondition.id
Expand Down
9 changes: 5 additions & 4 deletions test/models/licence-version-purpose-condition.model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const { expect } = Code

// Test helpers
const LicenceVersionPurposeConditionHelper = require('../support/helpers/licence-version-purpose-condition.helper.js')
const LicenceVersionPurposeConditionTypeModel = require('../../app/models/licence-version-purpose-condition-type.model.js')
const LicenceVersionPurposeHelper = require('../support/helpers/licence-version-purpose.helper.js')
const LicenceVersionPurposeModel = require('../../app/models/licence-version-purpose.model.js')
const LicenceVersionPurposeConditionTypeModel = require('../../app/models/licence-version-purpose-condition-type.model.js')
const LicenceVersionPurposesConditionsTypeSeeder = require('../support/seeders/licence-version-purpose-condition-types.seeder.js')

// Thing under test
const LicenceVersionPurposeConditionModel = require('../../app/models/licence-version-purpose-condition.model.js')
Expand Down Expand Up @@ -65,11 +66,11 @@ describe('Licence Version Purpose Condition model', () => {
})

describe('when linking to licence version purpose condition type', () => {
const testLicenceVersionPurposeConditionTypeId = '4eac5d7e-21e4-475c-8108-3e0c2ece181f'
const licenceVersionPurposeConditionType = LicenceVersionPurposesConditionsTypeSeeder.data[0]

beforeEach(async () => {
testRecord = await LicenceVersionPurposeConditionHelper.add({
licenceVersionPurposeConditionTypeId: testLicenceVersionPurposeConditionTypeId
licenceVersionPurposeConditionTypeId: licenceVersionPurposeConditionType.id
})
})

Expand All @@ -89,7 +90,7 @@ describe('Licence Version Purpose Condition model', () => {
expect(result.id).to.equal(testRecord.id)

expect(result.licenceVersionPurposeConditionType).to.be.an.instanceOf(LicenceVersionPurposeConditionTypeModel)
expect(result.licenceVersionPurposeConditionType.id).to.equal(testLicenceVersionPurposeConditionTypeId)
expect(result.licenceVersionPurposeConditionType.id).to.equal(licenceVersionPurposeConditionType.id)
})
})
})
Expand Down
10 changes: 8 additions & 2 deletions test/services/licences/fetch-licence-summary.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const LicenceHolderSeeder = require('../../support/seeders/licence-holder.seeder
const LicenceVersionHelper = require('../../support/helpers/licence-version.helper.js')
const LicenceVersionPurposeConditionHelper = require('../../support/helpers/licence-version-purpose-condition.helper.js')
const LicenceVersionPurposeHelper = require('../../support/helpers/licence-version-purpose.helper.js')
const LicenceVersionPurposesConditionsTypeSeeder = require('../../support/seeders/licence-version-purpose-condition-types.seeder.js')
const PermitLicenceHelper = require('../../support/helpers/permit-licence.helper.js')
const PurposeSeeder = require('../../support/seeders/purposes.seeder.js')
const RegionHelper = require('../../support/helpers/region.helper.js')
Expand All @@ -34,11 +35,16 @@ describe('Fetch Licence Summary service', () => {
let licenceVersion
let licenceVersionPurpose
let licenceVersionPurposeCondition
let licenceVersionPurposeConditionType
let permitLicence
let purpose
let region

beforeEach(async () => {
licenceVersionPurposeConditionType = LicenceVersionPurposesConditionsTypeSeeder.data.find((conditionType) => {
return conditionType.displayTitle === 'Aggregate condition link between licences'
})

region = await RegionHelper.add()

licence = await LicenceHelper.add({
Expand All @@ -64,7 +70,7 @@ describe('Fetch Licence Summary service', () => {

licenceVersionPurposeCondition = await LicenceVersionPurposeConditionHelper.add({
licenceVersionPurposeId: licenceVersionPurpose.id,
licenceVersionPurposeConditionTypeId: '4c0b378d-a9c2-4b50-b1bd-9aeefe988f93'
licenceVersionPurposeConditionTypeId: licenceVersionPurposeConditionType.id
})

licenceHolderSeed = await LicenceHolderSeeder.seed(licence.licenceRef)
Expand Down Expand Up @@ -141,7 +147,7 @@ describe('Fetch Licence Summary service', () => {
licenceVersionPurposeConditions: [{
id: licenceVersionPurposeCondition.id,
licenceVersionPurposeConditionType: {
id: '4c0b378d-a9c2-4b50-b1bd-9aeefe988f93',
id: licenceVersionPurposeConditionType.id,
displayTitle: 'Aggregate condition link between licences'
}
}]
Expand Down
Loading

0 comments on commit 4e95407

Please sign in to comment.