-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display purposes in view licence page summary tab (#682)
* Display purposes in view licence page summary tab https://eaflood.atlassian.net/browse/WATER-4326 Migrating the licence summary page from the water-abstraction-ui to the water-abstraction-system. This ticket is for adding the purposes to the licence summary tab
- Loading branch information
1 parent
1f06915
commit fbf8833
Showing
13 changed files
with
437 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for LicenceVersionPurposes (water.licence_version_purposes) | ||
* @module LicenceVersionPurposes | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class LicenceVersionPurposes extends BaseModel { | ||
static get tableName () { | ||
return 'licenceVersionPurposes' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
licenceVersion: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'licence-version.model', | ||
join: { | ||
from: 'licenceVersionPurposes.licenceVersionId', | ||
to: 'licenceVersions.id' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = LicenceVersionPurposes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
db/migrations/legacy/20240129145658_create-licence-version-purposes-table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
const tableName = 'licence_version_purposes' | ||
|
||
exports.up = function (knex) { | ||
return knex | ||
.schema | ||
.withSchema('water') | ||
.createTable(tableName, (table) => { | ||
// Primary Key | ||
table.uuid('licence_version_purpose_id').primary().defaultTo(knex.raw('gen_random_uuid()')) | ||
|
||
// Data | ||
table.uuid('licence_version_id').notNullable() | ||
table.uuid('purpose_primary_id').notNullable() | ||
table.uuid('purpose_secondary_id').notNullable() | ||
table.uuid('purpose_use_id').notNullable() | ||
table.integer('abstraction_period_start_day').notNullable() | ||
table.integer('abstraction_period_start_month').notNullable() | ||
table.integer('abstraction_period_end_day').notNullable() | ||
table.integer('abstraction_period_end_month').notNullable() | ||
table.date('time_limited_start_date') | ||
table.date('time_limited_end_date') | ||
table.text('notes') | ||
table.decimal('annual_quantity') | ||
table.string('external_id') | ||
table.boolean('is_test') | ||
|
||
// Legacy timestamps | ||
// NOTE: They are not automatically set | ||
table.dateTime('date_created').notNullable() | ||
table.dateTime('date_updated').notNullable() | ||
|
||
// Constraints | ||
table.unique(['external_id'], { useConstraint: true }) | ||
}) | ||
} | ||
|
||
exports.down = function (knex) { | ||
return knex | ||
.schema | ||
.withSchema('water') | ||
.dropTableIfExists(tableName) | ||
} |
36 changes: 36 additions & 0 deletions
36
db/migrations/public/20240129151549_create-licence-version-purposes-view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
|
||
const viewName = 'licence_version_purposes' | ||
|
||
exports.up = function (knex) { | ||
return knex | ||
.schema | ||
.createView(viewName, (view) => { | ||
// NOTE: We have commented out unused columns from the source table | ||
view.as(knex('licence_version_purposes').withSchema('water').select([ | ||
'licence_version_purpose_id AS id', | ||
'licence_version_id', | ||
'purpose_primary_id', | ||
'purpose_secondary_id', | ||
'purpose_use_id AS purpose_id', | ||
'abstraction_period_start_day', | ||
'abstraction_period_start_month', | ||
'abstraction_period_end_day', | ||
'abstraction_period_end_month', | ||
'time_limited_start_date', | ||
'time_limited_end_date', | ||
'notes', | ||
'annual_quantity', | ||
'external_id', | ||
// 'is_test ', | ||
'date_created AS created_at', | ||
'date_updated AS updated_at' | ||
])) | ||
}) | ||
} | ||
|
||
exports.down = function (knex) { | ||
return knex | ||
.schema | ||
.dropViewIfExists(viewName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it, beforeEach } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Test helpers | ||
const DatabaseHelper = require('../support/helpers/database.helper.js') | ||
const LicenceVersionModel = require('../../app/models/licence-version.model.js') | ||
const LicenceVersionHelper = require('../support/helpers/licence-version.helper.js') | ||
const LicenceVersionPurposesHelper = require('../support/helpers/licence-version-purpose.helper.js') | ||
|
||
// Thing under test | ||
const LicenceVersionPurposeModel = require('../../app/models/licence-version-purpose.model.js') | ||
|
||
describe('Licence Version Purposes model', () => { | ||
let testRecord | ||
|
||
beforeEach(async () => { | ||
await DatabaseHelper.clean() | ||
|
||
testRecord = await LicenceVersionPurposesHelper.add() | ||
}) | ||
|
||
describe('Basic query', () => { | ||
it('can successfully run a basic query', async () => { | ||
const result = await LicenceVersionPurposeModel.query().findById(testRecord.id) | ||
|
||
expect(result).to.be.an.instanceOf(LicenceVersionPurposeModel) | ||
expect(result.id).to.equal(testRecord.id) | ||
}) | ||
}) | ||
|
||
describe('Relationships', () => { | ||
describe('when linking to licence version purposes', () => { | ||
let testLicenceVersion | ||
|
||
beforeEach(async () => { | ||
testLicenceVersion = await LicenceVersionHelper.add() | ||
|
||
const { id } = testLicenceVersion | ||
testRecord = await LicenceVersionPurposesHelper.add({ licenceVersionId: id }) | ||
}) | ||
|
||
it('can successfully run a related query', async () => { | ||
const query = await LicenceVersionPurposeModel.query() | ||
.innerJoinRelated('licenceVersion') | ||
|
||
expect(query).to.exist() | ||
}) | ||
|
||
it('can eager load the licence version', async () => { | ||
const result = await LicenceVersionPurposeModel.query() | ||
.findById(testRecord.id) | ||
.withGraphFetched('licenceVersion') | ||
|
||
expect(result).to.be.instanceOf(LicenceVersionPurposeModel) | ||
expect(result.id).to.equal(testRecord.id) | ||
|
||
expect(result.licenceVersion).to.be.an.instanceOf(LicenceVersionModel) | ||
expect(result.licenceVersion.id).to.equal(testLicenceVersion.id) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.