diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 379f85f3eb..1ac603a2f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -739,7 +739,6 @@ jobs: 'your-business/alternative-trading-address/**/*.spec.js', 'your-business/change-your-answers/**/*.spec.js', 'your-business/check-your-answers/**/*.spec.js', - 'your-business/companies-house-number/*.spec.js', 'your-business/company-details/**/*.spec.js', 'your-business/credit-control/**/*.spec.js', 'your-business/nature-of-business/**/*.spec.js', diff --git a/e2e-tests/constants/routes/insurance/business.js b/e2e-tests/constants/routes/insurance/business.js index f64aaedccc..454a6c8379 100644 --- a/e2e-tests/constants/routes/insurance/business.js +++ b/e2e-tests/constants/routes/insurance/business.js @@ -14,7 +14,6 @@ export const EXPORTER_BUSINESS = { COMPANY_DETAILS_CHANGE: `${COMPANY_DETAILS_ROOT}/change`, COMPANY_DETAILS_CHECK_AND_CHANGE: `${COMPANY_DETAILS_ROOT}/check-and-change`, COMPANY_DETAILS_SAVE_AND_BACK: `${COMPANY_DETAILS_ROOT}/save-and-back`, - ENTER_COMPANIES_HOUSE_NUMBER: `${ROOT}/enter-companies-house-number`, ALTERNATIVE_TRADING_ADDRESS_ROOT, ALTERNATIVE_TRADING_ADDRESS_CHANGE: `${ALTERNATIVE_TRADING_ADDRESS_ROOT}/change`, ALTERNATIVE_TRADING_ADDRESS_CHECK_AND_CHANGE: `${ALTERNATIVE_TRADING_ADDRESS_ROOT}/check-and-change`, diff --git a/e2e-tests/content-strings/pages/insurance/business/index.js b/e2e-tests/content-strings/pages/insurance/business/index.js index 115be97fb8..d631c40594 100644 --- a/e2e-tests/content-strings/pages/insurance/business/index.js +++ b/e2e-tests/content-strings/pages/insurance/business/index.js @@ -12,11 +12,6 @@ export const ROOT = { OUTRO: 'It should only take a few minutes to complete.', }; -export const ENTER_COMPANIES_HOUSE_NUMBER = { - ...SHARED, - PAGE_TITLE: 'Enter your Companies House registration number (CRN)', -}; - export const COMPANY_DETAILS = { ...SHARED, PAGE_TITLE: 'Your company details', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/your-business/companies-house-number/companies-house-number-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/your-business/companies-house-number/companies-house-number-page.spec.js deleted file mode 100644 index 65d2c6d51c..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/your-business/companies-house-number/companies-house-number-page.spec.js +++ /dev/null @@ -1,72 +0,0 @@ -import partials from '../../../../../../partials'; -import { field as fieldSelector } from '../../../../../../pages/shared'; -import { PAGES } from '../../../../../../content-strings'; -import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; -import { INSURANCE_FIELD_IDS } from '../../../../../../constants/field-ids/insurance'; - -const { - ROOT, - EXPORTER_BUSINESS: { ENTER_COMPANIES_HOUSE_NUMBER }, -} = INSURANCE_ROUTES; - -const CONTENT_STRINGS = PAGES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER; - -const { - ELIGIBILITY: { COMPANIES_HOUSE_NUMBER: FIELD_ID }, -} = INSURANCE_FIELD_IDS; - -const field = fieldSelector(FIELD_ID); - -const baseUrl = Cypress.config('baseUrl'); - -context( - 'Insurance - Your business - Enter Companies House number - As an Exporter, I want to enter my Companies House number, So that I can apply for credit insurance with UKEF', - () => { - let referenceNumber; - let url; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.startYourBusinessSection({}); - - url = `${baseUrl}${ROOT}/${referenceNumber}${ENTER_COMPANIES_HOUSE_NUMBER}`; - - cy.navigateToUrl(url); - - cy.assertUrl(url); - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('renders core page elements', () => { - cy.corePageChecks({ - pageTitle: CONTENT_STRINGS.PAGE_TITLE, - currentHref: `${ROOT}/${referenceNumber}${ENTER_COMPANIES_HOUSE_NUMBER}`, - backLink: `${ROOT}/${referenceNumber}${ENTER_COMPANIES_HOUSE_NUMBER}#`, - }); - }); - - describe('page tests', () => { - beforeEach(() => { - cy.navigateToUrl(url); - }); - - it('renders a heading caption', () => { - cy.checkText(partials.headingCaption(), CONTENT_STRINGS.HEADING_CAPTION); - }); - - it(`should render a ${FIELD_ID} input`, () => { - field.input().should('exist'); - }); - }); - }, -); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/your-business/companies-house-number/companies-house-number-search.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/your-business/companies-house-number/companies-house-number-search.spec.js deleted file mode 100644 index 64f2db9316..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/your-business/companies-house-number/companies-house-number-search.spec.js +++ /dev/null @@ -1,217 +0,0 @@ -import { field as fieldSelector } from '../../../../../../pages/shared'; -import { ERROR_MESSAGES } from '../../../../../../content-strings'; -import { - COMPANIES_HOUSE_NUMBER as VALID_COMPANIES_HOUSE_NUMBER, - COMPANIES_HOUSE_NUMBER_NO_LEADING_ZERO, - COMPANIES_HOUSE_NUMBER_EMPTY, - COMPANIES_HOUSE_NUMBER_TOO_SHORT, - COMPANIES_HOUSE_NUMBER_WITH_SPECIAL_CHARACTERS, - COMPANIES_HOUSE_NUMBER_WITH_SPACES, - COMPANIES_HOUSE_NUMBER_NO_FINANCIAL_YEAR_END_DATE, - COMPANIES_HOUSE_NUMBER_NOT_FOUND, -} from '../../../../../../constants'; -import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; -import { INSURANCE_FIELD_IDS } from '../../../../../../constants/field-ids/insurance'; - -const { - ROOT, - EXPORTER_BUSINESS: { ENTER_COMPANIES_HOUSE_NUMBER, COMPANY_DETAILS }, -} = INSURANCE_ROUTES; - -const COMPANIES_HOUSE_ERRORS = ERROR_MESSAGES.INSURANCE.ELIGIBILITY; - -const { - ELIGIBILITY: { COMPANIES_HOUSE_NUMBER: FIELD_ID }, -} = INSURANCE_FIELD_IDS; - -const field = fieldSelector(FIELD_ID); - -const baseUrl = Cypress.config('baseUrl'); - -context( - 'Insurance - Your business - Enter Companies House number - As an Exporter, I want to enter my Companies House number, So that I can apply for credit insurance with UKEF', - () => { - let referenceNumber; - let url; - let companyNumber; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.startYourBusinessSection({}); - - url = `${baseUrl}${ROOT}/${referenceNumber}${ENTER_COMPANIES_HOUSE_NUMBER}`; - - cy.navigateToUrl(url); - cy.assertUrl(url); - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe('form submission', () => { - describe('when submitting an empty form', () => { - beforeEach(() => { - cy.navigateToUrl(url); - }); - - it('should display the `is empty` error', () => { - cy.submitAndAssertFieldErrors({ - field, - value: companyNumber, - expectedErrorMessage: COMPANIES_HOUSE_ERRORS[FIELD_ID].IS_EMPTY, - }); - }); - }); - - describe('when the companies house number is empty', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - companyNumber = COMPANIES_HOUSE_NUMBER_EMPTY; - }); - - it('should display the `is empty` error', () => { - cy.submitAndAssertFieldErrors({ - field, - value: companyNumber, - expectedErrorMessage: COMPANIES_HOUSE_ERRORS[FIELD_ID].IS_EMPTY, - }); - }); - }); - - describe('when the companies house number is too short', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - companyNumber = COMPANIES_HOUSE_NUMBER_TOO_SHORT; - }); - - it('should display the `incorrect format` error', () => { - cy.submitAndAssertFieldErrors({ - field, - value: companyNumber, - expectedErrorMessage: COMPANIES_HOUSE_ERRORS[FIELD_ID].INCORRECT_FORMAT, - }); - }); - }); - - describe('when the companies house number has special characters', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - companyNumber = COMPANIES_HOUSE_NUMBER_WITH_SPECIAL_CHARACTERS; - - cy.interceptCompaniesHousePost({ companyNumber }); - }); - - it('should display the `incorrect format` error', () => { - cy.submitAndAssertFieldErrors({ - field, - value: companyNumber, - expectedErrorMessage: COMPANIES_HOUSE_ERRORS[FIELD_ID].INCORRECT_FORMAT, - }); - }); - }); - - describe('when the companies house number is not found', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - companyNumber = COMPANIES_HOUSE_NUMBER_NOT_FOUND; - - cy.interceptCompaniesHousePost({ companyNumber }); - }); - - it('should display the `not found` error', () => { - cy.submitAndAssertFieldErrors({ - field, - value: companyNumber, - expectedErrorMessage: COMPANIES_HOUSE_ERRORS[FIELD_ID].NOT_FOUND, - }); - }); - }); - - describe('when submitting the answer as a valid companies house number', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - cy.interceptCompaniesHousePost({ companyNumber }); - - cy.keyboardInput(field.input(), VALID_COMPANIES_HOUSE_NUMBER); - - cy.clickSubmitButton(); - }); - - it(`should redirect to ${COMPANY_DETAILS}`, () => { - const expected = `${baseUrl}${ROOT}/${referenceNumber}${COMPANY_DETAILS}`; - - cy.assertUrl(expected); - }); - }); - - describe('when submitting the answer as a valid companies house number, with no leading zero', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - cy.interceptCompaniesHousePost({ companyNumber: COMPANIES_HOUSE_NUMBER_NO_LEADING_ZERO }); - - cy.keyboardInput(field.input(), COMPANIES_HOUSE_NUMBER_NO_LEADING_ZERO); - - cy.clickSubmitButton(); - }); - - it(`should redirect to ${COMPANY_DETAILS}`, () => { - const expected = `${baseUrl}${ROOT}/${referenceNumber}${COMPANY_DETAILS}`; - - cy.assertUrl(expected); - }); - }); - - describe('when submitting the answer as a valid companies house number, with white spaces', () => { - beforeEach(() => { - cy.navigateToUrl(url); - - cy.interceptCompaniesHousePost({ companyNumber: COMPANIES_HOUSE_NUMBER_WITH_SPACES }); - - cy.keyboardInput(field.input(), COMPANIES_HOUSE_NUMBER_WITH_SPACES); - - cy.clickSubmitButton(); - }); - - it(`should redirect to ${COMPANY_DETAILS}`, () => { - const expected = `${baseUrl}${ROOT}/${referenceNumber}${COMPANY_DETAILS}`; - - cy.assertUrl(expected); - }); - }); - - describe('when submitting the answer as a valid companies house number, in lowercase', () => { - const lowerCaseCompaniesHouseNumber = COMPANIES_HOUSE_NUMBER_NO_FINANCIAL_YEAR_END_DATE.toLowerCase(); - - beforeEach(() => { - cy.navigateToUrl(url); - - cy.interceptCompaniesHousePost({ companyNumber: lowerCaseCompaniesHouseNumber }); - - cy.keyboardInput(field.input(), lowerCaseCompaniesHouseNumber); - - cy.clickSubmitButton(); - }); - - it(`should redirect to ${COMPANY_DETAILS}`, () => { - const expected = `${baseUrl}${ROOT}/${referenceNumber}${COMPANY_DETAILS}`; - - cy.assertUrl(expected); - }); - }); - }); - }, -); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 808e9711cd..7641ab0db8 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -604,7 +604,6 @@ var CUSTOM_RESOLVERS = [ 'getCompaniesHouseInformation', 'getApplicationByReferenceNumber', 'submitApplication', - 'updateCompanyPostDataMigration', // feedback 'createFeedbackAndSendEmail', 'getApimCisCountries', @@ -3009,12 +3008,6 @@ var typeDefs = ` iban: String bicSwiftCode: String ): SuccessResponse - - """ update a company (post data migration) """ - updateCompanyPostDataMigration( - id: String - company: CompanyInput - ): SuccessResponse } type Query { @@ -8603,42 +8596,6 @@ var verifyAccountReactivationToken = async (root, variables, context) => { }; var verify_account_reactivation_token_default = verifyAccountReactivationToken; -// custom-resolvers/mutations/update-company-post-data-migration/index.ts -var updateCompanyPostDataMigration = async (root, variables, context) => { - try { - console.info('Updating company (post data migration) %s', variables.id); - const { id, company } = variables; - const { registeredOfficeAddress, industrySectorNames: industrySectorNames2, sicCodes, ...otherFields } = company; - const updatedCompany = await context.db.Company.updateOne({ - where: { - id, - }, - data: otherFields, - }); - const { id: addressId, ...addressFields } = registeredOfficeAddress; - if (!updatedCompany.registeredOfficeAddressId) { - console.error('Unable to update company address - does not exist (post data migration) %o', id); - throw new Error(`Unable to update company address - does not exist (post data migration) ${id}`); - } - await context.db.CompanyAddress.updateOne({ - where: { - id: updatedCompany.registeredOfficeAddressId, - }, - data: addressFields, - }); - if (sicCodes) { - await create_company_sic_codes_default(context, updatedCompany.id, sicCodes, industrySectorNames2); - } - return { - success: true, - }; - } catch (error) { - console.error('Error updating company (post data migration) %o', error); - throw new Error(`Updating company (post data migration) ${error}`); - } -}; -var update_company_post_data_migration_default = updateCompanyPostDataMigration; - // helpers/encrypt/index.ts var import_crypto12 = __toESM(require('crypto')); @@ -9523,7 +9480,6 @@ var customResolvers = { submitApplication: submit_application_default, createFeedbackAndSendEmail: create_feedback_default, verifyAccountReactivationToken: verify_account_reactivation_token_default, - updateCompanyPostDataMigration: update_company_post_data_migration_default, updateLossPayeeFinancialDetailsUk: update_loss_payee_financial_details_uk_default, updateLossPayeeFinancialDetailsInternational: update_loss_payee_financial_details_international_default, }, diff --git a/src/api/constants/allowed-graphql-resolvers/index.ts b/src/api/constants/allowed-graphql-resolvers/index.ts index 08bfbbc3d3..2531424ae6 100644 --- a/src/api/constants/allowed-graphql-resolvers/index.ts +++ b/src/api/constants/allowed-graphql-resolvers/index.ts @@ -70,7 +70,6 @@ const CUSTOM_RESOLVERS = [ 'getCompaniesHouseInformation', 'getApplicationByReferenceNumber', 'submitApplication', - 'updateCompanyPostDataMigration', // feedback 'createFeedbackAndSendEmail', diff --git a/src/api/custom-resolvers/index.ts b/src/api/custom-resolvers/index.ts index 6bbc42d639..cc012e95a3 100644 --- a/src/api/custom-resolvers/index.ts +++ b/src/api/custom-resolvers/index.ts @@ -17,7 +17,6 @@ import { submitApplication, createFeedbackAndSendEmail, verifyAccountReactivationToken, - updateCompanyPostDataMigration, updateLossPayeeFinancialDetailsUk, updateLossPayeeFinancialDetailsInternational, } from './mutations'; @@ -58,7 +57,6 @@ const customResolvers = { submitApplication, createFeedbackAndSendEmail, verifyAccountReactivationToken, - updateCompanyPostDataMigration, updateLossPayeeFinancialDetailsUk, updateLossPayeeFinancialDetailsInternational, }, diff --git a/src/api/custom-resolvers/mutations/index.ts b/src/api/custom-resolvers/mutations/index.ts index 7aa1a13d59..9d2385b1d6 100644 --- a/src/api/custom-resolvers/mutations/index.ts +++ b/src/api/custom-resolvers/mutations/index.ts @@ -16,7 +16,6 @@ import deleteApplicationByReferenceNumber from './delete-application-by-referenc import submitApplication from './submit-application'; import createFeedbackAndSendEmail from './create-feedback'; import verifyAccountReactivationToken from './verify-account-reactivation-token'; -import updateCompanyPostDataMigration from './update-company-post-data-migration'; import updateLossPayeeFinancialDetailsUk from './update-loss-payee-financial-details-uk'; import updateLossPayeeFinancialDetailsInternational from './update-loss-payee-financial-details-international'; @@ -39,7 +38,6 @@ export { submitApplication, createFeedbackAndSendEmail, verifyAccountReactivationToken, - updateCompanyPostDataMigration, updateLossPayeeFinancialDetailsUk, updateLossPayeeFinancialDetailsInternational, }; diff --git a/src/api/custom-resolvers/mutations/update-company-post-data-migration/index.test.ts b/src/api/custom-resolvers/mutations/update-company-post-data-migration/index.test.ts deleted file mode 100644 index 1e102cffae..0000000000 --- a/src/api/custom-resolvers/mutations/update-company-post-data-migration/index.test.ts +++ /dev/null @@ -1,157 +0,0 @@ -import updateCompanyPostDataMigration from '.'; -import getKeystoneContext from '../../../test-helpers/get-keystone-context'; -import companyHelpers from '../../../test-helpers/company'; -import { Context } from '../../../types'; -import { mockCompany } from '../../../test-mocks/mock-application'; - -describe('custom-resolvers/update-company-post-data-migration', () => { - let context: Context; - - let company; - let companyAddress; - let result; - - const { - registeredOfficeAddress: { __typename, ...addressFields }, - } = mockCompany; - - const mockCompanyData = { - companyName: mockCompany.companyName, - companyNumber: mockCompany.companyNumber, - registeredOfficeAddress: addressFields, - industrySectorNames: ['mock sector name'], - sicCodes: [mockCompany.sicCodes[0].sicCode], - dateOfCreation: new Date(), - financialYearEndDate: new Date(), - }; - - let variables; - - beforeAll(async () => { - context = getKeystoneContext(); - - company = await companyHelpers.createCompany(context); - - companyAddress = await context.db.CompanyAddress.createOne({ - data: { - company: { - connect: { id: company.id }, - }, - }, - }); - - await context.db.Company.updateOne({ - where: { - id: company.id, - }, - data: { - registeredOfficeAddress: { - connect: { id: companyAddress.id }, - }, - }, - }); - - variables = { - id: company.id, - company: mockCompanyData, - }; - - result = await updateCompanyPostDataMigration({}, variables, context); - }); - - afterAll(() => { - jest.resetAllMocks(); - }); - - it('should successfully update company data', async () => { - const updatedCompany = await companyHelpers.getCompany(context, company.id); - - expect(updatedCompany.companyName).toEqual(mockCompany.companyName); - expect(updatedCompany.companyNumber).toEqual(mockCompany.companyNumber); - expect(updatedCompany.dateOfCreation).toBeDefined(); - expect(updatedCompany.financialYearEndDate).toBeDefined(); - }); - - it('should successfully update company address', async () => { - const updatedCompanyAddress = await context.db.CompanyAddress.findOne({ - where: { - id: companyAddress.id, - }, - }); - - const expected = { - ...addressFields, - id: companyAddress.id, - }; - - expect(updatedCompanyAddress).toEqual(expected); - }); - - it('should successfully create company SIC codes', async () => { - const sicCodes = await context.db.CompanySicCode.findMany(); - - const latestSicCode = sicCodes[sicCodes.length - 1]; - - expect(typeof latestSicCode.id).toEqual('string'); - expect(latestSicCode.id.length).toBeGreaterThan(0); - expect(latestSicCode.companyId).toEqual(company.id); - - expect(latestSicCode.sicCode).toEqual(mockCompanyData.sicCodes[0]); - expect(typeof latestSicCode.id).toEqual('string'); - expect(latestSicCode.id.length).toBeGreaterThan(0); - - expect(latestSicCode.industrySectorName).toEqual(mockCompanyData.industrySectorNames[0]); - }); - - it('should return success=true', () => { - expect(result).toEqual({ success: true }); - }); - - describe('when an error occurs whilst updating company data', () => { - it('should throw an error', async () => { - const mockVariables = { - ...variables, - id: '1', - }; - - const expectedMessage = 'Updating company (post data migration) Access denied: You cannot update that Company - it may not exist'; - - await expect(updateCompanyPostDataMigration({}, mockVariables, context)).rejects.toThrow(expectedMessage); - }); - }); - - describe('when an error occurs whilst updating company SIC codes', () => { - it('should throw an error', async () => { - const mockVariables = { - ...variables, - company: { - ...variables.company, - sicCodes: 'a, b, c', - }, - }; - - const expectedMessage = `Updating company (post data migration) Error: Creating company SIC codes for ${company.id} TypeError: sicCodes.forEach is not a function`; - - await expect(updateCompanyPostDataMigration({}, mockVariables, context)).rejects.toThrow(expectedMessage); - }); - }); - - describe('when an error occurs whilst updating company address data', () => { - it('should throw an error', async () => { - /** - * delete all company address entires - * so that the company does not have an address relationship. - */ - - const companyAddresses = await context.query.CompanyAddress.findMany(); - - await context.query.CompanyAddress.deleteMany({ - where: companyAddresses, - }); - - const expectedMessage = 'Updating company (post data migration) Error: Unable to update company address - does not exist (post data migration)'; - - await expect(updateCompanyPostDataMigration({}, variables, context)).rejects.toThrow(expectedMessage); - }); - }); -}); diff --git a/src/api/custom-resolvers/mutations/update-company-post-data-migration/index.ts b/src/api/custom-resolvers/mutations/update-company-post-data-migration/index.ts deleted file mode 100644 index f2cca0188c..0000000000 --- a/src/api/custom-resolvers/mutations/update-company-post-data-migration/index.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Context } from '.keystone/types'; // eslint-disable-line -import createCompanySicCodes from '../../../helpers/create-company-sic-codes'; -import { SuccessResponse, UpdateCompanyPostDataMigrationVariables } from '../../../types'; - -/** - * updateCompanyPostDataMigration - * Update a company (post data migration) - * 1) Update data in the Company table - * 2) Update data in the CompanyAddress table - * 3) Create company SIC codes. - * @param {Object} root: GraphQL root variables - * @param {ApplicationCompany} GraphQL variables - * @param {Context} context: KeystoneJS context API - * @returns {Promise} Object with success flag - */ -const updateCompanyPostDataMigration = async (root: any, variables: UpdateCompanyPostDataMigrationVariables, context: Context): Promise => { - try { - console.info('Updating company (post data migration) %s', variables.id); - - const { id, company } = variables; - - const { registeredOfficeAddress, industrySectorNames, sicCodes, ...otherFields } = company; - - const updatedCompany = await context.db.Company.updateOne({ - where: { - id, - }, - data: otherFields, - }); - - const { id: addressId, ...addressFields } = registeredOfficeAddress; - - if (!updatedCompany.registeredOfficeAddressId) { - console.error('Unable to update company address - does not exist (post data migration) %o', id); - - throw new Error(`Unable to update company address - does not exist (post data migration) ${id}`); - } - - await context.db.CompanyAddress.updateOne({ - where: { - id: updatedCompany.registeredOfficeAddressId, - }, - data: addressFields, - }); - - if (sicCodes) { - await createCompanySicCodes(context, updatedCompany.id, sicCodes, industrySectorNames); - } - - return { - success: true, - }; - } catch (error) { - console.error('Error updating company (post data migration) %o', error); - - throw new Error(`Updating company (post data migration) ${error}`); - } -}; - -export default updateCompanyPostDataMigration; diff --git a/src/api/custom-schema/type-defs.ts b/src/api/custom-schema/type-defs.ts index 9534a7d006..96c8ec8fb8 100644 --- a/src/api/custom-schema/type-defs.ts +++ b/src/api/custom-schema/type-defs.ts @@ -444,12 +444,6 @@ const typeDefs = ` iban: String bicSwiftCode: String ): SuccessResponse - - """ update a company (post data migration) """ - updateCompanyPostDataMigration( - id: String - company: CompanyInput - ): SuccessResponse } type Query { diff --git a/src/api/schema.graphql b/src/api/schema.graphql index 5fdd3b18f9..014fedaf53 100644 --- a/src/api/schema.graphql +++ b/src/api/schema.graphql @@ -3256,9 +3256,6 @@ type Mutation { """ update loss payee financial international """ updateLossPayeeFinancialDetailsInternational(id: String, bankAddress: String, iban: String, bicSwiftCode: String): SuccessResponse - - """ update a company (post data migration) """ - updateCompanyPostDataMigration(id: String, company: CompanyInput): SuccessResponse } union UserAuthenticationWithPasswordResult = UserAuthenticationWithPasswordSuccess | UserAuthenticationWithPasswordFailure diff --git a/src/api/types/application-types/index.ts b/src/api/types/application-types/index.ts index 7ac2549baa..f00f674ffd 100644 --- a/src/api/types/application-types/index.ts +++ b/src/api/types/application-types/index.ts @@ -395,11 +395,6 @@ export interface SubmitApplicationVariables { applicationId: string; } -export interface UpdateCompanyPostDataMigrationVariables extends Relationship { - id: string; - company: ApplicationCompanyCore; -} - export interface UpdateApplicationRelationshipParams { context: Context; applicationId: string; diff --git a/src/ui/server/api/keystone/application/update/companyPostDataMigration.ts b/src/ui/server/api/keystone/application/update/companyPostDataMigration.ts deleted file mode 100644 index c2b780c1a7..0000000000 --- a/src/ui/server/api/keystone/application/update/companyPostDataMigration.ts +++ /dev/null @@ -1,47 +0,0 @@ -import apollo from '../../../../graphql/apollo'; -import updateCompanyPostDataMigrationMutation from '../../../../graphql/mutations/update-application/companyPostDataMigration'; -import { ApolloResponse } from '../../../../../types'; - -/** - * updateCompanyPostDataMigration - * Update an application's "company" - * Note: this is only consumed by V1 applications that have been migrated to V2, - * that do not have company data. Company data is required in V2. - * @param {String} Company ID - * @param {Object} Company update - * @returns {Promise} Updated company - */ -const updateCompanyPostDataMigration = async (id: string, update: object) => { - try { - console.info('Updating application company (post data migration)'); - - const variables = { - id, - company: update, - }; - - const response = (await apollo('POST', updateCompanyPostDataMigrationMutation, variables)) as ApolloResponse; - - if (response.errors) { - console.error('GraphQL error updating application company (post data migration) %o', response.errors); - } - - if (response?.networkError?.result?.errors) { - console.error('GraphQL network error updating application company (post data migration) %o', response.networkError.result.errors); - } - - if (response?.data?.updateCompanyPostDataMigration) { - return response.data.updateCompanyPostDataMigration; - } - - console.error('Error with GraphQL updateCompanyPostDataMigration %o', response); - - throw new Error('Updating application company (post data migration)'); - } catch (error) { - console.error('Error updating application company (post data migration) %o', error); - - throw new Error('Updating application company (post data migration)'); - } -}; - -export default updateCompanyPostDataMigration; diff --git a/src/ui/server/api/keystone/application/update/index.ts b/src/ui/server/api/keystone/application/update/index.ts index 0f07f3bd95..96f29d9081 100644 --- a/src/ui/server/api/keystone/application/update/index.ts +++ b/src/ui/server/api/keystone/application/update/index.ts @@ -4,7 +4,6 @@ import buyer from './buyer'; import buyerTradingHistory from './buyerTradingHistory'; import buyerRelationship from './buyerRelationship'; import company from './company'; -import companyPostDataMigration from './companyPostDataMigration'; import declarations from '../declarations'; import companyDifferentTradingAddress from './companyDifferentTradingAddress'; import exportContract from './exportContract'; @@ -32,7 +31,6 @@ const update = { buyerRelationship, buyerTradingHistory, company, - companyPostDataMigration, declarations: declarations.update, companyDifferentTradingAddress, exportContract, diff --git a/src/ui/server/constants/routes/insurance/business.ts b/src/ui/server/constants/routes/insurance/business.ts index 0744e5ec41..66af729f7f 100644 --- a/src/ui/server/constants/routes/insurance/business.ts +++ b/src/ui/server/constants/routes/insurance/business.ts @@ -14,7 +14,6 @@ export const EXPORTER_BUSINESS = { COMPANY_DETAILS_CHANGE: `${COMPANY_DETAILS_ROOT}/change`, COMPANY_DETAILS_CHECK_AND_CHANGE: `${COMPANY_DETAILS_ROOT}/check-and-change`, COMPANY_DETAILS_SAVE_AND_BACK: `${COMPANY_DETAILS_ROOT}/save-and-back`, - ENTER_COMPANIES_HOUSE_NUMBER: `${ROOT}/enter-companies-house-number`, ALTERNATIVE_TRADING_ADDRESS_ROOT, ALTERNATIVE_TRADING_ADDRESS_ROOT_SAVE_AND_BACK: `${ALTERNATIVE_TRADING_ADDRESS_ROOT}/save-and-back`, ALTERNATIVE_TRADING_ADDRESS_CHANGE: `${ALTERNATIVE_TRADING_ADDRESS_ROOT}/change`, diff --git a/src/ui/server/constants/templates/insurance/business/index.ts b/src/ui/server/constants/templates/insurance/business/index.ts index 40f03b22bc..4083a0e028 100644 --- a/src/ui/server/constants/templates/insurance/business/index.ts +++ b/src/ui/server/constants/templates/insurance/business/index.ts @@ -1,6 +1,5 @@ export const BUSINESS_TEMPLATES = { ROOT: 'insurance/your-business/index.njk', - ENTER_COMPANIES_HOUSE_NUMBER: 'insurance/your-business/enter-companies-house-number.njk', COMPANY_DETAILS: 'insurance/your-business/company-details.njk', ALTERNATIVE_TRADING_ADDRESS: 'insurance/your-business/alternative-trading-address.njk', NATURE_OF_YOUR_BUSINESS: 'insurance/your-business/nature-of-your-business.njk', diff --git a/src/ui/server/content-strings/pages/insurance/your-business/index.ts b/src/ui/server/content-strings/pages/insurance/your-business/index.ts index 71d0d1e480..d817650688 100644 --- a/src/ui/server/content-strings/pages/insurance/your-business/index.ts +++ b/src/ui/server/content-strings/pages/insurance/your-business/index.ts @@ -14,10 +14,6 @@ const EXPORTER_BUSINESS = { }, OUTRO: 'It should only take a few minutes to complete.', }, - ENTER_COMPANIES_HOUSE_NUMBER: { - ...SHARED, - PAGE_TITLE: 'Enter your Companies House registration number (CRN)', - }, COMPANY_DETAILS: { ...SHARED, ...COMPANY_DETAILS, diff --git a/src/ui/server/controllers/insurance/business/companies-house-search/index.test.ts b/src/ui/server/controllers/insurance/business/companies-house-search/index.test.ts deleted file mode 100644 index 731a8f5926..0000000000 --- a/src/ui/server/controllers/insurance/business/companies-house-search/index.test.ts +++ /dev/null @@ -1,258 +0,0 @@ -import { FIELD_ID, PAGE_VARIABLES, PAGE_CONTENT_STRINGS, TEMPLATE, get, post } from '.'; -import { PAGES } from '../../../../content-strings'; -import { FIELDS_ELIGIBILITY as FIELDS } from '../../../../content-strings/fields/insurance/eligibility'; -import { ERROR_MESSAGES } from '../../../../content-strings/error-messages'; -import { ROUTES, TEMPLATES } from '../../../../constants'; -import INSURANCE_FIELD_IDS from '../../../../constants/field-ids/insurance'; -import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; -import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; -import constructPayload from '../../../../helpers/construct-payload'; -import generateValidationErrors from '../../../../helpers/companies-house-search/validation'; -import generateValidationErrorsHelper from '../../../../helpers/validation'; -import companiesHouse from '../../../../helpers/companies-house-search'; -import mapCompaniesHouseData from '../../../../helpers/mappings/map-companies-house-data'; -import saveData from '../save-data/companies-house-search-data'; -import { CompaniesHouseResponse, Request, Response } from '../../../../../types'; -import { mockReq, mockRes, mockCompaniesHouseResponse, mockCompany, referenceNumber, mockSpyPromiseRejection } from '../../../../test-mocks'; - -const { - ELIGIBILITY: { - COMPANIES_HOUSE: { COMPANY_NUMBER }, - }, -} = INSURANCE_FIELD_IDS; - -const { - PROBLEM_WITH_SERVICE, - INSURANCE: { - ELIGIBILITY: { COMPANY_NOT_ACTIVE_EXIT, COMPANIES_HOUSE_UNAVAILABLE_EXIT }, - EXPORTER_BUSINESS: { COMPANY_DETAILS_ROOT }, - INSURANCE_ROOT, - }, -} = ROUTES; - -describe('controllers/insurance/business/companies-house-search', () => { - let req: Request; - let res: Response; - - jest.mock('../../../../helpers/companies-house-search'); - - beforeEach(() => { - req = mockReq(); - res = mockRes(); - }); - - describe('FIELD_ID', () => { - it('should have the correct ID', () => { - expect(FIELD_ID).toEqual(COMPANY_NUMBER); - }); - }); - - describe('PAGE_VARIABLES', () => { - it('should have correct properties', () => { - const expected = { - FIELD: { - ID: FIELD_ID, - ...FIELDS[FIELD_ID], - }, - }; - - expect(PAGE_VARIABLES).toEqual(expected); - }); - }); - - describe('PAGE_CONTENT_STRINGS', () => { - it('should have the correct strings', () => { - expect(PAGE_CONTENT_STRINGS).toEqual(PAGES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER); - }); - }); - - describe('TEMPLATE', () => { - it('should have the correct template defined', () => { - expect(TEMPLATE).toEqual(TEMPLATES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER); - }); - }); - - describe('get', () => { - it('should render template', () => { - get(req, res); - - expect(res.render).toHaveBeenCalledWith(TEMPLATE, { - ...insuranceCorePageVariables({ - PAGE_CONTENT_STRINGS, - BACK_LINK: req.headers.referer, - }), - userName: getUserNameFromSession(req.session.user), - ...PAGE_VARIABLES, - }); - }); - }); - - describe('post', () => { - const validBody = { - [FIELD_ID]: mockCompany.companyNumber, - }; - - companiesHouse.search = jest.fn(() => Promise.resolve(mockCompaniesHouseResponse)); - saveData.companyDetailsPostMigration = jest.fn(() => Promise.resolve(true)); - - describe('when there are validation errors', () => { - it('should render template with validation errors from constructPayload function', async () => { - await post(req, res); - - const payload = constructPayload(req.body, [FIELD_ID]); - - expect(res.render).toHaveBeenCalledWith(TEMPLATE, { - ...insuranceCorePageVariables({ - PAGE_CONTENT_STRINGS, - BACK_LINK: req.headers.referer, - }), - userName: getUserNameFromSession(req.session.user), - ...PAGE_VARIABLES, - validationErrors: generateValidationErrors(payload), - submittedValues: payload, - }); - }); - }); - - describe('when there are no validation errors', () => { - beforeEach(() => { - req.body = validBody; - }); - - it('should call companiesHouse.search once with data from constructPayload function', async () => { - await post(req, res); - - const payload = constructPayload(req.body, [FIELD_ID]); - - expect(companiesHouse.search).toHaveBeenCalledTimes(1); - expect(companiesHouse.search).toHaveBeenCalledWith(payload[FIELD_ID]); - }); - - it('should call saveData.companyDetailsPostMigration with mapped company data', async () => { - await post(req, res); - - const mappedData = mapCompaniesHouseData(mockCompaniesHouseResponse); - - expect(saveData.companyDetailsPostMigration).toHaveBeenCalledTimes(1); - expect(saveData.companyDetailsPostMigration).toHaveBeenCalledWith(res.locals.application, mappedData); - }); - - it(`should redirect to ${COMPANY_DETAILS_ROOT}`, async () => { - await post(req, res); - - const expected = `${INSURANCE_ROOT}/${referenceNumber}${COMPANY_DETAILS_ROOT}`; - - expect(res.redirect).toHaveBeenCalledWith(expected); - }); - - describe('when companiesHouse.search returns isActive=false', () => { - it(`should redirect to ${COMPANY_NOT_ACTIVE_EXIT}`, async () => { - req.body = validBody; - - const mockResponse = { - ...mockCompaniesHouseResponse, - apiError: false, - isActive: false, - } as CompaniesHouseResponse; - - companiesHouse.search = jest.fn(() => Promise.resolve(mockResponse)); - - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(COMPANY_NOT_ACTIVE_EXIT); - }); - }); - }); - - describe('api error handling', () => { - describe('when companiesHouse.search returns notFound=true', () => { - it('should render template with validation errors', async () => { - req.body = validBody; - - const mockResponse = { - ...mockCompaniesHouseResponse, - notFound: true, - } as CompaniesHouseResponse; - - companiesHouse.search = jest.fn(() => Promise.resolve(mockResponse)); - - await post(req, res); - - const payload = constructPayload(req.body, [FIELD_ID]); - - const expectedErrorMessage = ERROR_MESSAGES.INSURANCE.ELIGIBILITY[FIELD_ID].NOT_FOUND; - - expect(res.render).toHaveBeenCalledWith(TEMPLATE, { - ...insuranceCorePageVariables({ - PAGE_CONTENT_STRINGS, - BACK_LINK: req.headers.referer, - }), - userName: getUserNameFromSession(req.session.user), - ...PAGE_VARIABLES, - validationErrors: generateValidationErrorsHelper(FIELD_ID, expectedErrorMessage, {}), - submittedValues: payload, - }); - }); - }); - - describe('when companiesHouse.search returns apiError=true', () => { - it(`should redirect to ${COMPANIES_HOUSE_UNAVAILABLE_EXIT}`, async () => { - req.body = validBody; - - const mockResponse = { - ...mockCompaniesHouseResponse, - apiError: true, - } as CompaniesHouseResponse; - - companiesHouse.search = jest.fn(() => Promise.resolve(mockResponse)); - - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(COMPANIES_HOUSE_UNAVAILABLE_EXIT); - }); - }); - - describe('when saveData.companyDetailsPostMigration returns false', () => { - it(`should redirect to ${PROBLEM_WITH_SERVICE}`, async () => { - req.body = validBody; - - companiesHouse.search = jest.fn(() => Promise.resolve(mockCompaniesHouseResponse)); - saveData.companyDetailsPostMigration = jest.fn(() => Promise.resolve(false)); - - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(PROBLEM_WITH_SERVICE); - }); - }); - - describe('when there is an error with companiesHouse.search', () => { - beforeEach(() => { - companiesHouse.search = mockSpyPromiseRejection; - }); - - it(`should redirect to ${PROBLEM_WITH_SERVICE}`, async () => { - req.body = validBody; - - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(PROBLEM_WITH_SERVICE); - }); - }); - - describe('when there is an error with saveData.companyDetailsPostMigration', () => { - beforeEach(() => { - companiesHouse.search = jest.fn(() => Promise.resolve(mockCompaniesHouseResponse)); - saveData.companyDetailsPostMigration = mockSpyPromiseRejection; - }); - - it(`should redirect to ${PROBLEM_WITH_SERVICE}`, async () => { - req.body = validBody; - - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(PROBLEM_WITH_SERVICE); - }); - }); - }); - }); -}); diff --git a/src/ui/server/controllers/insurance/business/companies-house-search/index.ts b/src/ui/server/controllers/insurance/business/companies-house-search/index.ts deleted file mode 100644 index ec80d6ff8b..0000000000 --- a/src/ui/server/controllers/insurance/business/companies-house-search/index.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { PAGES } from '../../../../content-strings'; -import { FIELDS_ELIGIBILITY as FIELDS } from '../../../../content-strings/fields/insurance/eligibility'; -import { ERROR_MESSAGES } from '../../../../content-strings/error-messages'; -import { ROUTES, TEMPLATES } from '../../../../constants'; -import INSURANCE_FIELD_IDS from '../../../../constants/field-ids/insurance'; -import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; -import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; -import constructPayload from '../../../../helpers/construct-payload'; -import generateValidationErrors from '../../../../helpers/companies-house-search/validation'; -import generateValidationErrorsHelper from '../../../../helpers/validation'; -import companiesHouse from '../../../../helpers/companies-house-search'; -import mapCompaniesHouseData from '../../../../helpers/mappings/map-companies-house-data'; -import saveData from '../save-data/companies-house-search-data'; -import { CompaniesHouseResponse, Request, Response } from '../../../../../types'; - -const { - ELIGIBILITY: { - COMPANIES_HOUSE: { COMPANY_NUMBER }, - }, -} = INSURANCE_FIELD_IDS; - -const { - PROBLEM_WITH_SERVICE, - INSURANCE: { - ELIGIBILITY: { COMPANY_NOT_ACTIVE_EXIT, COMPANIES_HOUSE_UNAVAILABLE_EXIT }, - EXPORTER_BUSINESS: { COMPANY_DETAILS_ROOT }, - INSURANCE_ROOT, - }, -} = ROUTES; - -export const FIELD_ID = COMPANY_NUMBER; - -export const PAGE_VARIABLES = { - FIELD: { - ID: FIELD_ID, - ...FIELDS[FIELD_ID], - }, -}; - -export const PAGE_CONTENT_STRINGS = PAGES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER; - -export const TEMPLATE = TEMPLATES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER; - -/** - * get - * Render the "Companies house search" page - * @param {Express.Request} Express request - * @param {Express.Response} Express response - * @returns {Express.Response.render} Companies house search page - */ -export const get = (req: Request, res: Response) => - res.render(TEMPLATE, { - ...insuranceCorePageVariables({ - PAGE_CONTENT_STRINGS, - BACK_LINK: req.headers.referer, - }), - userName: getUserNameFromSession(req.session.user), - ...PAGE_VARIABLES, - }); - -/** - * post - * Post the "Companies house search" form - * @param {Express.Request} Express request - * @param {Express.Response} Express response - * @returns {Express.Response.redirect} Next part of the flow or validation errors - */ -export const post = async (req: Request, res: Response) => { - try { - const { application } = res.locals; - - if (!application) { - return res.redirect(PROBLEM_WITH_SERVICE); - } - - const { referenceNumber } = application; - - const payload = constructPayload(req.body, [FIELD_ID]) as CompaniesHouseResponse; - - /** - * Check that a companies house number has been provided. - * If not, render the template with validation errors. - */ - const formValidationErrors = generateValidationErrors(payload); - - if (formValidationErrors) { - return res.render(TEMPLATE, { - ...insuranceCorePageVariables({ - PAGE_CONTENT_STRINGS, - BACK_LINK: req.headers.referer, - }), - userName: getUserNameFromSession(req.session.user), - ...PAGE_VARIABLES, - validationErrors: formValidationErrors, - submittedValues: payload, - }); - } - - /** - * 1) Call companies house API (via our own API) - * 2) If notFound is returned, render the page with validation errors. - * 3) If apiError is returned, redirect to COMPANIES_HOUSE_UNAVAILABLE. - * 4) If the company is not active, redirect to COMPANY_NOT_ACTIVE. - */ - const response = await companiesHouse.search(payload[FIELD_ID]); - - if (response.notFound) { - const errorMessage = ERROR_MESSAGES.INSURANCE.ELIGIBILITY[FIELD_ID].NOT_FOUND; - - return res.render(TEMPLATE, { - ...insuranceCorePageVariables({ - PAGE_CONTENT_STRINGS, - BACK_LINK: req.headers.referer, - }), - userName: getUserNameFromSession(req.session.user), - ...PAGE_VARIABLES, - validationErrors: generateValidationErrorsHelper(FIELD_ID, errorMessage, {}), - submittedValues: payload, - }); - } - - if (response.apiError) { - return res.redirect(COMPANIES_HOUSE_UNAVAILABLE_EXIT); - } - - if (!response.isActive) { - return res.redirect(COMPANY_NOT_ACTIVE_EXIT); - } - - const mappedData = mapCompaniesHouseData(response); - - const saveResponse = await saveData.companyDetailsPostMigration(application, mappedData); - - if (!saveResponse) { - return res.redirect(PROBLEM_WITH_SERVICE); - } - - return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${COMPANY_DETAILS_ROOT}`); - } catch (error) { - console.error('Error updating application - your business - company house search (post data migration) %o', error); - - return res.redirect(PROBLEM_WITH_SERVICE); - } -}; diff --git a/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.api-error.test.ts b/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.api-error.test.ts deleted file mode 100644 index 5bb8fb7254..0000000000 --- a/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.api-error.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import save from '.'; -import api from '../../../../../api'; -import { mockApplication, mockSpyPromiseRejection } from '../../../../../test-mocks'; - -describe('controllers/insurance/business/save-data/companies-house-search-data - API error', () => { - let updateSpy = jest.fn(() => Promise.resolve(true)); - - const mockFormBody = { - mock: true, - }; - - beforeEach(() => { - api.keystone.application.update.companyPostDataMigration = updateSpy; - }); - - describe('when there is an error', () => { - beforeEach(() => { - updateSpy = mockSpyPromiseRejection; - - api.keystone.application.update.companyPostDataMigration = updateSpy; - }); - - it('should throw an error', async () => { - try { - await save.companyDetailsPostMigration(mockApplication, mockFormBody); - } catch (error) { - const expected = new Error("Updating application's company (post data migration)"); - expect(error).toEqual(expected); - } - }); - }); -}); diff --git a/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.test.ts b/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.test.ts deleted file mode 100644 index 65fa9e0582..0000000000 --- a/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import save from '.'; -import api from '../../../../../api'; -import { sanitiseData } from '../../../../../helpers/sanitise-data'; -import { mockApplication } from '../../../../../test-mocks'; - -describe('controllers/insurance/business/save-data/companies-house-search-data', () => { - const mockUpdateApplicationResponse = mockApplication; - const updateSpy = jest.fn(() => Promise.resolve(mockUpdateApplicationResponse)); - - const mockFormBody = { - mock: true, - }; - - beforeEach(() => { - api.keystone.application.update.companyPostDataMigration = updateSpy; - }); - - it('should call api.keystone.application.update.companyPostDataMigration', async () => { - await save.companyDetailsPostMigration(mockApplication, mockFormBody); - - expect(updateSpy).toHaveBeenCalledTimes(1); - - const expectedSanitisedData = sanitiseData(mockFormBody); - expect(updateSpy).toHaveBeenCalledWith(mockApplication.company.id, expectedSanitisedData); - }); - - it('should return the API response', async () => { - const result = await save.companyDetailsPostMigration(mockApplication, mockFormBody); - - expect(result).toEqual(mockUpdateApplicationResponse); - }); -}); diff --git a/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.ts b/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.ts deleted file mode 100644 index 74ba283861..0000000000 --- a/src/ui/server/controllers/insurance/business/save-data/companies-house-search-data/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -import api from '../../../../../api'; -import { sanitiseData } from '../../../../../helpers/sanitise-data'; -import { Application, RequestBody } from '../../../../../../types'; - -/** - * gets fields to add to the database and sanitises them - * saves to company tables in database via api call - * @param {Application} application - * @param {RequestBody} formBody - * @returns {Promise} Saved data - */ -const companyDetailsPostMigration = async (application: Application, formBody: RequestBody) => { - const sanitisedData = sanitiseData(formBody); - - const companyId = application.company?.id; - - try { - // send the form data to the API for database update. - const saveResponse = await api.keystone.application.update.companyPostDataMigration(companyId, sanitisedData); - return saveResponse; - } catch (error) { - throw new Error("Updating application's company (post data migration)"); - } -}; - -export default { companyDetailsPostMigration }; diff --git a/src/ui/server/graphql/mutations/update-application/companyPostDataMigration.ts b/src/ui/server/graphql/mutations/update-application/companyPostDataMigration.ts deleted file mode 100644 index db5f6c1d3e..0000000000 --- a/src/ui/server/graphql/mutations/update-application/companyPostDataMigration.ts +++ /dev/null @@ -1,11 +0,0 @@ -import gql from 'graphql-tag'; - -const updateCompanyPostDataMigrationMutation = gql` - mutation updateCompanyPostDataMigration($id: String!, $company: CompanyInput!) { - updateCompanyPostDataMigration(id: $id, company: $company) { - success - } - } -`; - -export default updateCompanyPostDataMigrationMutation; diff --git a/src/ui/server/routes/insurance/business/index.test.js b/src/ui/server/routes/insurance/business/index.test.js index e6bb125796..3519f8d1f3 100644 --- a/src/ui/server/routes/insurance/business/index.test.js +++ b/src/ui/server/routes/insurance/business/index.test.js @@ -3,8 +3,6 @@ import { ROUTES } from '../../../constants'; import { get as getYourBusiness } from '../../../controllers/insurance/business'; -import { get as getEnterCompaniesHouseNumber, post as postEnterCompaniesHouseNumber } from '../../../controllers/insurance/business/companies-house-search'; - import { get as getCompanyDetails, post as postCompanyDetails } from '../../../controllers/insurance/business/company-details'; import { post as postCompanyDetailsSaveAndBack } from '../../../controllers/insurance/business/company-details/save-and-back'; @@ -40,14 +38,11 @@ describe('routes/insurance/your-business', () => { }); it('should setup all routes', () => { - expect(get).toHaveBeenCalledTimes(28); - expect(post).toHaveBeenCalledTimes(33); + expect(get).toHaveBeenCalledTimes(27); + expect(post).toHaveBeenCalledTimes(32); expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.EXPORTER_BUSINESS.ROOT, getYourBusiness); - expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER, getEnterCompaniesHouseNumber); - expect(post).toHaveBeenCalledWith(ROUTES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER, postEnterCompaniesHouseNumber); - expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS, getCompanyDetails); expect(post).toHaveBeenCalledWith(ROUTES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS_SAVE_AND_BACK, postCompanyDetailsSaveAndBack); expect(post).toHaveBeenCalledWith(ROUTES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS, postCompanyDetails); diff --git a/src/ui/server/routes/insurance/business/index.ts b/src/ui/server/routes/insurance/business/index.ts index ec9c6d9c0a..2aa3e5f141 100644 --- a/src/ui/server/routes/insurance/business/index.ts +++ b/src/ui/server/routes/insurance/business/index.ts @@ -3,8 +3,6 @@ import { ROUTES } from '../../../constants'; import { get as getYourBusiness } from '../../../controllers/insurance/business'; -import { get as getEnterCompaniesHouseNumber, post as postEnterCompaniesHouseNumber } from '../../../controllers/insurance/business/companies-house-search'; - import { get as getCompanyDetails, post as postCompanyDetails } from '../../../controllers/insurance/business/company-details'; import { post as postCompanyDetailsSaveAndBack } from '../../../controllers/insurance/business/company-details/save-and-back'; @@ -34,9 +32,6 @@ const insuranceBusinessRouter = express.Router(); insuranceBusinessRouter.get(`/:referenceNumber${ROUTES.INSURANCE.EXPORTER_BUSINESS.ROOT}`, getYourBusiness); -insuranceBusinessRouter.get(`/:referenceNumber${ROUTES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER}`, getEnterCompaniesHouseNumber); -insuranceBusinessRouter.post(`/:referenceNumber${ROUTES.INSURANCE.EXPORTER_BUSINESS.ENTER_COMPANIES_HOUSE_NUMBER}`, postEnterCompaniesHouseNumber); - insuranceBusinessRouter.get(`/:referenceNumber${ROUTES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS}`, getCompanyDetails); insuranceBusinessRouter.post(`/:referenceNumber${ROUTES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS_SAVE_AND_BACK}`, postCompanyDetailsSaveAndBack); insuranceBusinessRouter.post(`/:referenceNumber${ROUTES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS}`, postCompanyDetails); diff --git a/src/ui/server/routes/insurance/index.test.ts b/src/ui/server/routes/insurance/index.test.ts index d5bd8e7c04..8779366dbe 100644 --- a/src/ui/server/routes/insurance/index.test.ts +++ b/src/ui/server/routes/insurance/index.test.ts @@ -21,8 +21,8 @@ describe('routes/insurance', () => { }); it('should setup all routes', () => { - expect(get).toHaveBeenCalledTimes(218); - expect(post).toHaveBeenCalledTimes(229); + expect(get).toHaveBeenCalledTimes(217); + expect(post).toHaveBeenCalledTimes(228); expect(get).toHaveBeenCalledWith(INSURANCE_ROUTES.START, startGet); diff --git a/src/ui/templates/insurance/your-business/enter-companies-house-number.njk b/src/ui/templates/insurance/your-business/enter-companies-house-number.njk deleted file mode 100644 index b42d16be9a..0000000000 --- a/src/ui/templates/insurance/your-business/enter-companies-house-number.njk +++ /dev/null @@ -1,63 +0,0 @@ -{% extends 'index.njk' %} -{% from "govuk/components/back-link/macro.njk" import govukBackLink %} -{% from 'govuk/components/error-summary/macro.njk' import govukErrorSummary %} -{% import '../../components/text-input.njk' as textInput %} -{% import '../../components/submit-button.njk' as submitButton %} - -{% block pageTitle %} - {{ CONTENT_STRINGS.PAGE_TITLE }} -{% endblock %} - -{% block content %} - - {{ govukBackLink({ - text: CONTENT_STRINGS.LINKS.BACK, - href: BACK_LINK, - attributes: { - "data-cy": DATA_CY.BACK_LINK - } - }) }} - - {% if validationErrors.summary %} - {{ govukErrorSummary({ - titleText: CONTENT_STRINGS.ERROR_MESSAGES.THERE_IS_A_PROBLEM, - errorList: validationErrors.summary, - attributes: { - 'data-cy': 'error-summary' - } - }) }} - {% endif %} - -
-
- - -
- - - {{ CONTENT_STRINGS.HEADING_CAPTION }} - - -

{{ CONTENT_STRINGS.PAGE_TITLE }}

-
- -
- - - {{ submitButton.render({ - text: CONTENT_STRINGS.BUTTONS.CONTINUE - }) }} -
-
-
- -{% endblock %}