diff --git a/app/presenters/import/legacy/address.presenter.js b/app/presenters/import/legacy/address.presenter.js deleted file mode 100644 index e8d2336188..0000000000 --- a/app/presenters/import/legacy/address.presenter.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD address data to the WRLS format - * @module AddressPresenter - */ - -/** - * Maps the legacy NALD address data to the WRLS format - * - * @param {ImportLegacyAddressType} address - the legacy NALD address - * @param {string} dataSource - * - * @returns {object} the NALD company data transformed into the WRLS format for an address - * ready for validation and persisting - */ -function go(address, dataSource) { - return { - address1: address.address1, - address2: address.address2, - address3: address.address3, - address4: address.address4, - address5: address.address5, - address6: address.address6, - postcode: address.postcode, - country: address.country, - externalId: address.external_id, - dataSource - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/company-address.presenter.js b/app/presenters/import/legacy/company-address.presenter.js deleted file mode 100644 index 38121eb0fa..0000000000 --- a/app/presenters/import/legacy/company-address.presenter.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD data to a company address - * @module CompanyAddressPresenter - */ - -/** - * Maps the legacy NALD data to a company address - * - * @param {ImportLegacyCompanyAddressType} address - the legacy NALD data in company address format - * - * @returns {object} the NALD company address data transformed into the WRLS format for a company address - * ready for validation and persisting - */ -function go(address) { - return { - addressId: address.external_id, - companyId: address.company_external_id, - licenceRoleId: address.licence_role_id, - startDate: address.start_date, - endDate: address.licence_role_name === 'licenceHolder' ? _endDate(address) : address.end_date - } -} - -/** - * Calculate the licence holders company address end date - * - * A licence can have multiple versions, when one licence version ends the other should start. - * - * Unless a licence has not ended then the end date can be null to show it has not ended - * - * A licence can be ended, revoked, lapsed or expired. When this is the case we want to the oldest date of the options. - * - * @param {ImportLegacyCompanyAddressType} address - the legacy NALD address - * - * @returns {date | null} the end date for a licence holder - * @private - */ -function _endDate(address) { - const endDates = [address.end_date, address.lapsed_date, address.expired_date, address.revoked_date].filter( - (endDate) => { - return endDate - } - ) - - const oldestDate = new Date(Math.max(...endDates)) - - return !isNaN(oldestDate) ? oldestDate : null -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/company-contact.presenter.js b/app/presenters/import/legacy/company-contact.presenter.js deleted file mode 100644 index 85322c5c22..0000000000 --- a/app/presenters/import/legacy/company-contact.presenter.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict' - -/** - * Creates a company contact in the WRLS format - * @module CompanyContactPresenter - */ - -/** - * Creates a company contact in the WRLS format - * - * NALD does not have the concept of a 'company contact'. It is a WRLS construct only. - * - * If the NALD party is of type 'PERS', WRLS on import splits it into a 'company' and 'contact' record. The - * 'company-contact' record is the thing that links then together in WRLS. - * - * @param {ImportLegacyContactType} contact - the legacy NALD contact derived from the 'party' - * - * @returns {object} the details needed to persist the company contact in WRLS - */ -function go(contact) { - return { - externalId: contact.external_id, - startDate: contact.start_date, - licenceRoleId: contact.licence_role_id - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/company.presenter.js b/app/presenters/import/legacy/company.presenter.js deleted file mode 100644 index 94f11998cd..0000000000 --- a/app/presenters/import/legacy/company.presenter.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD company data to the WRLS format - * @module CompanyPresenter - */ - -/** - * Maps the legacy NALD company data to the WRLS format - * - * @param {ImportLegacyCompanyType} company - the legacy NALD company - * - * @returns {object} the NALD company data transformed into the WRLS format for a company - * ready for validation and persisting - */ -function go(company) { - return { - name: company.name, - type: company.type, - externalId: company.external_id, - addresses: [], - companyAddresses: [] - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/contact.presenter.js b/app/presenters/import/legacy/contact.presenter.js deleted file mode 100644 index 462142402a..0000000000 --- a/app/presenters/import/legacy/contact.presenter.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD contact data to the WRLS format - * @module ContactPresenter - */ - -/** - * Maps the legacy NALD contact data to the WRLS format - * - * @param {ImportLegacyContactType} contact - the legacy NALD contact - * - * @returns {object} the NALD contact data transformed into the WRLS format for a contact - * ready for validation and persisting - */ -function go(contact) { - return { - externalId: contact.external_id, - salutation: contact.salutation, - initials: contact.initials, - firstName: contact.first_name, - lastName: contact.last_name - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/licence-document-role.presenter.js b/app/presenters/import/legacy/licence-document-role.presenter.js deleted file mode 100644 index c198dad00d..0000000000 --- a/app/presenters/import/legacy/licence-document-role.presenter.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict' - -/** - * Maps legacy NALD licence data to the WRLS licence document role format - * @module LicenceDocumentRolePresenter - */ - -/** - * Maps legacy NALD licence data to the WRLS licence document role format - * - * @param {ImportLegacyLicenceDocumentRoleType} licenceDocumentRole - the legacy NALD licence - * @param {string} licenceRef - the licence ref for the licence document - * - * @returns {object} the NALD licence data transformed into the WRLS licence document role format - * ready for validation and persisting - */ -function go(licenceDocumentRole, licenceRef) { - return { - addressId: licenceDocumentRole.address_id, - companyId: licenceDocumentRole.company_id, - contactId: licenceDocumentRole.contact_id, - documentId: licenceRef, - endDate: licenceDocumentRole.end_date, - licenceRoleId: licenceDocumentRole.licence_role_id, - startDate: licenceDocumentRole.start_date - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/licence-document.presenter.js b/app/presenters/import/legacy/licence-document.presenter.js deleted file mode 100644 index 5c40511bb7..0000000000 --- a/app/presenters/import/legacy/licence-document.presenter.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -/** - * Maps legacy NALD licence data to the WRLS licence document format - * @module LicenceDocumentPresenter - */ - -/** - * Maps legacy NALD licence data to the WRLS licence document format - * - * @param {ImportLegacyLicenceDocumentType} licenceDocument - the legacy NALD licence - * - * @returns {object} the NALD licence data transformed into the WRLS licence document format - * ready for validation and persisting - */ -function go(licenceDocument) { - return { - // Add an empty array property ready for when transforming and attaching licence document roles - licenceDocumentRoles: [], - licenceRef: licenceDocument.licence_ref, - endDate: licenceDocument.end_date, - startDate: licenceDocument.start_date - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/licence-version-purpose-condition.presenter.js b/app/presenters/import/legacy/licence-version-purpose-condition.presenter.js deleted file mode 100644 index 5bc806337a..0000000000 --- a/app/presenters/import/legacy/licence-version-purpose-condition.presenter.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD licence version purpose condition data to the WRLS format - * @module LicenceVersionPurposeConditionPresenter - */ - -/** - * Maps the legacy NALD licence version purpose condition data to the WRLS format - * - * @param {ImportLegacyLicenceVersionPurposeConditionType} licenceVersionPurposeCondition - the legacy NALD - * licence version purpose conditions - * - * @returns {object} the NALD licence version purpose conditions data transformed into the WRLS format ready for - * validation and persisting - */ -function go(licenceVersionPurposeCondition) { - return { - param1: licenceVersionPurposeCondition.param1, - param2: licenceVersionPurposeCondition.param2, - notes: licenceVersionPurposeCondition.notes, - externalId: licenceVersionPurposeCondition.external_id, - licenceVersionPurposeConditionTypeId: licenceVersionPurposeCondition.licence_version_purpose_condition_type_id - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/licence-version-purpose.presenter.js b/app/presenters/import/legacy/licence-version-purpose.presenter.js deleted file mode 100644 index 5f7776062c..0000000000 --- a/app/presenters/import/legacy/licence-version-purpose.presenter.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD licence version purpose data to the WRLS format - * @module LicenceVersionPurposePresenter - */ - -/** - * Maps the legacy NALD licence version purpose data to the WRLS format - * - * @param {ImportLegacyLicenceVersionPurposeType} licenceVersionPurpose - the legacy NALD licence version purpose - * - * @returns {object} the NALD licence version purpose data transformed into the WRLS format ready for validation and - * persisting - */ -function go(licenceVersionPurpose) { - return { - abstractionPeriodEndDay: licenceVersionPurpose.abstraction_period_end_day, - abstractionPeriodEndMonth: licenceVersionPurpose.abstraction_period_end_month, - abstractionPeriodStartDay: licenceVersionPurpose.abstraction_period_start_day, - abstractionPeriodStartMonth: licenceVersionPurpose.abstraction_period_start_month, - annualQuantity: licenceVersionPurpose.annual_quantity, - dailyQuantity: licenceVersionPurpose.daily_quantity, - externalId: licenceVersionPurpose.external_id, - hourlyQuantity: licenceVersionPurpose.hourly_quantity, - instantQuantity: licenceVersionPurpose.instant_quantity, - notes: licenceVersionPurpose.notes, - primaryPurposeId: licenceVersionPurpose.primary_purpose_id, - purposeId: licenceVersionPurpose.purpose_id, - secondaryPurposeId: licenceVersionPurpose.secondary_purpose_id, - timeLimitedEndDate: licenceVersionPurpose.time_limited_end_date, - timeLimitedStartDate: licenceVersionPurpose.time_limited_start_date, - // Add an empty array property ready for when transforming and attaching licence version purpose conditions - licenceVersionPurposeConditions: [] - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/licence-version.presenter.js b/app/presenters/import/legacy/licence-version.presenter.js deleted file mode 100644 index b2f18edbb7..0000000000 --- a/app/presenters/import/legacy/licence-version.presenter.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict' - -/** - * Maps legacy NALD licence version data to the WRLS format - * @module LicenceVersionPresenter - */ - -const NALD_STATUSES = { - CURR: 'current', - SUPER: 'superseded' -} - -/** - * Maps legacy NALD licence version data to the WRLS format - * - * @param {ImportLegacyLicenceVersionTyp} licenceVersion - the legacy NALD licence version - * - * @returns {object} the NALD licence version data transformed into the WRLS format ready for validation and persisting - */ -function go(licenceVersion) { - return { - endDate: licenceVersion.effective_end_date, - externalId: licenceVersion.external_id, - increment: licenceVersion.increment_number, - issue: licenceVersion.issue_no, - // Add an empty array property ready for when transforming and attaching licence version purposes - licenceVersionPurposes: [], - startDate: licenceVersion.effective_start_date, - status: NALD_STATUSES[licenceVersion.status] - } -} - -module.exports = { - go -} diff --git a/app/presenters/import/legacy/licence.presenter.js b/app/presenters/import/legacy/licence.presenter.js deleted file mode 100644 index 6d91611f22..0000000000 --- a/app/presenters/import/legacy/licence.presenter.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict' - -/** - * Maps the legacy NALD licence data to the WRLS format - * @module LicencePresenter - */ - -const { naldRegions } = require('../../../lib/static-lookups.lib.js') - -/** - * Maps the legacy NALD licence data to the WRLS format - * - * @param {ImportLegacyLicenceType} licence - the legacy NALD licence - * - * @returns {object} the NALD licence data transformed into the WRLS format ready for validation and persisting - */ -function go(licence) { - return { - expiredDate: licence.expiry_date, - lapsedDate: licence.lapsed_date, - licenceRef: licence.licence_ref, - // Add an empty array property ready for when transforming and attaching licence versions - licenceVersions: [], - regionId: licence.region_id, - regions: _regions(licence), - revokedDate: licence.revoked_date, - startDate: _startDate(licence), - waterUndertaker: licence.environmental_improvement_unit_charge_code.endsWith('SWC') - } -} - -/** - * Creates a JSON object of the region data. This is stored as a JSON object in the licence.regions column. - * - * @private - */ -const _regions = (licence) => { - const historicalAreaCode = licence.historical_area_code - const regionPrefix = licence.environmental_improvement_unit_charge_code.substr(0, 2) - const regionalChargeArea = naldRegions[regionPrefix] - const standardUnitChargeCode = licence.standard_unit_charge_code - const localEnvironmentAgencyPlanCode = licence.local_environment_agency_plan_code - - return { historicalAreaCode, regionalChargeArea, standardUnitChargeCode, localEnvironmentAgencyPlanCode } -} - -function _startDate(licence) { - if (licence.original_effective_date) { - return licence.original_effective_date - } - - return licence.earliest_version_start_date -} - -module.exports = { - go -} diff --git a/app/services/plugins/hapi-pino-ignore-request.service.js b/app/services/plugins/hapi-pino-ignore-request.service.js index 1f3fe430b2..de241295de 100644 --- a/app/services/plugins/hapi-pino-ignore-request.service.js +++ b/app/services/plugins/hapi-pino-ignore-request.service.js @@ -10,18 +10,6 @@ * * Used by `app/plugins/hapi_pino.plugin.js` to control what does and doesn't get added to our log output. * - * ## import licence endpoint - * - * The import licence endpoint (`/import/licence`) is intended to be used when we switch from importing licences from - * NALD to ReSP. In ReSp we will be 'pinged' when a licence is added or changed. Hence we've built an endpoint we expect - * to be hit sporadically on any given day. - * - * However, until then we are migrating the legacy NALD licence import over bit by bit. It runs through _all_ licences - * each night, which means we are seeing almost 80K entries daily in the logs! - * - * We silence it until we have switched to ReSP else we risk breaking our environments because our logs have eaten up - * all disk space. - * * ## status endpoint * * We built `/status` to support AWS load balancer health checks which fire approximately every 500ms. If we logged @@ -54,7 +42,7 @@ * @returns {boolean} true if the request should be ignored, else false */ function go(options, request) { - const staticPaths = ['/', '/import/licence/legacy', '/status', '/favicon.ico'] + const staticPaths = ['/', '/status', '/favicon.ico'] // If request is a known path ignore it if (staticPaths.includes(request.path)) { diff --git a/app/validators/import/address.validator.js b/app/validators/import/address.validator.js deleted file mode 100644 index 3739ff4f7b..0000000000 --- a/app/validators/import/address.validator.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict' - -/** - * @module ImportAddressValidator - */ - -const Joi = require('joi') - -/** - * Checks that the imported address data has been transformed and is valid for persisting to WRLS - * - * @param {object} address - The transformed address data - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(address) { - const schema = Joi.object({ - address1: Joi.string().required(), - address2: Joi.string().allow(null), - address3: Joi.string().allow(null), - address4: Joi.string().allow(null), - address5: Joi.string().allow(null), - address6: Joi.string().allow(null), - country: Joi.string().allow(null), - externalId: Joi.string().required(), - postcode: Joi.string().allow(null), - dataSource: Joi.string().required() - }) - - const result = schema.validate(address, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/company.validator.js b/app/validators/import/company.validator.js deleted file mode 100644 index 98df1cb22e..0000000000 --- a/app/validators/import/company.validator.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict' - -/** - * @module ImportCompanyValidator - */ - -const Joi = require('joi') - -/** - * Checks that the imported company data has been transformed and is valid for persisting to WRLS - * - * @param {object} company - The transformed company data - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(company) { - const schema = Joi.object({ - name: Joi.string().required(), - type: Joi.string().valid('organisation', 'person').required(), - externalId: Joi.string().required(), - addresses: Joi.array().required(), - companyAddresses: Joi.array().required() - }) - - const result = schema.validate(company, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/contact.validator.js b/app/validators/import/contact.validator.js deleted file mode 100644 index b96faf1a1c..0000000000 --- a/app/validators/import/contact.validator.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict' - -/** - * @module ImportContactValidator - */ - -const Joi = require('joi') - -/** - * Checks that the imported contact data has been transformed and is valid for persisting to WRLS - * - * @param {object} contact - The transformed contact data - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(contact) { - const schema = Joi.object({ - salutation: Joi.string().allow(null), - initials: Joi.string().allow(null), - firstName: Joi.string().allow(null), - lastName: Joi.string().allow(null), - externalId: Joi.string().required() - }) - - const result = schema.validate(contact, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/licence-document-role.validator.js b/app/validators/import/licence-document-role.validator.js deleted file mode 100644 index 476eec5a03..0000000000 --- a/app/validators/import/licence-document-role.validator.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict' - -/** - * @module ImportLicenceDocumentRoleValidator - */ - -const Joi = require('joi') - -/** - * Checks that imported licence data that has been transformed is valid for persisting to WRLS - * as a licence document role - * - * @param {object} licenceDocumentRole - The transformed licence data into a licence document role - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(licenceDocumentRole) { - const schema = Joi.object({ - addressId: Joi.string().required(), - companyId: Joi.string().required(), - contactId: Joi.string().allow(null), - documentId: Joi.string().required(), - endDate: Joi.date().required().allow(null), - licenceRoleId: Joi.string().guid().required(), - startDate: Joi.date().required() - }) - - const result = schema.validate(licenceDocumentRole, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/licence-document.validator.js b/app/validators/import/licence-document.validator.js deleted file mode 100644 index 019658d951..0000000000 --- a/app/validators/import/licence-document.validator.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict' - -/** - * @module ImportLicenceDocumentValidator - */ - -const Joi = require('joi') - -/** - * Checks that imported licence data that has been transformed is valid for persisting to WRLS as a licence document - * - * @param {object} licenceDocument - The transformed licence data into a licence document - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(licenceDocument) { - const schema = Joi.object({ - licenceRef: Joi.string().required(), - endDate: Joi.date().required().allow(null), - startDate: Joi.date().required(), - licenceDocumentRoles: Joi.array().required() - }) - - const result = schema.validate(licenceDocument, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/licence-structure.validator.js b/app/validators/import/licence-structure.validator.js deleted file mode 100644 index 982150209a..0000000000 --- a/app/validators/import/licence-structure.validator.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict' - -/** - * @module ImportLicenceStructureValidator - */ - -const Joi = require('joi') - -/** - * Checks that the transformed licence has a structure valid for persisting to WRLS - * - * The data assigned to the licence object will have already been validated by `ImportLicenceValidator`. This validator - * is ensuring the licence has a valid structure. For example, that it has at least 1 licence version, which in turn has - * at least 1 licence version purpose. - * - * Only if the data against a licence and its child records is valid, and the overall structure of the licence is valid - * should we be attempting to import it. - * - * A valid licence structure is the following. Some properties must contain at least one child object to be valid. Those - * that are optional we leave empty. - * - * ```javascript - * { - * licenceVersions: [{ - * licenceVersionPurposes: [{ - * licenceVersionPurposeConditions: [] - * }] - * }] - * } - * ``` - * - * @param {object} licence - The transformed licence with child records, for example, licence versions - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(licence) { - const schema = Joi.object({ - licenceVersions: Joi.array() - .min(1) - .items( - Joi.object({ - licenceVersionPurposes: Joi.array().min(1) - }).unknown(true) - ) - }).unknown(true) - - const result = schema.validate(licence) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/licence-version-purpose-condition.validator.js b/app/validators/import/licence-version-purpose-condition.validator.js deleted file mode 100644 index 391b8a27a4..0000000000 --- a/app/validators/import/licence-version-purpose-condition.validator.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict' - -/** - * @module LicenceVersionPurposeConditionValidator - */ - -const Joi = require('joi') - -/** - * Checks that the data for inserting/updating the water.licence_version_purpose_conditions table is valid - * - * @param {object} data - The data to be validated - * - * - * @returns {object} the result from calling Joi's schema.validate(). It will be an object with a `value:` property. If - * any errors are found the `error:` property will also exist detailing what the issues were - */ -function go(data) { - const schema = Joi.object({ - licenceVersionPurposeConditionTypeId: Joi.string().guid().required(), - param1: Joi.string().allow(null).optional(), - param2: Joi.string().allow(null).optional(), - notes: Joi.string().allow(null).optional(), - externalId: Joi.string().required() - }) - - const result = schema.validate(data, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/licence-version-purpose.validator.js b/app/validators/import/licence-version-purpose.validator.js deleted file mode 100644 index b4761b24bc..0000000000 --- a/app/validators/import/licence-version-purpose.validator.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict' - -/** - * @module ImportLicenceVersionPurposeValidator - */ - -const Joi = require('joi') - -const MONTHS_IN_YEAR = 12 - -/** - * Checks that imported licence version purpose data that has been transformed is valid for persisting to WRLS - * - * @param {object} licenceVersionPurpose - The transformed licence version purpose data - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(licenceVersionPurpose) { - const schema = Joi.object({ - abstractionPeriodEndDay: _daysInMonthSchema('abstractionPeriodEndMonth'), - abstractionPeriodEndMonth: Joi.number().integer().min(1).max(MONTHS_IN_YEAR).required(), - abstractionPeriodStartDay: _daysInMonthSchema('abstractionPeriodStartMonth'), - abstractionPeriodStartMonth: Joi.number().integer().min(1).max(MONTHS_IN_YEAR).required(), - annualQuantity: Joi.number().allow(null), - dailyQuantity: Joi.number().allow(null), - externalId: Joi.string().required(), - hourlyQuantity: Joi.number().allow(null), - instantQuantity: Joi.number().allow(null), - notes: Joi.string().allow(null), - primaryPurposeId: Joi.string().guid().required(), - purposeId: Joi.string().guid().required(), - secondaryPurposeId: Joi.string().guid().required(), - timeLimitedEndDate: Joi.date().allow(null), - timeLimitedStartDate: Joi.date().allow(null), - licenceVersionPurposeConditions: Joi.array() - }) - - const result = schema.validate(licenceVersionPurpose, { convert: false }) - - if (result.error) { - throw result.error - } -} - -/** - * Allows us to validate that the abstraction period is valid, for example, it is not April 31 or June 31 (those months - * only have 30 days). - * - * Also, we have encountered issues previously where users have entered the end abstraction period as 29 Feb because it - * was a leap year at the time of creation. However, when this data is used in a non-leap year, for example, billing - * it causes the service to error. - * - * It is agreed by the team that administer WRLS that only 28 Feb will ever be used, regardless of leap year. - * - * @private - */ -function _daysInMonthSchema(endMonthProperty) { - return Joi.number().when(endMonthProperty, { - switch: [ - { is: 2, then: Joi.number().integer().min(1).max(28).required() }, - { is: 4, then: Joi.number().integer().min(1).max(30).required() }, - { is: 6, then: Joi.number().integer().min(1).max(30).required() }, - { is: 9, then: Joi.number().integer().min(1).max(30).required() }, - { is: 11, then: Joi.number().integer().min(1).max(30).required() } - ], - otherwise: Joi.number().integer().min(1).max(31).required() - }) -} - -module.exports = { - go -} diff --git a/app/validators/import/licence-version.validator.js b/app/validators/import/licence-version.validator.js deleted file mode 100644 index 9609968b65..0000000000 --- a/app/validators/import/licence-version.validator.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict' - -/** - * @module ImportLicenceVersionValidator - */ - -const Joi = require('joi') - -const WRLS_STATUSES = ['current', 'superseded'] - -/** - * Checks that imported licence version data that has been transformed is valid for persisting to WRLS - * - * @param {object} licenceVersion - The transformed licence version data - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(licenceVersion) { - const schema = Joi.object({ - endDate: Joi.date().required().allow(null), - externalId: Joi.string().required(), - increment: Joi.number().required(), - issue: Joi.number().required(), - licenceVersionPurposes: Joi.array().required(), - startDate: Joi.date().required(), - status: Joi.string() - .required() - .valid(...WRLS_STATUSES) - }) - - const result = schema.validate(licenceVersion, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/app/validators/import/licence.validator.js b/app/validators/import/licence.validator.js deleted file mode 100644 index 973aa3c520..0000000000 --- a/app/validators/import/licence.validator.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict' - -/** - * @module ImportLicenceValidator - */ - -const Joi = require('joi') - -/** - * Checks that imported licence data that has been transformed is valid for persisting to WRLS - * - * @param {object} licence - The transformed licence data - * - * @throws {Joi.ValidationError} - throws a Joi validation error if the validation fails - */ -function go(licence) { - const schema = Joi.object({ - expiredDate: Joi.date().allow(null), - lapsedDate: Joi.date().allow(null), - // NOTE: With the combination of trim() and `convert: false` passed to validate() we ensure that the licence ref - // does not contain any leading or trailing whitespace. It is common for users to accidentally add whitespace in - // NALD.Because of this when the legacy import runs it sees the licence as distinct and so creates a new record. - // This then breaks the service because things like search, find the errant licence record and 'blow up' because the - // licence ref doesn't match validation held in a different part of the service. - // We don't want to make the same mistake with our version. - licenceRef: Joi.string().trim().required(), - licenceVersions: Joi.array().required(), - regionId: Joi.string().guid().required(), - regions: Joi.object({ - regionalChargeArea: Joi.string().required(), - localEnvironmentAgencyPlanCode: Joi.string().required(), - historicalAreaCode: Joi.string().required(), - standardUnitChargeCode: Joi.string().required() - }), - revokedDate: Joi.date().allow(null), - startDate: Joi.date().required(), - waterUndertaker: Joi.boolean().required() - }) - - const result = schema.validate(licence, { convert: false }) - - if (result.error) { - throw result.error - } -} - -module.exports = { - go -} diff --git a/test/presenters/import/legacy/address.presenter.test.js b/test/presenters/import/legacy/address.presenter.test.js deleted file mode 100644 index 665f59e071..0000000000 --- a/test/presenters/import/legacy/address.presenter.test.js +++ /dev/null @@ -1,58 +0,0 @@ -'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 - -// Thing under test -const AddressPresenter = require('../../../../app/presenters/import/legacy/address.presenter.js') - -describe('Import Legacy Address presenter', () => { - let legacyAddress - - const dateSource = 'nald' - - beforeEach(() => { - legacyAddress = _legacyAddress() - }) - - it('correctly transforms the data', () => { - const result = AddressPresenter.go(legacyAddress, dateSource) - - expect(result).to.equal({ - address1: '4 Privet Drive', - address2: null, - address3: null, - address4: null, - address5: 'Little Whinging', - address6: 'Surrey', - country: 'United Kingdom', - externalId: '7:7777', - postcode: 'HP11', - dataSource: 'nald' - }) - }) - - it('correctly sets the data source provided', () => { - const result = AddressPresenter.go(legacyAddress, dateSource) - - expect(result.dataSource).to.equal('nald') - }) -}) - -function _legacyAddress() { - return { - address1: '4 Privet Drive', - address2: null, - address3: null, - address4: null, - address5: 'Little Whinging', - address6: 'Surrey', - postcode: 'HP11', - country: 'United Kingdom', - external_id: '7:7777' - } -} diff --git a/test/presenters/import/legacy/company-address.presenter.test.js b/test/presenters/import/legacy/company-address.presenter.test.js deleted file mode 100644 index 5e362c246c..0000000000 --- a/test/presenters/import/legacy/company-address.presenter.test.js +++ /dev/null @@ -1,136 +0,0 @@ -'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 { generateUUID } = require('../../../../app/lib/general.lib.js') - -// Thing under test -const CompanyAddressPresenter = require('../../../../app/presenters/import/legacy/company-address.presenter.js') - -describe('Import Legacy Company Address presenter', () => { - const licenceRoleId = generateUUID() - - let legacyLicenceHolderAddress - - beforeEach(() => { - legacyLicenceHolderAddress = _legacyLicenceHolderCompanyAddress(licenceRoleId) - }) - - it('correctly transforms the data', () => { - const result = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(result).to.equal({ - addressId: '7:777', - companyId: '1:007', - endDate: null, - licenceRoleId, - startDate: new Date('2020-01-01') - }) - }) - - describe('when the role is licence holder', () => { - describe('and all the dates are null', () => { - it('correctly sets end date to null', () => { - const { endDate } = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(endDate).to.be.null() - }) - }) - - describe('and the end date is a date and the licence dates are null', () => { - beforeEach(() => { - const temp = _legacyLicenceHolderCompanyAddress(licenceRoleId) - - legacyLicenceHolderAddress = { ...temp, end_date: new Date('2022-02-02') } - }) - - it('correctly sets end date to the end date value', () => { - const { endDate } = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(endDate).to.equal(new Date('2022-02-02')) - }) - }) - - describe('and the revoked date is a date and the other dates are null', () => { - beforeEach(() => { - const temp = _legacyLicenceHolderCompanyAddress(licenceRoleId) - - legacyLicenceHolderAddress = { ...temp, revoked_date: new Date('2023-03-03') } - }) - - it('correctly sets end date to the revoked date value', () => { - const { endDate } = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(endDate).to.equal(new Date('2023-03-03')) - }) - }) - - describe('and the expired date is a date and the other dates are null', () => { - beforeEach(() => { - const temp = _legacyLicenceHolderCompanyAddress(licenceRoleId) - - legacyLicenceHolderAddress = { ...temp, expired_date: new Date('2024-04-04') } - }) - - it('correctly sets end date to the expired date value', () => { - const { endDate } = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(endDate).to.equal(new Date('2024-04-04')) - }) - }) - - describe('and the lapsed date is a date and the other dates are null', () => { - beforeEach(() => { - const temp = _legacyLicenceHolderCompanyAddress(licenceRoleId) - - legacyLicenceHolderAddress = { ...temp, lapsed_date: new Date('2025-05-05') } - }) - - it('correctly sets end date to the lapsed date value', () => { - const { endDate } = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(endDate).to.equal(new Date('2025-05-05')) - }) - }) - - describe('and all the dates have values', () => { - beforeEach(() => { - const temp = _legacyLicenceHolderCompanyAddress(licenceRoleId) - - legacyLicenceHolderAddress = { - ...temp, - end_date: new Date('2022-02-02'), - revoked_date: new Date('2023-03-03'), - expired_date: new Date('2024-04-04'), - lapsed_date: new Date('2025-05-05') - } - }) - - it('correctly sets end date latest date of the available dates', () => { - const { endDate } = CompanyAddressPresenter.go(legacyLicenceHolderAddress) - - expect(endDate).to.equal(new Date('2025-05-05')) - }) - }) - }) -}) - -function _legacyLicenceHolderCompanyAddress(licenceRoleId) { - return { - company_external_id: '1:007', - external_id: '7:777', - start_date: new Date('2020-01-01'), - end_date: null, - licence_role_id: licenceRoleId, - revoked_date: null, - expired_date: null, - lapsed_date: null, - licence_role_name: 'licenceHolder' - } -} diff --git a/test/presenters/import/legacy/company-contact.presenter.test.js b/test/presenters/import/legacy/company-contact.presenter.test.js deleted file mode 100644 index f43fc4b5bd..0000000000 --- a/test/presenters/import/legacy/company-contact.presenter.test.js +++ /dev/null @@ -1,45 +0,0 @@ -'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 { generateUUID } = require('../../../../app/lib/general.lib.js') - -// Thing under test -const CompanyContactPresenter = require('../../../../app/presenters/import/legacy/company-contact.presenter.js') - -describe('Import Legacy Company Contact presenter', () => { - let legacyContact - const licenceRoleId = generateUUID() - - beforeEach(() => { - legacyContact = _legacyContact(licenceRoleId) - }) - - it('correctly transforms the data', () => { - const result = CompanyContactPresenter.go(legacyContact) - - expect(result).to.equal({ - startDate: new Date('2020-01-01'), - licenceRoleId, - externalId: '1:007' - }) - }) -}) - -function _legacyContact(licenceRoleId) { - return { - salutation: 'Mr', - initials: 'H', - first_name: 'James', - last_name: 'Bond', - external_id: '1:007', - start_date: new Date('2020-01-01'), - licence_role_id: licenceRoleId - } -} diff --git a/test/presenters/import/legacy/company.presenter.test.js b/test/presenters/import/legacy/company.presenter.test.js deleted file mode 100644 index ae8b9790fb..0000000000 --- a/test/presenters/import/legacy/company.presenter.test.js +++ /dev/null @@ -1,39 +0,0 @@ -'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 - -// Thing under test -const CompanyPresenter = require('../../../../app/presenters/import/legacy/company.presenter.js') - -describe('Import Legacy Company presenter', () => { - let legacyCompany - - beforeEach(() => { - legacyCompany = _legacyCompany() - }) - - it('correctly transforms the data', () => { - const result = CompanyPresenter.go(legacyCompany) - - expect(result).to.equal({ - externalId: '1:1940', - name: 'ACME', - type: 'organisation', - addresses: [], - companyAddresses: [] - }) - }) -}) - -function _legacyCompany() { - return { - name: 'ACME', - type: 'organisation', - external_id: '1:1940' - } -} diff --git a/test/presenters/import/legacy/contact.presenter.test.js b/test/presenters/import/legacy/contact.presenter.test.js deleted file mode 100644 index 7523505e4d..0000000000 --- a/test/presenters/import/legacy/contact.presenter.test.js +++ /dev/null @@ -1,41 +0,0 @@ -'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 - -// Thing under test -const ContactPresenter = require('../../../../app/presenters/import/legacy/contact.presenter.js') - -describe('Import Legacy Contact presenter', () => { - let legacyContact - - beforeEach(() => { - legacyContact = _legacyContact() - }) - - it('correctly transforms the data', () => { - const result = ContactPresenter.go(legacyContact) - - expect(result).to.equal({ - salutation: 'Mr', - initials: 'H', - firstName: 'James', - lastName: 'Bond', - externalId: '1:007' - }) - }) -}) - -function _legacyContact() { - return { - salutation: 'Mr', - initials: 'H', - first_name: 'James', - last_name: 'Bond', - external_id: '1:007' - } -} diff --git a/test/presenters/import/legacy/licence-document-role.presenter.test.js b/test/presenters/import/legacy/licence-document-role.presenter.test.js deleted file mode 100644 index 8222af842a..0000000000 --- a/test/presenters/import/legacy/licence-document-role.presenter.test.js +++ /dev/null @@ -1,59 +0,0 @@ -'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 { generateLicenceRef } = require('../../../support/helpers/licence.helper.js') -const { generateUUID } = require('../../../../app/lib/general.lib.js') - -// Thing under test -const LicenceDocumentRolePresenter = require('../../../../app/presenters/import/legacy/licence-document-role.presenter.js') - -describe('Import Legacy Licence Document role presenter', () => { - let legacyLicenceDocumentRole - let licenceRef - let licenceRoleId - - beforeEach(() => { - licenceRef = generateLicenceRef() - licenceRoleId = generateUUID() - - legacyLicenceDocumentRole = _legacyLicenceDocumentRole(licenceRef, licenceRoleId) - }) - - it('correctly transforms the data', () => { - const result = LicenceDocumentRolePresenter.go(legacyLicenceDocumentRole, licenceRef) - - expect(result).to.equal({ - addressId: '1:007', - companyId: '1:007', - contactId: '1:008', - documentId: licenceRef, - licenceRoleId, - endDate: null, - startDate: new Date('1999-01-01') - }) - }) - - it('correctly sets the "documentId" as the licence ref', () => { - const result = LicenceDocumentRolePresenter.go(legacyLicenceDocumentRole, licenceRef) - - expect(result.documentId).to.equal(licenceRef) - }) -}) - -function _legacyLicenceDocumentRole(licenceRef, licenceRoleId) { - return { - address_id: '1:007', - company_id: '1:007', - contact_id: '1:008', - end_date: null, - start_date: new Date('1999-01-01'), - licence_role_id: licenceRoleId - } -} diff --git a/test/presenters/import/legacy/licence-document.presenter.test.js b/test/presenters/import/legacy/licence-document.presenter.test.js deleted file mode 100644 index eb4fd07429..0000000000 --- a/test/presenters/import/legacy/licence-document.presenter.test.js +++ /dev/null @@ -1,44 +0,0 @@ -'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 { generateLicenceRef } = require('../../../support/helpers/licence.helper.js') - -// Thing under test -const LicenceDocumentPresenter = require('../../../../app/presenters/import/legacy/licence-document.presenter.js') - -describe('Import Legacy Licence Document presenter', () => { - let legacyLicenceDocument - let licenceRef - - beforeEach(() => { - licenceRef = generateLicenceRef() - - legacyLicenceDocument = _legacyLicenceDocument(licenceRef) - }) - - it('correctly transforms the data', () => { - const result = LicenceDocumentPresenter.go(legacyLicenceDocument) - - expect(result).to.equal({ - licenceRef, - endDate: null, - licenceDocumentRoles: [], - startDate: new Date('1999-01-01') - }) - }) -}) - -function _legacyLicenceDocument(licenceRef) { - return { - end_date: null, - start_date: new Date('1999-01-01'), - licence_ref: licenceRef - } -} diff --git a/test/presenters/import/legacy/licence-version-purpose-condition.presenter.test.js b/test/presenters/import/legacy/licence-version-purpose-condition.presenter.test.js deleted file mode 100644 index 6e1ea642bb..0000000000 --- a/test/presenters/import/legacy/licence-version-purpose-condition.presenter.test.js +++ /dev/null @@ -1,41 +0,0 @@ -'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 - -// Thing under test -const LicenceVersionPurposeConditionsPresenter = require('../../../../app/presenters/import/legacy/licence-version-purpose-condition.presenter.js') - -describe('Import Legacy Licence Version Purpose Conditions presenter', () => { - let legacyLicenceVersionPurposeCondition - - beforeEach(() => { - legacyLicenceVersionPurposeCondition = _legacyLicenceVersionPurposeCondition() - }) - - it('correctly transforms the data', () => { - const results = LicenceVersionPurposeConditionsPresenter.go(legacyLicenceVersionPurposeCondition) - - expect(results).to.equal({ - externalId: '172640:6:10000004', - licenceVersionPurposeConditionTypeId: 'b10cc9d1-d46f-465d-a74a-26b2e567c699', - notes: 'At each abstraction borehole', - param1: null, - param2: null - }) - }) -}) - -function _legacyLicenceVersionPurposeCondition() { - return { - external_id: '172640:6:10000004', - licence_version_purpose_condition_type_id: 'b10cc9d1-d46f-465d-a74a-26b2e567c699', - notes: 'At each abstraction borehole', - param1: null, - param2: null - } -} diff --git a/test/presenters/import/legacy/licence-version-purpose.presenter.test.js b/test/presenters/import/legacy/licence-version-purpose.presenter.test.js deleted file mode 100644 index 1052234581..0000000000 --- a/test/presenters/import/legacy/licence-version-purpose.presenter.test.js +++ /dev/null @@ -1,63 +0,0 @@ -'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 - -// Thing under test -const LicenceVersionPurposePresenter = require('../../../../app/presenters/import/legacy/licence-version-purpose.presenter.js') - -describe('Import Legacy Licence Version Purpose presenter', () => { - let legacyLicenceVersionPurpose - - beforeEach(() => { - legacyLicenceVersionPurpose = _legacyLicenceVersionPurpose() - }) - - it('correctly transforms the data', () => { - const results = LicenceVersionPurposePresenter.go(legacyLicenceVersionPurpose) - - expect(results).to.equal({ - abstractionPeriodEndDay: 31, - abstractionPeriodEndMonth: 3, - abstractionPeriodStartDay: 1, - abstractionPeriodStartMonth: 4, - annualQuantity: 545520, - dailyQuantity: 1500.2, - externalId: '6:10000004', - hourlyQuantity: 140.929, - instantQuantity: null, - licenceVersionPurposeConditions: [], - notes: null, - primaryPurposeId: '8d9d407c-3da7-4977-84a0-97738c9b44cc', - purposeId: '025bfdc9-d7f4-46b5-a7e0-451dec1a34a6', - secondaryPurposeId: '04bdc9f6-a4e7-41de-831c-9ebf15b92782', - timeLimitedEndDate: null, - timeLimitedStartDate: null - }) - }) -}) - -function _legacyLicenceVersionPurpose() { - return { - abstraction_period_end_day: 31, - abstraction_period_end_month: 3, - abstraction_period_start_day: 1, - abstraction_period_start_month: 4, - annual_quantity: 545520, - daily_quantity: 1500.2, - external_id: '6:10000004', - hourly_quantity: 140.929, - instant_quantity: null, - notes: null, - primary_purpose_id: '8d9d407c-3da7-4977-84a0-97738c9b44cc', - purpose_id: '025bfdc9-d7f4-46b5-a7e0-451dec1a34a6', - secondary_purpose_id: '04bdc9f6-a4e7-41de-831c-9ebf15b92782', - time_limited_end_date: null, - time_limited_start_date: null, - version_external_id: '6:2113:100:0' - } -} diff --git a/test/presenters/import/legacy/licence-version.presenter.test.js b/test/presenters/import/legacy/licence-version.presenter.test.js deleted file mode 100644 index 56325a2945..0000000000 --- a/test/presenters/import/legacy/licence-version.presenter.test.js +++ /dev/null @@ -1,66 +0,0 @@ -'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 - -// Thing under test -const LicenceVersionPresenter = require('../../../../app/presenters/import/legacy/licence-version.presenter.js') - -describe('Import Legacy Licence Version presenter', () => { - let legacyLicenceVersion - - beforeEach(() => { - legacyLicenceVersion = _legacyLicenceVersion() - }) - - it('correctly transforms the data', () => { - const result = LicenceVersionPresenter.go(legacyLicenceVersion) - - expect(result).to.equal({ - endDate: null, - externalId: '6:2113:100:0', - increment: 0, - issue: 100, - licenceVersionPurposes: [], - startDate: new Date('1999-01-01'), - status: 'current' - }) - }) - - describe('the "status" property', () => { - describe('when the legacy licence version status is "CURR"', () => { - it('returns "current"', () => { - const result = LicenceVersionPresenter.go(legacyLicenceVersion) - - expect(result.status).to.equal('current') - }) - }) - - describe('when the legacy licence version status is "SUPER"', () => { - beforeEach(() => { - legacyLicenceVersion.status = 'SUPER' - }) - - it('returns "superseded"', () => { - const result = LicenceVersionPresenter.go(legacyLicenceVersion) - - expect(result.status).to.equal('superseded') - }) - }) - }) -}) - -function _legacyLicenceVersion() { - return { - effective_end_date: null, - effective_start_date: new Date('1999-01-01'), - external_id: '6:2113:100:0', - increment_number: 0, - issue_no: 100, - status: 'CURR' - } -} diff --git a/test/presenters/import/legacy/licence.presenter.test.js b/test/presenters/import/legacy/licence.presenter.test.js deleted file mode 100644 index bda715f060..0000000000 --- a/test/presenters/import/legacy/licence.presenter.test.js +++ /dev/null @@ -1,122 +0,0 @@ -'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 { generateLicenceRef } = require('../../../support/helpers/licence.helper.js') - -// Thing under test -const LicencePresenter = require('../../../../app/presenters/import/legacy/licence.presenter.js') - -describe('Import Legacy Licence presenter', () => { - let legacyLicence - - beforeEach(() => { - legacyLicence = _legacyLicence() - }) - - it('correctly transforms the data', () => { - const result = LicencePresenter.go(legacyLicence) - - expect(result).to.equal({ - expiredDate: null, - lapsedDate: null, - licenceRef: legacyLicence.licence_ref, - licenceVersions: [], - regionId: '82d8c1b7-0eed-43a7-a5f9-4e397c08e17e', - regions: { - historicalAreaCode: 'KAEA', - regionalChargeArea: 'Southern', - standardUnitChargeCode: 'SUCSO', - localEnvironmentAgencyPlanCode: 'LEME' - }, - revokedDate: null, - startDate: new Date('1992-08-19'), - waterUndertaker: false - }) - }) - - describe('the "regions" property', () => { - beforeEach(() => { - legacyLicence.environmental_improvement_unit_charge_code = 'YOOTH' - }) - - it('returns a JSON object where the "regionalChargeArea" is based on the first 2 chars of the EIUC code', () => { - const result = LicencePresenter.go(legacyLicence) - - expect(result.regions).to.equal({ - historicalAreaCode: 'KAEA', - regionalChargeArea: 'Yorkshire', - standardUnitChargeCode: 'SUCSO', - localEnvironmentAgencyPlanCode: 'LEME' - }) - }) - }) - - describe('the "startDate" property', () => { - describe('when "original_effective_date" is populated in the licence data', () => { - it('returns "original_effective_date" as the "startDate"', () => { - const result = LicencePresenter.go(legacyLicence) - - expect(result.startDate).to.equal(legacyLicence.original_effective_date) - }) - }) - - describe('when "original_effective_date" is not populated in the licence data', () => { - beforeEach(() => { - legacyLicence.original_effective_date = null - }) - - it('returns "earliest_version_start_date" as the "startDate"', () => { - const result = LicencePresenter.go(legacyLicence) - - expect(result.startDate).to.equal(legacyLicence.earliest_version_start_date) - }) - }) - }) - - describe('the "waterUndertaker" property', () => { - describe('when the "environmental_improvement_unit_charge_code" does not end with SWC', () => { - it('returns false', () => { - const result = LicencePresenter.go(legacyLicence) - - expect(result.waterUndertaker).to.be.false() - }) - }) - - describe('when the "environmental_improvement_unit_charge_code" ends with SWC', () => { - beforeEach(() => { - legacyLicence.environmental_improvement_unit_charge_code = 'SOSWC' - }) - - it('returns true', () => { - const result = LicencePresenter.go(legacyLicence) - - expect(result.waterUndertaker).to.be.true() - }) - }) - }) -}) - -function _legacyLicence() { - return { - historical_area_code: 'KAEA', - environmental_improvement_unit_charge_code: 'SOOTH', - local_environment_agency_plan_code: 'LEME', - standard_unit_charge_code: 'SUCSO', - expiry_date: null, - region_code: '6', - id: '2113', - lapsed_date: null, - licence_ref: generateLicenceRef(), - original_effective_date: new Date('1992-08-19'), - revoked_date: null, - earliest_version_start_date: new Date('1999-01-01'), - region_id: '82d8c1b7-0eed-43a7-a5f9-4e397c08e17e' - } -} diff --git a/test/services/plugins/hapi-pino-ignore-request.service.test.js b/test/services/plugins/hapi-pino-ignore-request.service.test.js index 8300fed5fe..d4b7f9b464 100644 --- a/test/services/plugins/hapi-pino-ignore-request.service.test.js +++ b/test/services/plugins/hapi-pino-ignore-request.service.test.js @@ -27,14 +27,6 @@ describe('Hapi Pino Ignore Request service', () => { }) }) - describe('when the request is for "/import/licence/legacy"', () => { - it('returns true', () => { - const result = HapiPinoIgnoreRequestService.go({ logAssetRequests: false }, { path: '/import/licence/legacy' }) - - expect(result).to.be.true() - }) - }) - describe('when the request is for an asset', () => { describe('and LOG_ASSET_REQUESTS is false', () => { it('returns true', () => { diff --git a/test/validators/import/address.validator.test.js b/test/validators/import/address.validator.test.js deleted file mode 100644 index f7b4afdd70..0000000000 --- a/test/validators/import/address.validator.test.js +++ /dev/null @@ -1,302 +0,0 @@ -'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 - -// Thing under test -const ImportAddressValidator = require('../../../app/validators/import/address.validator.js') - -describe('Import Address validator', () => { - let transformedAddress - - beforeEach(async () => { - transformedAddress = _transformedAddress() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - - describe('the "address1" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.address1 = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address1" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.address1 = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address1" must be a string') - }) - }) - }) - - describe('the "address2" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.address2 = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address2" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.address2 = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "address3" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.address3 = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address3" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.address3 = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "address4" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.address4 = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address4" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.address4 = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "address5" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.address5 = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address5" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.address5 = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "address6" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.address6 = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"address6" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.address6 = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "country" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.country = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"country" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.country = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "postcode" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.postcode = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"postcode" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.postcode = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.not.throw() - }) - }) - }) - - describe('the "dataSource" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.dataSource = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"dataSource" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.dataSource = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"dataSource" must be a string') - }) - }) - }) - - describe('the "externalId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedAddress.externalId = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"externalId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedAddress.externalId = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportAddressValidator.go(transformedAddress) - }).to.throw('"externalId" must be a string') - }) - }) - }) -}) - -function _transformedAddress() { - return { - address1: '4 Privet Drive', - address2: null, - address3: null, - address4: null, - address5: 'Little Whinging', - address6: 'Surrey', - country: 'United Kingdom', - externalId: '7:7777', - postcode: 'HP11', - dataSource: 'nald' - } -} diff --git a/test/validators/import/company.validator.test.js b/test/validators/import/company.validator.test.js deleted file mode 100644 index 10f5802d75..0000000000 --- a/test/validators/import/company.validator.test.js +++ /dev/null @@ -1,177 +0,0 @@ -'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 - -// Thing under test -const ImportCompanyValidator = require('../../../app/validators/import/company.validator.js') - -describe('Import Company validator', () => { - let transformedCompany - - beforeEach(async () => { - transformedCompany = _transformedCompany() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.not.throw() - }) - }) - - describe('the "name" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedCompany.name = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"name" must be a string') - }) - }) - - describe('when it is not present', () => { - beforeEach(() => { - delete transformedCompany.name - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"name" is required') - }) - }) - }) - - describe('the "type" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedCompany.type = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"type" must be one of [organisation, person]') - }) - }) - - describe('when it is not a valid string - organisation or person', () => { - beforeEach(() => { - transformedCompany.type = 'org' - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"type" must be one of [organisation, person]') - }) - }) - - describe('when it is not present', () => { - beforeEach(() => { - delete transformedCompany.type - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"type" is required') - }) - }) - }) - - describe('the "externalId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedCompany.externalId = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"externalId" must be a string') - }) - }) - - describe('when it is not present', () => { - beforeEach(() => { - delete transformedCompany.externalId - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"externalId" is required') - }) - }) - }) - - describe('the "addresses" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedCompany.addresses = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"addresses" must be an array') - }) - }) - describe('when it is not set', () => { - beforeEach(() => { - delete transformedCompany.addresses - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"addresses" is required') - }) - }) - }) - - describe('the "companyAddresses" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedCompany.companyAddresses = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"companyAddresses" must be an array') - }) - }) - describe('when it is not set', () => { - beforeEach(() => { - delete transformedCompany.companyAddresses - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyValidator.go(transformedCompany) - }).to.throw('"companyAddresses" is required') - }) - }) - }) -}) - -function _transformedCompany() { - return { - name: 'ACME', - type: 'person', - externalId: '1:1940', - addresses: [], - companyAddresses: [] - } -} diff --git a/test/validators/import/contact.validator.test.js b/test/validators/import/contact.validator.test.js deleted file mode 100644 index 363d17b072..0000000000 --- a/test/validators/import/contact.validator.test.js +++ /dev/null @@ -1,167 +0,0 @@ -'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 - -// Thing under test -const ImportCompanyContactValidator = require('../../../app/validators/import/contact.validator.js') - -describe('Import Contact validator', () => { - let transformedContact - - beforeEach(async () => { - transformedContact = _transformedContact() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.not.throw() - }) - }) - - describe('the "salutation" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedContact.salutation = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.throw('"salutation" must be a string') - }) - }) - - describe('when it null', () => { - beforeEach(() => { - transformedContact.salutation = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.not.throw() - }) - }) - }) - - describe('the "initials" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedContact.initials = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.throw('"initials" must be a string') - }) - }) - - describe('when it null', () => { - beforeEach(() => { - transformedContact.initials = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.not.throw() - }) - }) - }) - - describe('the "firstName" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedContact.firstName = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.throw('"firstName" must be a string') - }) - }) - - describe('when it null', () => { - beforeEach(() => { - transformedContact.firstName = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.not.throw() - }) - }) - }) - - describe('the "lastName" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedContact.lastName = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.throw('"lastName" must be a string') - }) - }) - - describe('when it null', () => { - beforeEach(() => { - transformedContact.lastName = null - }) - - it('does not throw an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.not.throw() - }) - }) - }) - - describe('the "externalId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedContact.externalId = 1 - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.throw('"externalId" must be a string') - }) - }) - - describe('when it is not present', () => { - beforeEach(() => { - delete transformedContact.externalId - }) - - it('throws an error', async () => { - expect(() => { - ImportCompanyContactValidator.go(transformedContact) - }).to.throw('"externalId" is required') - }) - }) - }) -}) - -function _transformedContact() { - return { - salutation: 'Mr', - initials: 'H', - firstName: 'James', - lastName: 'Bond', - externalId: '1:1940' - } -} diff --git a/test/validators/import/licence-document-role.validator.test.js b/test/validators/import/licence-document-role.validator.test.js deleted file mode 100644 index a86b0ea3fe..0000000000 --- a/test/validators/import/licence-document-role.validator.test.js +++ /dev/null @@ -1,261 +0,0 @@ -'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 { generateLicenceRef } = require('../../support/helpers/licence.helper.js') -const { generateUUID } = require('../../../app/lib/general.lib.js') - -// Thing under test -const LicenceDocumentRoleValidator = require('../../../app/validators/import/licence-document-role.validator.js') - -describe('Import Licence Document role validator', () => { - let transformedLicenceDocumentRole - - beforeEach(async () => { - transformedLicenceDocumentRole = _transformedLicenceDocumentRoleRole() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.not.throw() - }) - }) - - describe('the "addressId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceDocumentRole.addressId = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"addressId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.addressId = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"addressId" must be a string') - }) - }) - - describe('when it does not exist', () => { - beforeEach(() => { - delete transformedLicenceDocumentRole.addressId - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"addressId" is required') - }) - }) - }) - - describe('the "companyId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceDocumentRole.companyId = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"companyId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.companyId = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"companyId" must be a string') - }) - }) - - describe('when it does not exist', () => { - beforeEach(() => { - delete transformedLicenceDocumentRole.companyId - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"companyId" is required') - }) - }) - }) - - describe('the "contactId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceDocumentRole.contactId = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"contactId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.contactId = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.not.throw() - }) - }) - - describe('when it does not exist', () => { - beforeEach(() => { - delete transformedLicenceDocumentRole.contactId - }) - - it('does not throw an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.not.throw() - }) - }) - }) - - describe('the "documentId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceDocumentRole.documentId = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"documentId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.documentId = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"documentId" must be a string') - }) - }) - }) - - describe('the "licenceRoleId" property', () => { - describe('when it is not a guid', () => { - beforeEach(() => { - transformedLicenceDocumentRole.licenceRoleId = '123' - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"licenceRoleId" must be a valid GUID') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.licenceRoleId = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"licenceRoleId" must be a string') - }) - }) - }) - - describe('the "endDate" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicenceDocumentRole.endDate = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"endDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.endDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).not.to.throw() - }) - }) - }) - - describe('the "startDate" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicenceDocumentRole.startDate = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"startDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocumentRole.startDate = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) - }).to.throw('"startDate" must be a valid date') - }) - }) - }) -}) - -function _transformedLicenceDocumentRoleRole() { - return { - addressId: '1:007', - companyId: '1:007', - contactId: '1:008', - documentId: generateLicenceRef(), - licenceRoleId: generateUUID(), - endDate: null, - startDate: new Date('1999-01-01') - } -} diff --git a/test/validators/import/licence-document.validator.test.js b/test/validators/import/licence-document.validator.test.js deleted file mode 100644 index 63b6f88a33..0000000000 --- a/test/validators/import/licence-document.validator.test.js +++ /dev/null @@ -1,143 +0,0 @@ -'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 { generateLicenceRef } = require('../../support/helpers/licence.helper.js') - -// Thing under test -const LicenceDocumentValidator = require('../../../app/validators/import/licence-document.validator.js') - -describe('Import Licence Document validator', () => { - let transformedLicenceDocument - - beforeEach(async () => { - transformedLicenceDocument = _transformedLicenceDocument() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.not.throw() - }) - }) - - describe('the "licenceRef" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicenceDocument.licenceRef = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"licenceRef" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocument.licenceRef = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"licenceRef" must be a string') - }) - }) - }) - - describe('the "endDate" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicenceDocument.endDate = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"endDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocument.endDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).not.to.throw() - }) - }) - }) - - describe('the "startDate" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicenceDocument.startDate = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"startDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocument.startDate = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"startDate" must be a valid date') - }) - }) - }) - - describe('the "licenceDocumentRoles" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedLicenceDocument.licenceDocumentRoles = 1 - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"licenceDocumentRoles" must be an array') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceDocument.licenceDocumentRoles = null - }) - - it('throws an error', () => { - expect(() => { - LicenceDocumentValidator.go(transformedLicenceDocument) - }).to.throw('"licenceDocumentRoles" must be an array') - }) - }) - }) -}) - -function _transformedLicenceDocument() { - return { - licenceRef: generateLicenceRef(), - endDate: new Date('2052-06-23'), - startDate: new Date('1992-08-19'), - licenceDocumentRoles: [] - } -} diff --git a/test/validators/import/licence-structure.validator.test.js b/test/validators/import/licence-structure.validator.test.js deleted file mode 100644 index bb711f2e35..0000000000 --- a/test/validators/import/licence-structure.validator.test.js +++ /dev/null @@ -1,122 +0,0 @@ -'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 - -// Thing under test -const LicenceStructureValidator = require('../../../app/validators/import/licence-structure.validator.js') - -describe('Import Licence Structure validator', () => { - let transformedLicence - - beforeEach(() => { - transformedLicence = _transformedLicence() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.not.throw() - }) - }) - - describe('the "licenceVersions" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedLicence.licenceVersions = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.throw('"licenceVersions" must be an array') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.licenceVersions = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.throw('"licenceVersions" must be an array') - }) - }) - - describe('when it is empty', () => { - beforeEach(() => { - transformedLicence.licenceVersions = [] - }) - - it('throws an error', async () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.throw('"licenceVersions" must contain at least 1 items') - }) - }) - - describe('and its "licenceVersionPurposes" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedLicence.licenceVersions[0].licenceVersionPurposes = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.throw('"licenceVersions[0].licenceVersionPurposes" must be an array') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.licenceVersions[0].licenceVersionPurposes = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.throw('"licenceVersions[0].licenceVersionPurposes" must be an array') - }) - }) - - describe('when it is empty', () => { - beforeEach(() => { - transformedLicence.licenceVersions[0].licenceVersionPurposes = [] - }) - - it('throws an error', async () => { - expect(() => { - LicenceStructureValidator.go(transformedLicence) - }).to.throw('"licenceVersions[0].licenceVersionPurposes" must contain at least 1 items') - }) - }) - }) - }) -}) - -function _transformedLicence() { - return { - licenceRef: '01/123', - licenceVersions: [ - { - externalId: '6:2113:100:0', - licenceVersionPurposes: [ - { - externalId: '6:10000004' - }, - { - externalId: '6:10000005' - } - ] - } - ] - } -} diff --git a/test/validators/import/licence-version-purpose-conditions.validator.test.js b/test/validators/import/licence-version-purpose-conditions.validator.test.js deleted file mode 100644 index 5dcb335279..0000000000 --- a/test/validators/import/licence-version-purpose-conditions.validator.test.js +++ /dev/null @@ -1,176 +0,0 @@ -'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 - -// Thing under test -const LicenceVersionPurposeConditionsValidator = require('../../../app/validators/import/licence-version-purpose-condition.validator.js') - -describe('Import Licence Version Purpose Conditions validator', () => { - let transformedLicenceVersionPurposeCondition - - beforeEach(async () => { - transformedLicenceVersionPurposeCondition = _licenceVersionPurposeConditionsValidatorCondition() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.not.throw() - }) - }) - - describe('the "licenceVersionPurposeConditionTypeId" property', () => { - describe('when it is not on the object', () => { - beforeEach(() => { - delete transformedLicenceVersionPurposeCondition.licenceVersionPurposeConditionTypeId - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"licenceVersionPurposeConditionTypeId" is required') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.licenceVersionPurposeConditionTypeId = null - }) - - it('throws an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"licenceVersionPurposeConditionTypeId" must be a string') - }) - }) - - describe('when it is not a guid', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.licenceVersionPurposeConditionTypeId = '123' - }) - - it('throws an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"licenceVersionPurposeConditionTypeId" must be a valid GUID') - }) - }) - }) - - describe('the "param1" property', () => { - describe('when it is a number', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.param1 = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"param1" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.param1 = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.not.throw() - }) - }) - }) - - describe('the "param2" property', () => { - describe('when it is a number', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.param2 = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"param2" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.param2 = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.not.throw() - }) - }) - }) - - describe('the "notes" property', () => { - describe('when it is a number', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.notes = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"notes" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.notes = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.not.throw() - }) - }) - }) - - describe('the "externalId" property', () => { - describe('when it is not on the object', () => { - beforeEach(() => { - delete transformedLicenceVersionPurposeCondition.externalId - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"externalId" is required') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurposeCondition.externalId = null - }) - - it('throws an error', () => { - expect(() => { - LicenceVersionPurposeConditionsValidator.go(transformedLicenceVersionPurposeCondition) - }).to.throw('"externalId" must be a string') - }) - }) - }) -}) - -function _licenceVersionPurposeConditionsValidatorCondition() { - return { - externalId: '6:100004', - licenceVersionPurposeConditionTypeId: 'b10cc9d1-d46f-465d-a74a-26b2e567c699' - } -} diff --git a/test/validators/import/licence-version-purpose.validator.test.js b/test/validators/import/licence-version-purpose.validator.test.js deleted file mode 100644 index 44cd324a80..0000000000 --- a/test/validators/import/licence-version-purpose.validator.test.js +++ /dev/null @@ -1,639 +0,0 @@ -'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 - -// Thing under test -const LicenceVersionPurposeValidator = require('../../../app/validators/import/licence-version-purpose.validator.js') - -describe('Import Licence Version Purpose validator', () => { - let transformedLicenceVersionPurpose - - beforeEach(async () => { - transformedLicenceVersionPurpose = _transformedLicenceVersionPurpose() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - - describe('the "abstractionPeriodEndDay" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndDay = '31a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndDay" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndDay = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndDay" must be a number') - }) - }) - - describe('when it is less than the minimum (1)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndDay = 0 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndDay" must be greater than or equal to 1') - }) - }) - - describe('when "abstractionPeriodEndMonth"', () => { - describe('is February (2)', () => { - describe('and "abstractionPeriodEndDay" is more than the number of days in the month (29)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = 2 - transformedLicenceVersionPurpose.abstractionPeriodEndDay = 29 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndDay" must be less than or equal to 28') - }) - }) - }) - - describe('is April (4)', () => { - describe('and "abstractionPeriodEndDay" is more than the number of days in the month (30)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = 4 - transformedLicenceVersionPurpose.abstractionPeriodEndDay = 31 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndDay" must be less than or equal to 30') - }) - }) - }) - - describe('is March (3)', () => { - describe('and "abstractionPeriodEndDay" is more than the number of days in the month (31)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = 3 - transformedLicenceVersionPurpose.abstractionPeriodEndDay = 32 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndDay" must be less than or equal to 31') - }) - }) - }) - }) - }) - - describe('the "abstractionPeriodEndMonth" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = '12a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndMonth" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndMonth" must be a number') - }) - }) - - describe('when it is less than the minimum (1)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = 0 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndMonth" must be greater than or equal to 1') - }) - }) - - describe('when it is more than the maximum (12)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodEndMonth = 13 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodEndMonth" must be less than or equal to 12') - }) - }) - }) - - describe('the "abstractionPeriodStartDay" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartDay = '31a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartDay" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartDay = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartDay" must be a number') - }) - }) - - describe('when it is less than the minimum (1)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartDay = 0 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartDay" must be greater than or equal to 1') - }) - }) - - describe('when "abstractionPeriodStartMonth"', () => { - describe('is February (2)', () => { - describe('and "abstractionPeriodStartDay" is more than the number of days in the month (29)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = 2 - transformedLicenceVersionPurpose.abstractionPeriodStartDay = 29 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartDay" must be less than or equal to 28') - }) - }) - }) - - describe('is April (4)', () => { - describe('and "abstractionPeriodStartDay" is more than the number of days in the month (30)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = 4 - transformedLicenceVersionPurpose.abstractionPeriodStartDay = 31 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartDay" must be less than or equal to 30') - }) - }) - }) - - describe('is March (3)', () => { - describe('and "abstractionPeriodStartDay" is more than the number of days in the month (31)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = 3 - transformedLicenceVersionPurpose.abstractionPeriodStartDay = 32 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartDay" must be less than or equal to 31') - }) - }) - }) - }) - }) - - describe('the "abstractionPeriodStartMonth" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = '12a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartMonth" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartMonth" must be a number') - }) - }) - - describe('when it is less than the minimum (1)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = 0 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartMonth" must be greater than or equal to 1') - }) - }) - - describe('when it is more than the maximum (12)', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.abstractionPeriodStartMonth = 13 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"abstractionPeriodStartMonth" must be less than or equal to 12') - }) - }) - }) - - describe('the "annualQuantity" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.annualQuantity = '545520.1a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"annualQuantity" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.annualQuantity = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) - - describe('the "dailyQuantity" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.dailyQuantity = '1500.2a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"dailyQuantity" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.dailyQuantity = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) - - describe('the "externalId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.externalId = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"externalId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.externalId = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"externalId" must be a string') - }) - }) - }) - - describe('the "hourlyQuantity" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.hourlyQuantity = '140.929a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"hourlyQuantity" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.hourlyQuantity = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) - - describe('the "instantQuantity" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.instantQuantity = '1.1a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"instantQuantity" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.instantQuantity = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) - - describe('the "notes" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.notes = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"notes" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.notes = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) - - describe('the "primaryPurposeId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.primaryPurposeId = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"primaryPurposeId" must be a string') - }) - }) - - describe('when it is not a valid GUID', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.primaryPurposeId = 'i am not a GUID' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"primaryPurposeId" must be a valid GUID') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.primaryPurposeId = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"primaryPurposeId" must be a string') - }) - }) - }) - - describe('the "purposeId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.purposeId = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"purposeId" must be a string') - }) - }) - - describe('when it is not a valid GUID', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.purposeId = 'i am not a GUID' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"purposeId" must be a valid GUID') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.purposeId = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"purposeId" must be a string') - }) - }) - }) - - describe('the "secondaryPurposeId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.secondaryPurposeId = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"secondaryPurposeId" must be a string') - }) - }) - - describe('when it is not a valid GUID', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.secondaryPurposeId = 'i am not a GUID' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"secondaryPurposeId" must be a valid GUID') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.secondaryPurposeId = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"secondaryPurposeId" must be a string') - }) - }) - }) - - describe('the "timeLimitedEndDate" property', () => { - describe('when it is not a date or null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.timeLimitedEndDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"timeLimitedEndDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.timeLimitedEndDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) - - describe('the "timeLimitedStartDate" property', () => { - describe('when it is not a date or null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.timeLimitedStartDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.throw('"timeLimitedStartDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersionPurpose.timeLimitedStartDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionPurposeValidator.go(transformedLicenceVersionPurpose) - }).to.not.throw() - }) - }) - }) -}) - -function _transformedLicenceVersionPurpose() { - return { - abstractionPeriodEndDay: 31, - abstractionPeriodEndMonth: 3, - abstractionPeriodStartDay: 1, - abstractionPeriodStartMonth: 4, - annualQuantity: 545520.1, - dailyQuantity: 1500.2, - externalId: '6:10000004', - hourlyQuantity: 140.929, - instantQuantity: 1.1, - notes: 'This is a note', - primaryPurposeId: '8d9d407c-3da7-4977-84a0-97738c9b44cc', - purposeId: '025bfdc9-d7f4-46b5-a7e0-451dec1a34a6', - secondaryPurposeId: '04bdc9f6-a4e7-41de-831c-9ebf15b92782', - timeLimitedEndDate: new Date('1992-08-19'), - timeLimitedStartDate: new Date('2052-06-23') - } -} diff --git a/test/validators/import/licence-version.validator.test.js b/test/validators/import/licence-version.validator.test.js deleted file mode 100644 index de1271f301..0000000000 --- a/test/validators/import/licence-version.validator.test.js +++ /dev/null @@ -1,233 +0,0 @@ -'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 - -// Thing under test -const LicenceVersionValidator = require('../../../app/validators/import/licence-version.validator.js') - -describe('Import Licence Version validator', () => { - let transformedLicenceVersion - - beforeEach(async () => { - transformedLicenceVersion = _transformedLicenceVersion() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.not.throw() - }) - }) - - describe('the "endDate" property', () => { - describe('when it is not a date or null', () => { - beforeEach(() => { - transformedLicenceVersion.endDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"endDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.endDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.not.throw() - }) - }) - }) - - describe('the "externalId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersion.externalId = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"externalId" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.externalId = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"externalId" must be a string') - }) - }) - }) - - describe('the "increment" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersion.increment = '1a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"increment" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.increment = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"increment" must be a number') - }) - }) - }) - - describe('the "issue" property', () => { - describe('when it is not a number', () => { - beforeEach(() => { - transformedLicenceVersion.issue = '1a' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"issue" must be a number') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.issue = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"issue" must be a number') - }) - }) - }) - - describe('the "licenceVersionPurposes" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedLicenceVersion.licenceVersionPurposes = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"licenceVersionPurposes" must be an array') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.licenceVersionPurposes = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"licenceVersionPurposes" must be an array') - }) - }) - }) - - describe('the "startDate" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicenceVersion.startDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"startDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.startDate = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"startDate" must be a valid date') - }) - }) - }) - - describe('the "status" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicenceVersion.status = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"status" must be one of [current, superseded]') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicenceVersion.status = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"status" must be one of [current, superseded]') - }) - }) - - describe('when it is not a recognised status', () => { - beforeEach(() => { - transformedLicenceVersion.status = 'draft' - }) - - it('throws an error', async () => { - expect(() => { - LicenceVersionValidator.go(transformedLicenceVersion) - }).to.throw('"status" must be one of [current, superseded]') - }) - }) - }) -}) - -function _transformedLicenceVersion() { - return { - endDate: new Date('2052-06-23'), - externalId: '6:2113:100:0', - increment: 0, - issue: 100, - licenceVersionPurposes: [], - startDate: new Date('1999-01-01'), - status: 'current' - } -} diff --git a/test/validators/import/licence.validator.test.js b/test/validators/import/licence.validator.test.js deleted file mode 100644 index f30bb84e6e..0000000000 --- a/test/validators/import/licence.validator.test.js +++ /dev/null @@ -1,407 +0,0 @@ -'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 { generateLicenceRef } = require('../../support/helpers/licence.helper.js') - -// Thing under test -const LicenceValidator = require('../../../app/validators/import/licence.validator.js') - -describe('Import Licence validator', () => { - let transformedLicence - - beforeEach(async () => { - transformedLicence = _transformedLicence() - }) - - describe('when valid data is provided', () => { - it('does not throw an error', () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.not.throw() - }) - }) - - describe('the "expiredDate" property', () => { - describe('when it is not a date or null', () => { - beforeEach(() => { - transformedLicence.expiredDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"expiredDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.expiredDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.not.throw() - }) - }) - }) - - describe('the "lapsedDate" property', () => { - describe('when it is not a date or null', () => { - beforeEach(() => { - transformedLicence.lapsedDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"lapsedDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.lapsedDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.not.throw() - }) - }) - }) - - describe('the "licenceRef" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicence.licenceRef = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"licenceRef" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.licenceRef = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"licenceRef" must be a string') - }) - }) - - describe('when it contains whitespace', () => { - beforeEach(() => { - transformedLicence.licenceRef = `${transformedLicence.licenceRef} ` - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"licenceRef" must not have leading or trailing whitespace') - }) - }) - }) - - describe('the "licenceVersions" property', () => { - describe('when it is not an array', () => { - beforeEach(() => { - transformedLicence.licenceVersions = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"licenceVersions" must be an array') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.licenceVersions = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"licenceVersions" must be an array') - }) - }) - }) - - describe('the "regionId" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicence.regionId = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regionId" must be a string') - }) - }) - - describe('when it is not a valid GUID', () => { - beforeEach(() => { - transformedLicence.regionId = 'i am not a GUID' - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regionId" must be a valid GUID') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.regionId = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regionId" must be a string') - }) - }) - }) - - describe('the "regions" property', () => { - describe('when it is not an object', () => { - beforeEach(() => { - transformedLicence.regions = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions" must be of type object') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.regions = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions" must be of type object') - }) - }) - - describe('and its "regionalChargeArea" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicence.regions.regionalChargeArea = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.regionalChargeArea" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.regions.regionalChargeArea = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.regionalChargeArea" must be a string') - }) - }) - }) - - describe('and its "localEnvironmentAgencyPlanCode" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicence.regions.localEnvironmentAgencyPlanCode = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.localEnvironmentAgencyPlanCode" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.regions.localEnvironmentAgencyPlanCode = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.localEnvironmentAgencyPlanCode" must be a string') - }) - }) - }) - - describe('and its "historicalAreaCode" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicence.regions.historicalAreaCode = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.historicalAreaCode" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.regions.historicalAreaCode = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.historicalAreaCode" must be a string') - }) - }) - }) - - describe('and its "standardUnitChargeCode" property', () => { - describe('when it is not a string', () => { - beforeEach(() => { - transformedLicence.regions.standardUnitChargeCode = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.standardUnitChargeCode" must be a string') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.regions.standardUnitChargeCode = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"regions.standardUnitChargeCode" must be a string') - }) - }) - }) - }) - - describe('the "revokedDate" property', () => { - describe('when it is not a date or null', () => { - beforeEach(() => { - transformedLicence.revokedDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"revokedDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.revokedDate = null - }) - - it('does not throw an error', () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.not.throw() - }) - }) - }) - - describe('the "startDate" property', () => { - describe('when it is not a date', () => { - beforeEach(() => { - transformedLicence.startDate = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"startDate" must be a valid date') - }) - }) - - describe('when it is null', () => { - beforeEach(() => { - transformedLicence.startDate = null - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"startDate" must be a valid date') - }) - }) - }) - - describe('the "waterUndertaker" property', () => { - describe('when it is not a boolean', () => { - beforeEach(() => { - transformedLicence.waterUndertaker = 1 - }) - - it('throws an error', async () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.throw('"waterUndertaker" must be a boolean') - }) - }) - - describe('when it is a boolean', () => { - it('does not throw an error', () => { - expect(() => { - LicenceValidator.go(transformedLicence) - }).to.not.throw() - }) - }) - }) -}) - -function _transformedLicence() { - return { - expiredDate: new Date('2052-06-23'), - lapsedDate: new Date('2050-07-24'), - licenceRef: generateLicenceRef(), - licenceVersions: [], - regionId: '82d8c1b7-0eed-43a7-a5f9-4e397c08e17e', - regions: { - historicalAreaCode: 'KAEA', - regionalChargeArea: 'Southern', - standardUnitChargeCode: 'SUCSO', - localEnvironmentAgencyPlanCode: 'LEME' - }, - revokedDate: new Date('2049-08-25'), - startDate: new Date('1992-08-19'), - waterUndertaker: false - } -}