Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the existing purpose condition types to be consistent #1218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading