diff --git a/app/presenters/bills/view-bill.presenter.js b/app/presenters/bills/view-bill.presenter.js index 1bc0abce3d..5780a4f2bd 100644 --- a/app/presenters/bills/view-bill.presenter.js +++ b/app/presenters/bills/view-bill.presenter.js @@ -16,10 +16,10 @@ function go (bill, billingAccount) { const formattedBill = { accountName: _accountName(billingAccount), - accountNumber: billingAccount.invoiceAccountNumber, + accountNumber: billingAccount.accountNumber, addressLines: _addressLines(billingAccount), billId: bill.billingInvoiceId, - billingAccountId: billingAccount.invoiceAccountId, + billingAccountId: billingAccount.id, billNumber: bill.invoiceNumber, billRunId: billRun.billingBatchId, billRunNumber: billRun.billRunNumber, @@ -46,8 +46,8 @@ function go (bill, billingAccount) { function _accountName (billingAccount) { const accountAddress = billingAccount.billingAccountAddresses[0] - if (accountAddress.agentCompany) { - return accountAddress.agentCompany.name + if (accountAddress.company) { + return accountAddress.company.name } return billingAccount.company.name @@ -61,8 +61,8 @@ function _addressLines (billingAccount) { address.address2, address.address3, address.address4, - address.town, - address.county, + address.address5, + address.address6, address.postcode, address.country ] diff --git a/app/presenters/charging-module/create-customer-change.presenter.js b/app/presenters/charging-module/create-customer-change.presenter.js index 4b1c52d88f..519e33b41f 100644 --- a/app/presenters/charging-module/create-customer-change.presenter.js +++ b/app/presenters/charging-module/create-customer-change.presenter.js @@ -55,7 +55,7 @@ * @returns {Object} the request data needed in the format required by the Charging Module */ function go (billingAccount, address, company, contact) { - const { invoiceAccountNumber: customerReference } = billingAccount + const { accountNumber: customerReference } = billingAccount const region = customerReference.charAt(0) const customerName = _customerName(billingAccount, company) @@ -69,17 +69,17 @@ function go (billingAccount, address, company, contact) { } } -function _addressLine6 (county, country) { - if (!county && !country) { +function _addressLine6 (address6, country) { + if (!address6 && !country) { return '' } - if (county && country) { - return `${county}, ${country}` + if (address6 && country) { + return `${address6}, ${country}` } - if (county) { - return county + if (address6) { + return address6 } return country @@ -96,7 +96,7 @@ function _customerName (billingAccount, company) { function _formattedAddress (address, contact) { const addressLines = [] - const { address1, address2, address3, address4, town, county, country, postcode } = address + const { address1, address2, address3, address4, address5, address6, country, postcode } = address const contactName = contact.$name() if (address1) { @@ -133,8 +133,8 @@ function _formattedAddress (address, contact) { addressLine3: addressLines[2] ? addressLines[2] : null, addressLine4: addressLines[3] ? addressLines[3] : null, // We have encountered instances of ton being null so we confirm we have something to truncate to avoid an error - addressLine5: town ? _truncate(town, 60) : null, - addressLine6: _truncate(_addressLine6(county, country), 60), + addressLine5: address5 ? _truncate(address5, 60) : null, + addressLine6: _truncate(_addressLine6(address6, country), 60), postcode: _truncate(postcode, 60) } } diff --git a/app/services/bill-runs/supplementary/fetch-billing-accounts.service.js b/app/services/bill-runs/supplementary/fetch-billing-accounts.service.js index 6d2095560e..002b850a16 100644 --- a/app/services/bill-runs/supplementary/fetch-billing-accounts.service.js +++ b/app/services/bill-runs/supplementary/fetch-billing-accounts.service.js @@ -5,7 +5,7 @@ * @module FetchBillingAccountsService */ -const BillingAccountModel = require('../../../models/crm-v2/billing-account.model.js') +const BillingAccountModel = require('../../../models/billing-account.model.js') /** * Fetch all billing accounts for the supplied charge versions @@ -15,8 +15,8 @@ const BillingAccountModel = require('../../../models/crm-v2/billing-account.mode * @returns {Object[]} Array of objects in the format { invoiceAccountId: '...', invoiceAccountNumber: '...' } */ async function go (chargeVersions) { - const uniqueInvoiceAccountIds = _extractUniqueInvoiceAccountIds(chargeVersions) - const billingAccountModels = await _fetch(uniqueInvoiceAccountIds) + const uniqueBillingAccountIds = _extractUniqueBillingAccountIds(chargeVersions) + const billingAccountModels = await _fetch(uniqueBillingAccountIds) // The results come back from Objection as BillingAccountModels. Since we want to be clear that these are not // full-blown models, we turn them into plain objects using Objection's .toJSON() method @@ -25,20 +25,20 @@ async function go (chargeVersions) { return billingAccountObjects } -function _extractUniqueInvoiceAccountIds (chargeVersions) { - const allInvoiceAccountIds = chargeVersions.map((chargeVersion) => { +function _extractUniqueBillingAccountIds (chargeVersions) { + const allBillingAccountIds = chargeVersions.map((chargeVersion) => { return chargeVersion.invoiceAccountId }) - // Creating a new set from allInvoiceAccountIds gives us just the unique ids. Objection does not accept sets in + // Creating a new set from allBillingAccountIds gives us just the unique ids. Objection does not accept sets in // .findByIds() so we spread it into an array - return [...new Set(allInvoiceAccountIds)] + return [...new Set(allBillingAccountIds)] } -function _fetch (uniqueInvoiceAccountIds) { +function _fetch (uniqueBillingAccountIds) { return BillingAccountModel.query() - .select('invoiceAccountId', 'invoiceAccountNumber') - .findByIds([...uniqueInvoiceAccountIds]) + .select('id', 'accountNumber') + .findByIds([...uniqueBillingAccountIds]) } function _makeObjects (models) { diff --git a/app/services/bill-runs/supplementary/generate-bill.service.js b/app/services/bill-runs/supplementary/generate-bill.service.js index 5061ea4ee3..ff86efda4b 100644 --- a/app/services/bill-runs/supplementary/generate-bill.service.js +++ b/app/services/bill-runs/supplementary/generate-bill.service.js @@ -20,10 +20,10 @@ function go (billingAccount, billRunId, financialYearEnding) { const bill = { billingBatchId: billRunId, financialYearEnding, - invoiceAccountId: billingAccount.invoiceAccountId, + invoiceAccountId: billingAccount.id, billingInvoiceId: generateUUID(), address: {}, // Address is set to an empty object for SROC billing invoices - invoiceAccountNumber: billingAccount.invoiceAccountNumber, + invoiceAccountNumber: billingAccount.accountNumber, isCredit: false } diff --git a/app/services/bill-runs/supplementary/pre-generate-billing-data.service.js b/app/services/bill-runs/supplementary/pre-generate-billing-data.service.js index fde29b20f0..25e108a659 100644 --- a/app/services/bill-runs/supplementary/pre-generate-billing-data.service.js +++ b/app/services/bill-runs/supplementary/pre-generate-billing-data.service.js @@ -70,11 +70,11 @@ function _billLicenceKey (billId, licenceId) { /** * We pre-generate bills for every billing account so that we don't need to fetch any data from the db during the main * charge version processing loop. This function generates the required bill licences and returns an object where - * each key is the invoice account id, and each value is the bill, ie: + * each key is the billing account id, and each value is the bill, ie: * * { - * 'uuid-1': { invoiceAccountId: 'uuid-1', ... }, - * 'uuid-2': { invoiceAccountId: 'uuid-2', ... } + * 'uuid-1': { id: 'uuid-1', ... }, + * 'uuid-2': { id: 'uuid-2', ... } * } */ function _preGenerateBills (billingAccounts, billRunId, billingPeriod) { @@ -83,7 +83,7 @@ function _preGenerateBills (billingAccounts, billRunId, billingPeriod) { // bill licence already exists in the object before generating one return { ...acc, - [billingAccount.invoiceAccountId]: GenerateBillService.go( + [billingAccount.id]: GenerateBillService.go( billingAccount, billRunId, billingPeriod.endDate.getFullYear() diff --git a/app/services/billing-accounts/change-address.service.js b/app/services/billing-accounts/change-address.service.js index 6dde757765..e6bb9f4a36 100644 --- a/app/services/billing-accounts/change-address.service.js +++ b/app/services/billing-accounts/change-address.service.js @@ -5,11 +5,11 @@ * @module ChangeAddressService */ -const AddressModel = require('../../models/crm-v2/address.model.js') -const BillingAccountAddressModel = require('../../models/crm-v2/billing-account-address.model.js') -const BillingAccountModel = require('../../models/crm-v2/billing-account.model.js') -const CompanyModel = require('../../models/crm-v2/company.model.js') -const ContactModel = require('../../models/crm-v2/contact.model.js') +const AddressModel = require('../../models/address.model.js') +const BillingAccountAddressModel = require('../../models/billing-account-address.model.js') +const BillingAccountModel = require('../../models/billing-account.model.js') +const CompanyModel = require('../../models/company.model.js') +const ContactModel = require('../../models/contact.model.js') const SendCustomerChangeService = require('./send-customer-change.service.js') /** @@ -18,11 +18,11 @@ const SendCustomerChangeService = require('./send-customer-change.service.js') * Within the service an internal user can 'Change the address' of a billing account. That is what the button says but * they can also change or set the agent company and the contact along with the address. * - * Behind the scenes a new `crm_v2.invoice_account_address` record is created that links to the `crm_v2.address`, - * `crm_v2.company` and `crm_v2.contact` records. It will also be linked to the `crm_v2.invoice_account` which + * Behind the scenes a new `billing_account_address` record is created that links to the `addresses`, + * `companies` and `contacts` records. It will also be linked to the `crm_v2.billing_account` which * represents the billing account being amended. * - * It won't have an end date, which marks it as the 'current' address. The previous `invoice_account_address` will get + * It won't have an end date, which marks it as the 'current' address. The previous `billing_account_address` will get * its `end_date` updated. The legacy service then knows that address is no longer current. * * When a change like this is made SOP, the system that sends invoices to customers, needs to know about it. That @@ -34,7 +34,7 @@ const SendCustomerChangeService = require('./send-customer-change.service.js') * - the source for addresses, companies and contacts is NALD and WRLS. But rather than transform them at ingress to a * single format the tables manage both. For example, NALD contacts use `initials` whereas WRLS contacts use * `middle_initials`. A contact can also be a 'department' under WRLS, which means the format changes again - * - where possible duplication of records has tried to be avoided. For example, you cannot have 2 addresses with the + * - where possible, duplication of records has tried to be avoided. For example, you cannot have 2 addresses with the * same UPRN, or 2 companies with the same company number. The problem is the source data _does_ change. We have seen * the OS Places result for Horizon House change from Environment Agency, to Natural England, Defra and back to the * Environment Agency over the years. This means when a user changes the address, for example, they may actually be @@ -81,9 +81,9 @@ async function go (billingAccountId, address, agentCompany = {}, contact = {}) { return _response(persistedData) } -async function _fetchBillingAccount (invoiceAccountId) { +async function _fetchBillingAccount (billingAccountId) { return BillingAccountModel.query() - .findById(invoiceAccountId) + .findById(billingAccountId) .withGraphFetched('company') .modifyGraph('company', (builder) => { builder.select([ @@ -105,7 +105,7 @@ async function _fetchBillingAccount (invoiceAccountId) { * instances. * * We attempt to persist the address, company and contact model instances first because we need their IDs in order to - * create the new `crm_v2.invoice_account_address` record. When we create that record we also need to apply an end date + * create the new `billing_account_addresses` record. When we create that record we also need to apply an end date * to any existing billing account addresses with a null end date. This is how the service determines which address * details are current (end date is null). * @@ -130,24 +130,24 @@ async function _persist (timestamp, billingAccount, address, company, contact) { persistedData.contact = await _persistContact(trx, contact) const billingAccountAddress = BillingAccountAddressModel.fromJson({ - invoiceAccountId: billingAccount.invoiceAccountId, - addressId: persistedData.address.addressId, - agentCompanyId: persistedData.company.companyId, - contactId: persistedData.contact.contactId, + billingAccountId: billingAccount.id, + addressId: persistedData.address.id, + companyId: persistedData.company.id, + contactId: persistedData.contact.id, startDate: timestamp, endDate: null, createdAt: timestamp, updatedAt: timestamp }) - await _patchExistingBillingAccountAddressEndDate(trx, billingAccount.invoiceAccountId, timestamp) + await _patchExistingBillingAccountAddressEndDate(trx, billingAccount.id, timestamp) persistedData.billingAccountAddress = await _persistBillingAccountAddress(trx, billingAccountAddress) }) return persistedData } -async function _patchExistingBillingAccountAddressEndDate (trx, invoiceAccountId, timestamp) { +async function _patchExistingBillingAccountAddressEndDate (trx, billingAccountId, timestamp) { // The timestamp represents the current date and time we're making this change, i.e. today. So, the new billing // account address will start from today. To show that the old record is no longer current, we need to set its // `endDate` to be today - 1 (yesterday). The following works it all out even if we're over a month or year boundary @@ -160,14 +160,14 @@ async function _patchExistingBillingAccountAddressEndDate (trx, invoiceAccountId endDate, updatedAt: timestamp }) - .where('invoiceAccountId', invoiceAccountId) + .where('billingAccountId', billingAccountId) .whereNull('endDate') } /** * Persist the new billing account address * - * The legacy code included logic to handle a situation where the start date and invoice account ID are the same. This + * The legacy code included logic to handle a situation where the start date and billing account ID are the same. This * could happen if you make a change to a billing account's address more than once on the same day. It would first * SELECT any records where that was the case and then DELETE them. * @@ -177,21 +177,21 @@ async function _patchExistingBillingAccountAddressEndDate (trx, invoiceAccountId async function _persistBillingAccountAddress (trx, billingAccountAddress) { return billingAccountAddress.$query(trx) .insert() - .onConflict(['invoiceAccountId', 'startDate']) + .onConflict(['billingAccountId', 'startDate']) // If a conflict is found this specifies what fields should get updated .merge([ 'addressId', - 'agentCompanyId', + 'companyId', 'contactId', 'endDate', - 'dateUpdated' + 'updatedAt' ]) } /** * Persist the address entered during the change address process * - * If the address has an `addressId:` we assume it was an existing address selected during the journey. So, the address + * If the address has an `id:` we assume it was an existing address selected during the journey. So, the address * is already persisted hence we just return `address`. * * Else we attempt to insert a new address record. If the address has a `uprn:` it will be one selected from the @@ -199,7 +199,7 @@ async function _persistBillingAccountAddress (trx, billingAccountAddress) { * records with matching UPRNs. But we use this to our advantage. Using `onConflict()` and `merge()` we can have * Objection JS update the existing address record if a matching UPRN exists. * - * Because either INSERT or UPDATE gets fired `returning()` will kick in and return the all important `addressId` which + * Because either INSERT or UPDATE gets fired `returning()` will kick in and return the all important `id` which * we'll need later for the billing account address. It will also return the fields specified in the INSERT/UPDATE hence * we get a 'complete' address back that we can return to the calling function. * @@ -211,7 +211,7 @@ async function _persistBillingAccountAddress (trx, billingAccountAddress) { * > returned when first added. */ async function _persistAddress (trx, address) { - if (address.addressId) { + if (address.id) { return address } @@ -224,21 +224,21 @@ async function _persistAddress (trx, address) { 'address2', 'address3', 'address4', - 'town', - 'county', + 'address5', + 'address6', 'country', 'postcode', - 'dateUpdated' + 'updatedAt' ]) .returning([ - 'addressId' + 'id' ]) } /** * Persist the company (Agent) entered during the change address process * - * If the company has a `companyId:` we assume it was an existing company selected during the journey. So, the company + * If the company has an `id:` we assume it was an existing company selected during the journey. So, the company * is already persisted hence we just return `company`. If the company name is not set then the user has opted not to * change the agent in the journey. So, we just return the empty `CompanyModel` instance. * @@ -246,9 +246,9 @@ async function _persistAddress (trx, address) { * company record selected by the user, or they will have been required to enter the company number. The previous team * added a unique constraint on `company_number` in the table so we cannot insert 2 records with matching numbers. But * we use this to our advantage. Using `onConflict()` and `merge()` we can have Objection JS update the existing company - * record if a matching company number. + * record if a matching company number exists. * - * Because either INSERT or UPDATE gets fired `returning()` will kick in and return the all important `companyId` which + * Because either INSERT or UPDATE gets fired `returning()` will kick in and return the all important `id` which * we'll need later for the billing account address. It will also return the fields specified in the INSERT/UPDATE hence * we get a 'complete' company back that we can return to the calling function. * @@ -260,7 +260,7 @@ async function _persistAddress (trx, address) { * > what it returned when first added. */ async function _persistCompany (trx, company) { - if (company.companyId || !company.name) { + if (company.id || !company.name) { return company } @@ -270,10 +270,10 @@ async function _persistCompany (trx, company) { // If a conflict is found this specifies what fields should get updated .merge([ 'name', - 'dateUpdated' + 'updatedAt' ]) .returning([ - 'companyId' + 'id' ]) } @@ -293,7 +293,7 @@ async function _persistContact (trx, contact) { return contact.$query(trx) .insert() .returning([ - 'contactId' + 'id' ]) } @@ -314,22 +314,22 @@ function _response (persistedData) { const { address, company, contact, billingAccountAddress } = persistedData return { - invoiceAccountAddress: { ...billingAccountAddress }, + billingAccountAddress: { ...billingAccountAddress }, address: { ...address }, - agentCompany: company.companyId ? { ...company } : null, - contact: contact.contactId ? { ...contact } : null + agentCompany: company.id ? { ...company } : null, + contact: contact.id ? { ...contact } : null } } function _transformAddress (timestamp, address) { return AddressModel.fromJson({ - addressId: address.addressId, + id: address.addressId, address1: address.addressLine1, address2: address.addressLine2, address3: address.addressLine3, address4: address.addressLine4, - town: address.town, - county: address.county, + address5: address.town, + address6: address.county, country: address.country, postcode: address.postcode, uprn: address.uprn, @@ -341,7 +341,7 @@ function _transformAddress (timestamp, address) { function _transformCompany (timestamp, company) { return CompanyModel.fromJson({ - companyId: company.companyId, + id: company.companyId, type: company.type, name: company.name, companyNumber: company.companyNumber, diff --git a/app/services/bills/fetch-billing-account.service.js b/app/services/bills/fetch-billing-account.service.js index 3a5cdde34a..568853a950 100644 --- a/app/services/bills/fetch-billing-account.service.js +++ b/app/services/bills/fetch-billing-account.service.js @@ -5,7 +5,7 @@ * @module FetchBillingAccountService */ -const BillingAccount = require('../../models/crm-v2/billing-account.model.js') +const BillingAccount = require('../../models/billing-account.model.js') /** * Fetch the matching Billing account plus the current billing account address record linked to it @@ -22,13 +22,13 @@ async function _fetch (id) { const result = BillingAccount.query() .findById(id) .select([ - 'invoiceAccountId', - 'invoiceAccountNumber' + 'id', + 'accountNumber' ]) .withGraphFetched('company') .modifyGraph('company', (builder) => { builder.select([ - 'company_id', + 'id', 'name', 'type' ]) @@ -41,21 +41,21 @@ async function _fetch (id) { .withGraphFetched('billingAccountAddresses.address') .modifyGraph('billingAccountAddresses.address', (builder) => { builder.select([ - 'addressId', + 'id', 'address1', 'address2', 'address3', 'address4', - 'town', - 'county', + 'address5', + 'address6', 'postcode', 'country' ]) }) - .withGraphFetched('billingAccountAddresses.agentCompany') - .modifyGraph('billingAccountAddresses.agentCompany', (builder) => { + .withGraphFetched('billingAccountAddresses.company') + .modifyGraph('billingAccountAddresses.company', (builder) => { builder.select([ - 'companyId', + 'id', 'name', 'type' ]) @@ -63,7 +63,7 @@ async function _fetch (id) { .withGraphFetched('billingAccountAddresses.contact') .modifyGraph('billingAccountAddresses.contact', (builder) => { builder.select([ - 'contactId', + 'id', 'contactType', 'dataSource', 'department', diff --git a/test/presenters/bills/view-bill.presenter.test.js b/test/presenters/bills/view-bill.presenter.test.js index d8dcb0a1a0..bcb0de7e93 100644 --- a/test/presenters/bills/view-bill.presenter.test.js +++ b/test/presenters/bills/view-bill.presenter.test.js @@ -8,7 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const ContactModel = require('../../../app/models/crm-v2/contact.model.js') +const ContactModel = require('../../../app/models/contact.model.js') // Thing under test const ViewBillPresenter = require('../../../app/presenters/bills/view-bill.presenter.js') @@ -64,7 +64,7 @@ describe('View Bill presenter', () => { describe('when the billing account is linked to an agent', () => { beforeEach(() => { - billingAccount.billingAccountAddresses[0].agentCompany = { + billingAccount.billingAccountAddresses[0].company = { companyId: 'b0d35412-f76c-44ca-9d63-c6350337e03d', type: 'person', name: 'Alan Broke' @@ -400,34 +400,33 @@ function _testBill () { function _testBillingAccount () { return { - invoiceAccountId: 'ee3f5562-26ad-4d58-9b59-5c388a13d7d0', - invoiceAccountNumber: 'E88888888A', + id: 'ee3f5562-26ad-4d58-9b59-5c388a13d7d0', + accountNumber: 'E88888888A', company: { type: 'organisation', name: 'Wessex Water Services Ltd' }, billingAccountAddresses: [ { - invoiceAccountAddressId: 'b0e53215-b73a-4570-992b-2a724944ea19', - invoiceAccountId: 'ee3f5562-26ad-4d58-9b59-5c388a13d7d0', + id: 'b0e53215-b73a-4570-992b-2a724944ea19', + billingAccountId: 'ee3f5562-26ad-4d58-9b59-5c388a13d7d0', addressId: 'f3360183-8002-4802-a6d4-80d7e7160a50', startDate: new Date('1999-10-01'), endDate: null, - isTest: false, - agentCompanyId: null, + companyId: null, contactId: null, createdAt: new Date('2022-06-15'), updatedAt: new Date('2023-10-17'), - agentCompany: null, + company: null, contact: null, address: { - addressId: 'f3360183-8002-4802-a6d4-80d7e7160a50', + id: 'f3360183-8002-4802-a6d4-80d7e7160a50', address1: '86 Oxford Road', address2: 'WOOTTON', address3: null, address4: null, - town: 'COURTENAY', - county: null, + address5: 'COURTENAY', + address6: null, postcode: 'TA24 8NX', country: null } diff --git a/test/presenters/charging-module/create-customer-change.presenter.test.js b/test/presenters/charging-module/create-customer-change.presenter.test.js index 74adc5a859..62a6f3ab13 100644 --- a/test/presenters/charging-module/create-customer-change.presenter.test.js +++ b/test/presenters/charging-module/create-customer-change.presenter.test.js @@ -8,10 +8,10 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const AddressModel = require('../../../app/models/crm-v2/address.model.js') -const BillingAccountModel = require('../../../app/models/crm-v2/billing-account.model.js') -const CompanyModel = require('../../../app/models/crm-v2/company.model.js') -const ContactModel = require('../../../app/models/crm-v2/contact.model.js') +const AddressModel = require('../../../app/models/address.model.js') +const BillingAccountModel = require('../../../app/models/billing-account.model.js') +const CompanyModel = require('../../../app/models/company.model.js') +const ContactModel = require('../../../app/models/contact.model.js') // Thing under test const CreateCustomerChangePresenter = require('../../../app/presenters/charging-module/create-customer-change.presenter.js') @@ -23,7 +23,7 @@ const CreateCustomerChangePresenter = require('../../../app/presenters/charging- // what scenarios we face when converting the WRLS data. describe('Charging Module Create Transaction presenter', () => { const billingAccount = BillingAccountModel.fromJson({ - invoiceAccountNumber: 'B19120000A', + accountNumber: 'B19120000A', company: { name: 'BILLING ACCOUNT COMPANY' } @@ -33,8 +33,8 @@ describe('Charging Module Create Transaction presenter', () => { address2: 'HORIZON HOUSE', address3: 'DEANERY ROAD', address4: null, - town: 'BRISTOL', - county: null, + address5: 'BRISTOL', + address6: null, country: 'United Kingdom', postcode: 'BS1 5AH' } @@ -300,21 +300,21 @@ describe('Charging Module Create Transaction presenter', () => { contact = ContactModel.fromJson({}) }) - describe('when town is set in the address', () => { + describe('when address5 is set in the address', () => { beforeEach(() => { address = AddressModel.fromJson({ ...standardAddress }) }) - it('returns the town for addressLine5', () => { + it('returns address for addressLine5', () => { const result = CreateCustomerChangePresenter.go(billingAccount, address, company, contact) expect(result.addressLine5).to.equal('BRISTOL') }) }) - describe('when town is not set in the address', () => { + describe('when address5 is not set in the address', () => { beforeEach(() => { - address = AddressModel.fromJson({ ...standardAddress, town: null }) + address = AddressModel.fromJson({ ...standardAddress, address5: null }) }) it('returns null for addressLine5', () => { @@ -331,22 +331,22 @@ describe('Charging Module Create Transaction presenter', () => { contact = ContactModel.fromJson({}) }) - describe('when both county and country are set', () => { + describe('when both address6 and country are set', () => { beforeEach(() => { address = AddressModel.fromJson({ ...standardAddress, - county: 'AVON' + address6: 'AVON' }) }) - it('returns both county and country for addressLine6', () => { + it('returns both address6 and country for addressLine6', () => { const result = CreateCustomerChangePresenter.go(billingAccount, address, company, contact) expect(result.addressLine6).to.equal('AVON, United Kingdom') }) }) - describe('when neither county and country are set', () => { + describe('when neither address6 and country are set', () => { beforeEach(() => { address = AddressModel.fromJson({ ...standardAddress, @@ -361,16 +361,16 @@ describe('Charging Module Create Transaction presenter', () => { }) }) - describe('when only county is set', () => { + describe('when only address6 is set', () => { beforeEach(() => { address = AddressModel.fromJson({ ...standardAddress, - county: 'AVON', + address6: 'AVON', country: null }) }) - it('returns just the county for addressLine6', () => { + it('returns just address for addressLine6', () => { const result = CreateCustomerChangePresenter.go(billingAccount, address, company, contact) expect(result.addressLine6).to.equal('AVON') @@ -408,7 +408,7 @@ describe('Charging Module Create Transaction presenter', () => { beforeEach(() => { address = AddressModel.fromJson({ ...standardAddress, - town: 'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch Town' + address5: 'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch Town' }) company = CompanyModel.fromJson({}) contact = ContactModel.fromJson({}) diff --git a/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js b/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js index a8a85f467f..984aab1707 100644 --- a/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js +++ b/test/services/bill-runs/supplementary/fetch-billing-accounts.service.test.js @@ -8,7 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const BillingAccountHelper = require('../../../support/helpers/crm-v2/billing-account.helper.js') +const BillingAccountHelper = require('../../../support/helpers/billing-account.helper.js') const DatabaseHelper = require('../../../support/helpers/database.helper.js') // Thing under test @@ -33,20 +33,20 @@ describe('Fetch Billing Accounts service', () => { expectedResult = [ { - invoiceAccountId: billingAccounts[0].invoiceAccountId, - invoiceAccountNumber: billingAccounts[0].invoiceAccountNumber + id: billingAccounts[0].id, + accountNumber: billingAccounts[0].accountNumber }, { - invoiceAccountId: billingAccounts[1].invoiceAccountId, - invoiceAccountNumber: billingAccounts[1].invoiceAccountNumber + id: billingAccounts[1].id, + accountNumber: billingAccounts[1].accountNumber } ] }) it('fetches the billing accounts that the charge versions link to', async () => { const result = await FetchBillingAccountsService.go([ - { invoiceAccountId: billingAccounts[0].invoiceAccountId }, - { invoiceAccountId: billingAccounts[1].invoiceAccountId } + { invoiceAccountId: billingAccounts[0].id }, + { invoiceAccountId: billingAccounts[1].id } ]) expect(result).to.have.length(2).and.contain(expectedResult) diff --git a/test/services/bill-runs/supplementary/generate-bill.service.test.js b/test/services/bill-runs/supplementary/generate-bill.service.test.js index 6565c0bab4..1bc2677d1c 100644 --- a/test/services/bill-runs/supplementary/generate-bill.service.test.js +++ b/test/services/bill-runs/supplementary/generate-bill.service.test.js @@ -8,7 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const BillingAccountHelper = require('../../../support/helpers/crm-v2/billing-account.helper.js') +const BillingAccountHelper = require('../../../support/helpers/billing-account.helper.js') const DatabaseHelper = require('../../../support/helpers/database.helper.js') // Thing under test @@ -27,9 +27,9 @@ describe('Generate Bill service', () => { billingAccount = await BillingAccountHelper.add() expectedResult = { - invoiceAccountId: billingAccount.invoiceAccountId, + invoiceAccountId: billingAccount.id, address: {}, - invoiceAccountNumber: billingAccount.invoiceAccountNumber, + invoiceAccountNumber: billingAccount.accountNumber, billingBatchId: billRunId, financialYearEnding, isCredit: false diff --git a/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js b/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js index e09386ea8d..b045b1ba1c 100644 --- a/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js +++ b/test/services/bill-runs/supplementary/pre-generate-billing-data.service.test.js @@ -23,12 +23,12 @@ describe('Pre-generate billing data service', () => { const billingAccounts = [ { - invoiceAccountId: '235bae72-01f7-4a21-b8a3-d2b5fb2eff91', - invoiceAccountNumber: 'T12345678A' + id: '235bae72-01f7-4a21-b8a3-d2b5fb2eff91', + accountNumber: 'T12345678A' }, { - invoiceAccountId: '1d407b9c-457a-487d-bfe1-a54b72ef0bb5', - invoiceAccountNumber: 'T87654321A' + id: '1d407b9c-457a-487d-bfe1-a54b72ef0bb5', + accountNumber: 'T87654321A' } ] @@ -46,10 +46,10 @@ describe('Pre-generate billing data service', () => { describe('when the service is called', () => { beforeEach(async () => { chargeVersions = [ - { invoiceAccountId: billingAccounts[0].invoiceAccountId, licence: licences[0] }, - { invoiceAccountId: billingAccounts[1].invoiceAccountId, licence: licences[0] }, - { invoiceAccountId: billingAccounts[1].invoiceAccountId, licence: licences[1] }, - { invoiceAccountId: billingAccounts[1].invoiceAccountId, licence: licences[1] } + { invoiceAccountId: billingAccounts[0].id, licence: licences[0] }, + { invoiceAccountId: billingAccounts[1].id, licence: licences[0] }, + { invoiceAccountId: billingAccounts[1].id, licence: licences[1] }, + { invoiceAccountId: billingAccounts[1].id, licence: licences[1] } ] Sinon.stub(FetchBillingAccountsService, 'go').resolves(billingAccounts) @@ -63,7 +63,7 @@ describe('Pre-generate billing data service', () => { expect(keys).to.have.length(2) }) - it('is keyed with the invoice account id', async () => { + it('is keyed with the billing account id', async () => { const { bills: result } = await PreGenerateBillingDataService.go(chargeVersions, billRunId, billingPeriod) const entries = Object.entries(result) @@ -79,10 +79,10 @@ describe('Pre-generate billing data service', () => { const entries = Object.entries(result) entries.forEach(([key, value]) => { - const matchingInvoiceAccount = billingAccounts.find((billingAccount) => { - return key === billingAccount.invoiceAccountId + const matchingBillingAccount = billingAccounts.find((billingAccount) => { + return key === billingAccount.id }) - expect(value.invoiceAccountNumber).to.equal(matchingInvoiceAccount.invoiceAccountNumber) + expect(value.invoiceAccountNumber).to.equal(matchingBillingAccount.accountNumber) }) }) }) diff --git a/test/services/billing-accounts/change-address.service.test.js b/test/services/billing-accounts/change-address.service.test.js index 2493bfdba3..a6656494bc 100644 --- a/test/services/billing-accounts/change-address.service.test.js +++ b/test/services/billing-accounts/change-address.service.test.js @@ -9,14 +9,14 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const AddressHelper = require('../../support/helpers/crm-v2/address.helper.js') -const AddressModel = require('../../../app/models/crm-v2/address.model.js') -const BillingAccountAddressHelper = require('../../support/helpers/crm-v2/billing-account-address.helper.js') -const BillingAccountAddressModel = require('../../../app/models/crm-v2/billing-account-address.model.js') -const BillingAccountHelper = require('../../support/helpers/crm-v2/billing-account.helper.js') -const CompanyHelper = require('../../support/helpers/crm-v2/company.helper.js') -const CompanyModel = require('../../../app/models/crm-v2/company.model.js') -const ContactModel = require('../../../app/models/crm-v2/contact.model.js') +const AddressHelper = require('../../support/helpers/address.helper.js') +const AddressModel = require('../../../app/models/address.model.js') +const BillingAccountAddressHelper = require('../../support/helpers/billing-account-address.helper.js') +const BillingAccountAddressModel = require('../../../app/models/billing-account-address.model.js') +const BillingAccountHelper = require('../../support/helpers/billing-account.helper.js') +const CompanyHelper = require('../../support/helpers/company.helper.js') +const CompanyModel = require('../../../app/models/company.model.js') +const ContactModel = require('../../../app/models/contact.model.js') const DatabaseHelper = require('../../support/helpers/database.helper.js') // Things we need to stub @@ -48,7 +48,7 @@ describe('Change address service', () => { const contactIndividual = { type: 'person', firstName: 'Margherita', lastName: 'Villar' } - const invoiceAccountId = '2e72bd15-1412-4329-bf92-5217f83d19c0' + const billingAccountId = '2e72bd15-1412-4329-bf92-5217f83d19c0' let address let agentCompany @@ -58,7 +58,7 @@ describe('Change address service', () => { beforeEach(async () => { await DatabaseHelper.clean() - billingAccount = await BillingAccountHelper.add({ invoiceAccountId }) + billingAccount = await BillingAccountHelper.add({ id: billingAccountId }) }) afterEach(() => { @@ -76,11 +76,11 @@ describe('Change address service', () => { }) it('creates the billing account address and address records and handles the null agent and contact', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const newAddress = await AddressModel.query().first() - expect(result.invoiceAccountAddress.addressId).to.equal(newAddress.addressId) + expect(result.billingAccountAddress.addressId).to.equal(newAddress.id) expect(result.address.address1).to.equal('62 High St') expect(result.agentCompany).to.be.null() expect(result.contact).to.be.null() @@ -102,26 +102,26 @@ describe('Change address service', () => { }) it('overwrites the existing address with the latest OS Places details', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const reFetchedExistingAddress = await existingAddress.$query() - expect(reFetchedExistingAddress.addressId).to.equal(existingAddress.addressId) + expect(reFetchedExistingAddress.id).to.equal(existingAddress.id) expect(reFetchedExistingAddress.createdAt).to.equal(existingAddress.createdAt) expect(reFetchedExistingAddress.address1).to.equal(address.addressLine1) expect(reFetchedExistingAddress.updatedAt).not.to.equal(existingAddress.updatedAt) }) it('links the billing account address record to the existing address', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - expect(result.invoiceAccountAddress.addressId).to.equal(existingAddress.addressId) + expect(result.billingAccountAddress.addressId).to.equal(existingAddress.id) }) }) describe('and a matching address does not exist', () => { it('creates a new address record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const result = await AddressModel.query() @@ -131,11 +131,11 @@ describe('Change address service', () => { }) it('links the billing account address record to the new address', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const newAddress = await AddressModel.query().first() - expect(result.invoiceAccountAddress.addressId).to.equal(newAddress.addressId) + expect(result.billingAccountAddress.addressId).to.equal(newAddress.id) }) }) }) @@ -146,7 +146,7 @@ describe('Change address service', () => { }) it('creates a new address record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const result = await AddressModel.query() @@ -155,11 +155,11 @@ describe('Change address service', () => { }) it('links the billing account address record to the new address', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const newAddress = await AddressModel.query().first() - expect(result.invoiceAccountAddress.addressId).to.equal(newAddress.addressId) + expect(result.billingAccountAddress.addressId).to.equal(newAddress.id) }) }) @@ -169,24 +169,24 @@ describe('Change address service', () => { beforeEach(async () => { existingAddress = await AddressHelper.add() - address = { addressId: existingAddress.addressId } + address = { addressId: existingAddress.id } }) it('makes no changes to the existing address record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const reFetchedExistingAddress = await existingAddress.$query() - expect(reFetchedExistingAddress.addressId).to.equal(existingAddress.addressId) + expect(reFetchedExistingAddress.id).to.equal(existingAddress.id) expect(reFetchedExistingAddress.address1).to.equal(existingAddress.address1) expect(reFetchedExistingAddress.createdAt).to.equal(existingAddress.createdAt) expect(reFetchedExistingAddress.updatedAt).to.equal(existingAddress.updatedAt) }) it('links the billing account address record to the existing address', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - expect(result.invoiceAccountAddress.addressId).to.equal(existingAddress.addressId) + expect(result.billingAccountAddress.addressId).to.equal(existingAddress.id) }) }) }) @@ -206,26 +206,26 @@ describe('Change address service', () => { }) it('overwrites the existing company with the latest Companies House details', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const reFetchedExistingCompany = await existingCompany.$query() - expect(reFetchedExistingCompany.companyId).to.equal(existingCompany.companyId) + expect(reFetchedExistingCompany.id).to.equal(existingCompany.id) expect(reFetchedExistingCompany.createdAt).to.equal(existingCompany.createdAt) expect(reFetchedExistingCompany.name).to.equal(agentCompany.name) expect(reFetchedExistingCompany.updatedAt).not.to.equal(existingCompany.updatedAt) }) it('links the billing account address record to the existing company', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - expect(result.invoiceAccountAddress.agentCompanyId).to.equal(existingCompany.companyId) + expect(result.billingAccountAddress.companyId).to.equal(existingCompany.id) }) }) describe('has a company number that does not match an existing record', () => { it('creates a new company record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const result = await CompanyModel.query() @@ -235,11 +235,11 @@ describe('Change address service', () => { }) it('links the billing account address record to the new company', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const newCompany = await CompanyModel.query().first() - expect(result.invoiceAccountAddress.agentCompanyId).to.equal(newCompany.companyId) + expect(result.billingAccountAddress.companyId).to.equal(newCompany.id) }) }) @@ -249,24 +249,24 @@ describe('Change address service', () => { beforeEach(async () => { existingCompany = await CompanyHelper.add() - agentCompany = { companyId: existingCompany.companyId } + agentCompany = { companyId: existingCompany.id } }) it('makes no changes to the existing company record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const reFetchedExistingCompany = await existingCompany.$query() - expect(reFetchedExistingCompany.companyId).to.equal(existingCompany.companyId) + expect(reFetchedExistingCompany.id).to.equal(existingCompany.id) expect(reFetchedExistingCompany.name).to.equal(existingCompany.name) expect(reFetchedExistingCompany.createdAt).to.equal(existingCompany.createdAt) expect(reFetchedExistingCompany.updatedAt).to.equal(existingCompany.updatedAt) }) it('links the billing account address record to the existing company', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - expect(result.invoiceAccountAddress.agentCompanyId).to.equal(existingCompany.companyId) + expect(result.billingAccountAddress.companyId).to.equal(existingCompany.id) }) }) }) @@ -282,7 +282,7 @@ describe('Change address service', () => { }) it('creates a new contact record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const result = await ContactModel.query() @@ -291,11 +291,11 @@ describe('Change address service', () => { }) it('links the billing account address record to the new contact', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const newContact = await ContactModel.query().first() - expect(result.invoiceAccountAddress.contactId).to.equal(newContact.contactId) + expect(result.billingAccountAddress.contactId).to.equal(newContact.id) }) }) @@ -305,7 +305,7 @@ describe('Change address service', () => { }) it('creates a new contact record', async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const result = await ContactModel.query() @@ -315,18 +315,18 @@ describe('Change address service', () => { }) it('links the billing account address record to the new contact', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) const newContact = await ContactModel.query().first() - expect(result.invoiceAccountAddress.contactId).to.equal(newContact.contactId) + expect(result.billingAccountAddress.contactId).to.equal(newContact.id) }) }) }) describe("and the 'current' billing account address", () => { let clock - let existingInvoiceAccountAddress + let existingBillingAccountAddress beforeEach(() => { address = { ...addressFromManual } @@ -345,8 +345,8 @@ describe('Change address service', () => { const startDate = new Date(2023, 8, 4) const timestamp = new Date(2023, 8, 4, 9, 22, 57, 13) - existingInvoiceAccountAddress = await BillingAccountAddressHelper.add({ - invoiceAccountId, + existingBillingAccountAddress = await BillingAccountAddressHelper.add({ + billingAccountId, startDate, createdAt: timestamp, updatedAt: timestamp @@ -354,17 +354,17 @@ describe('Change address service', () => { }) it('overwrites the existing record and ensures the end date is null', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - const newInvoiceAccountAddress = await BillingAccountAddressModel.query() - .findById(result.invoiceAccountAddress.invoiceAccountAddressId) + const newBillingAccountAddress = await BillingAccountAddressModel.query() + .findById(result.billingAccountAddress.id) - expect(newInvoiceAccountAddress.invoiceAccountAddressId) - .to.equal(existingInvoiceAccountAddress.invoiceAccountAddressId) - expect(newInvoiceAccountAddress.addressId).not.to.equal(existingInvoiceAccountAddress.addressId) - expect(newInvoiceAccountAddress.endDate).to.be.null() - expect(newInvoiceAccountAddress.createdAt).to.equal(existingInvoiceAccountAddress.createdAt) - expect(newInvoiceAccountAddress.updatedAt).to.be.above(existingInvoiceAccountAddress.updatedAt) + expect(newBillingAccountAddress.id) + .to.equal(existingBillingAccountAddress.id) + expect(newBillingAccountAddress.addressId).not.to.equal(existingBillingAccountAddress.addressId) + expect(newBillingAccountAddress.endDate).to.be.null() + expect(newBillingAccountAddress.createdAt).to.equal(existingBillingAccountAddress.createdAt) + expect(newBillingAccountAddress.updatedAt).to.be.above(existingBillingAccountAddress.updatedAt) }) }) @@ -373,8 +373,8 @@ describe('Change address service', () => { const startDate = new Date(2023, 7, 3) const timestamp = new Date(2023, 7, 3, 14, 46, 3, 18) - existingInvoiceAccountAddress = await BillingAccountAddressHelper.add({ - invoiceAccountId, + existingBillingAccountAddress = await BillingAccountAddressHelper.add({ + billingAccountId, startDate, createdAt: timestamp, updatedAt: timestamp @@ -382,27 +382,27 @@ describe('Change address service', () => { }) it('creates a new billing account record with a null end date', async () => { - const result = await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + const result = await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - const newInvoiceAccountAddress = await BillingAccountAddressModel.query() - .findById(result.invoiceAccountAddress.invoiceAccountAddressId) + const newBillingAccountAddress = await BillingAccountAddressModel.query() + .findById(result.billingAccountAddress.id) - expect(newInvoiceAccountAddress.invoiceAccountAddressId) - .not.to.equal(existingInvoiceAccountAddress.invoiceAccountAddressId) - expect(newInvoiceAccountAddress.addressId).not.to.equal(existingInvoiceAccountAddress.addressId) - expect(newInvoiceAccountAddress.endDate).to.be.null() - expect(newInvoiceAccountAddress.createdAt).to.be.above(existingInvoiceAccountAddress.createdAt) - expect(newInvoiceAccountAddress.updatedAt).to.be.above(existingInvoiceAccountAddress.updatedAt) + expect(newBillingAccountAddress.id) + .not.to.equal(existingBillingAccountAddress.id) + expect(newBillingAccountAddress.addressId).not.to.equal(existingBillingAccountAddress.addressId) + expect(newBillingAccountAddress.endDate).to.be.null() + expect(newBillingAccountAddress.createdAt).to.be.above(existingBillingAccountAddress.createdAt) + expect(newBillingAccountAddress.updatedAt).to.be.above(existingBillingAccountAddress.updatedAt) }) it("updates the end date of the existing record to yesterday's date", async () => { - await ChangeAddressService.go(invoiceAccountId, address, agentCompany, contact) + await ChangeAddressService.go(billingAccountId, address, agentCompany, contact) - const reFetchedExistingInvoiceAccountAddress = await existingInvoiceAccountAddress.$query() + const reFetchedExistingInvoiceAccountAddress = await existingBillingAccountAddress.$query() const yesterday = new Date(2023, 8, 3) expect(reFetchedExistingInvoiceAccountAddress.endDate).to.equal(yesterday) - expect(reFetchedExistingInvoiceAccountAddress.updatedAt).to.be.above(existingInvoiceAccountAddress.updatedAt) + expect(reFetchedExistingInvoiceAccountAddress.updatedAt).to.be.above(existingBillingAccountAddress.updatedAt) }) }) }) diff --git a/test/services/bills/fetch-billing-account.service.test.js b/test/services/bills/fetch-billing-account.service.test.js index a96782a9ba..fa061fbe0f 100644 --- a/test/services/bills/fetch-billing-account.service.test.js +++ b/test/services/bills/fetch-billing-account.service.test.js @@ -8,16 +8,16 @@ const { describe, it, beforeEach } = exports.lab = Lab.script() const { expect } = Code // Test helpers -const AddressHelper = require('../../support/helpers/crm-v2/address.helper.js') -const AddressModel = require('../../../app/models/crm-v2/address.model.js') -const BillingAccountAddressHelper = require('../../support/helpers/crm-v2/billing-account-address.helper.js') -const BillingAccountAddressModel = require('../../../app/models/crm-v2/billing-account-address.model.js') -const BillingAccountHelper = require('../../support/helpers/crm-v2/billing-account.helper.js') -const BillingAccountModel = require('../../../app/models/crm-v2/billing-account.model.js') -const CompanyHelper = require('../../support/helpers/crm-v2/company.helper.js') -const CompanyModel = require('../../../app/models/crm-v2/company.model.js') -const ContactHelper = require('../../support/helpers/crm-v2/contact.helper.js') -const ContactModel = require('../../../app/models/crm-v2/contact.model.js') +const AddressHelper = require('../../support/helpers/address.helper.js') +const AddressModel = require('../../../app/models/address.model.js') +const BillingAccountAddressHelper = require('../../support/helpers/billing-account-address.helper.js') +const BillingAccountAddressModel = require('../../../app/models/billing-account-address.model.js') +const BillingAccountHelper = require('../../support/helpers/billing-account.helper.js') +const BillingAccountModel = require('../../../app/models/billing-account.model.js') +const CompanyHelper = require('../../support/helpers/company.helper.js') +const CompanyModel = require('../../../app/models/company.model.js') +const ContactHelper = require('../../support/helpers/contact.helper.js') +const ContactModel = require('../../../app/models/contact.model.js') const DatabaseHelper = require('../../support/helpers/database.helper.js') // Thing under test @@ -32,7 +32,7 @@ describe('Fetch Billing Account service', () => { linkedCompany = await CompanyHelper.add() - testBillingAccount = await BillingAccountHelper.add({ companyId: linkedCompany.companyId }) + testBillingAccount = await BillingAccountHelper.add({ companyId: linkedCompany.id }) }) describe('when a billing account with a matching ID exists', () => { @@ -40,21 +40,21 @@ describe('Fetch Billing Account service', () => { let linkedAddress beforeEach(async () => { - const { invoiceAccountId } = testBillingAccount + const { id: billingAccountId } = testBillingAccount linkedAddress = await AddressHelper.add() - const { addressId } = linkedAddress + const { id: addressId } = linkedAddress await Promise.all([ - BillingAccountAddressHelper.add({ invoiceAccountId, addressId, endDate: new Date('2023-09-18') }), - BillingAccountAddressHelper.add({ invoiceAccountId, addressId, startDate: new Date('2023-09-19') }) + BillingAccountAddressHelper.add({ billingAccountId, addressId, endDate: new Date('2023-09-18') }), + BillingAccountAddressHelper.add({ billingAccountId, addressId, startDate: new Date('2023-09-19') }) ]) }) it('only returns the current one', async () => { - const result = await FetchBillingAccountService.go(testBillingAccount.invoiceAccountId) + const result = await FetchBillingAccountService.go(testBillingAccount.id) - expect(result.invoiceAccountId).to.equal(testBillingAccount.invoiceAccountId) + expect(result.id).to.equal(testBillingAccount.id) expect(result).to.be.an.instanceOf(BillingAccountModel) expect(result.billingAccountAddresses).to.have.length(1) @@ -64,14 +64,14 @@ describe('Fetch Billing Account service', () => { // All account address records are linked to an address it('returns details for the linked address', async () => { - const result = await FetchBillingAccountService.go(testBillingAccount.invoiceAccountId) + const result = await FetchBillingAccountService.go(testBillingAccount.id) - expect(result.invoiceAccountId).to.equal(testBillingAccount.invoiceAccountId) + expect(result.id).to.equal(testBillingAccount.id) expect(result).to.be.an.instanceOf(BillingAccountModel) const returnedAddress = result.billingAccountAddresses[0].address - expect(returnedAddress.addressId).to.equal(linkedAddress.addressId) + expect(returnedAddress.id).to.equal(linkedAddress.id) expect(returnedAddress).to.be.an.instanceof(AddressModel) }) }) @@ -81,21 +81,21 @@ describe('Fetch Billing Account service', () => { let linkedAgentCompany beforeEach(async () => { - const { invoiceAccountId } = testBillingAccount + const { id: billingAccountId } = testBillingAccount linkedAgentCompany = await CompanyHelper.add() - await BillingAccountAddressHelper.add({ invoiceAccountId, agentCompanyId: linkedAgentCompany.companyId }) + await BillingAccountAddressHelper.add({ billingAccountId, companyId: linkedAgentCompany.id }) }) it('returns details for the linked agent company', async () => { - const result = await FetchBillingAccountService.go(testBillingAccount.invoiceAccountId) + const result = await FetchBillingAccountService.go(testBillingAccount.id) - expect(result.invoiceAccountId).to.equal(testBillingAccount.invoiceAccountId) + expect(result.id).to.equal(testBillingAccount.id) expect(result).to.be.an.instanceOf(BillingAccountModel) - const returnedAgentCompany = result.billingAccountAddresses[0].agentCompany + const returnedAgentCompany = result.billingAccountAddresses[0].company - expect(returnedAgentCompany.companyId).to.equal(linkedAgentCompany.companyId) + expect(returnedAgentCompany.id).to.equal(linkedAgentCompany.id) expect(returnedAgentCompany).to.be.an.instanceof(CompanyModel) }) }) @@ -105,35 +105,35 @@ describe('Fetch Billing Account service', () => { let linkedContact beforeEach(async () => { - const { invoiceAccountId } = testBillingAccount + const { id: billingAccountId } = testBillingAccount linkedContact = await ContactHelper.add() - await BillingAccountAddressHelper.add({ invoiceAccountId, contactId: linkedContact.contactId }) + await BillingAccountAddressHelper.add({ billingAccountId, contactId: linkedContact.id }) }) it('returns details for the linked contact', async () => { - const result = await FetchBillingAccountService.go(testBillingAccount.invoiceAccountId) + const result = await FetchBillingAccountService.go(testBillingAccount.id) - expect(result.invoiceAccountId).to.equal(testBillingAccount.invoiceAccountId) + expect(result.id).to.equal(testBillingAccount.id) expect(result).to.be.an.instanceOf(BillingAccountModel) const returnedContact = result.billingAccountAddresses[0].contact - expect(returnedContact.contactId).to.equal(linkedContact.contactId) + expect(returnedContact.id).to.equal(linkedContact.id) expect(returnedContact).to.be.an.instanceof(ContactModel) }) }) // All billing account records have a linked company it('returns details for the linked company', async () => { - const result = await FetchBillingAccountService.go(testBillingAccount.invoiceAccountId) + const result = await FetchBillingAccountService.go(testBillingAccount.id) - expect(result.invoiceAccountId).to.equal(testBillingAccount.invoiceAccountId) + expect(result.id).to.equal(testBillingAccount.id) expect(result).to.be.an.instanceOf(BillingAccountModel) const returnedCompany = result.company - expect(returnedCompany.contactId).to.equal(returnedCompany.companyId) + expect(returnedCompany.id).to.equal(returnedCompany.id) expect(returnedCompany).to.be.an.instanceof(CompanyModel) }) })