Skip to content

Commit

Permalink
feat(APIM-609): companies house - extend returned fields (#1089)
Browse files Browse the repository at this point in the history
## Introduction ✏️
In order for Companies House to be consumed by other products/services,
the integration needs to return some additional fields.

Note: unfortunately, some methods in the Companies House service do not
have unit test coverage as they are private methods. I would like to add
unit tests for all private methods (likely needing to make them public
or extracted into helper functions), but this would be a bigger change
than introducing additional fields.

## Resolution ✔️
- Update Companies House types.
- Update `CompaniesService` to return the following additional data:
  - `accounts` object
  - `dateOfCreation`
  - `registeredAddress.careOf`
  - `registeredAddress.premises`
  - `registeredAddress.region`
- Updated test generator shapes.

# Todo ❗ 
* Ensure tests are DRY and centralised helpers for types, DTO and
interfaces.

---------

Co-authored-by: Abhi Markan <amarkan>
  • Loading branch information
ttbarnes authored Dec 17, 2024
1 parent 11ec0d4 commit 041124c
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 223 deletions.
321 changes: 161 additions & 160 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"start:prod": "node dist/src/main",
"type-check": "tsc --noEmit --pretty",
"unit-test": "jest --selectProjects=Unit",
"unit-test-dev": "jest --verbose --config=jest.config.ts",
"validate:all": "npm run lint:fix && npm run prettier:fix && npm run type-check && npm run validate:yml",
"validate:yml": "npx yaml-lint **/*.yml --ignore=**/node_modules"
},
Expand Down Expand Up @@ -87,10 +88,10 @@
"@types/lodash": "^4.17.13",
"@types/node": "^22.10.2",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"chance": "^1.1.12",
"cspell": "^8.17.0",
"cspell": "^8.17.1",
"eslint": "^8.57.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ export type GetCompanyCompaniesHouseResponse = {
address_line_1: string;
address_line_2?: string;
address_line_3?: string;
care_of?: string;
country: string;
locality: string;
postal_code: string;
country: string;
premises?: string;
region?: string;
};
registered_office_is_in_dispute: boolean;
sic_codes: string[];
Expand Down
24 changes: 23 additions & 1 deletion src/modules/companies/companies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,38 @@ export class CompaniesService {
const address = company.registered_office_address;

return {
accounts: {
accountingReferenceDate: company.accounts.accounting_reference_date,
lastAccounts: {
madeUpTo: company.accounts.last_accounts?.made_up_to,
periodEndOn: company.accounts.last_accounts?.period_end_on,
periodStartOn: company.accounts.last_accounts?.period_start_on,
type: company.accounts.last_accounts?.period_start_on,
},
nextAccounts: {
dueOn: company.accounts.next_accounts.due_on,
overdue: company.accounts.next_accounts.overdue,
periodEndOn: company.accounts.next_accounts.period_end_on,
periodStartOn: company.accounts.next_accounts.period_start_on,
},
nextDue: company.accounts.next_due,
nextMadeUpTo: company.accounts.next_made_up_to,
overdue: company.accounts.overdue,
},
companiesHouseRegistrationNumber: company.company_number,
companyName: company.company_name,
dateOfCreation: company.date_of_creation,
registeredAddress: {
organisationName: address?.organisation_name,
addressLine1: address?.address_line_1,
addressLine2: address?.address_line_2,
addressLine3: address?.address_line_3,
careOf: address?.care_of,
country: address?.country,
locality: address?.locality,
postalCode: address?.postal_code,
country: address?.country,
premises: address?.premises,
region: address?.region,
},
industries: this.mapSicCodes(company.sic_codes, industryClasses),
};
Expand Down
53 changes: 44 additions & 9 deletions src/modules/companies/dto/get-company-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
class AccountsReferenceDate {
day: string;
month: string;
}

class AccountsLastAccounts {
madeUpTo: string;
periodEndOn: string;
periodStartOn: string;
type: string;
}

class AccountsNextAccounts {
dueOn: string;
overdue: boolean;
periodEndOn: string;
periodStartOn: string;
}

class Accounts {
accountingReferenceDate?: AccountsReferenceDate;
lastAccounts?: AccountsLastAccounts;
nextAccounts?: AccountsNextAccounts;
nextDue?: string;
nextMadeUpTo?: string;
overdue?: boolean;
}

class RegisteredAddress {
organisationName?: string;
addressLine1?: string;
addressLine2?: string;
addressLine3?: string;
careOf?: string;
country?: string;
locality?: string;
postalCode?: string;
premises?: string;
region?: string;
}

export class GetCompanyResponse {
accounts: Accounts;
companiesHouseRegistrationNumber: string;
companyName: string;
registeredAddress: {
organisationName?: string;
addressLine1?: string;
addressLine2?: string;
addressLine3?: string;
locality?: string;
postalCode?: string;
country?: string;
};
dateOfCreation: string;
registeredAddress: RegisteredAddress;
industries: Industry[];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,59 @@
{
"accounts": {
"accountingReferenceDate": {
"day": "31",
"month": "12"
},
"lastAccounts": {
"madeUpTo": "2024-12-31",
"periodEndOn": "2024-12-31",
"periodStartOn": "2024-01-01",
"type": "2024-01-01"
},
"nextAccounts": {
"dueOn": "2026-09-30",
"overdue": false,
"periodEndOn": "2024-12-31",
"periodStartOn": "2024-01-01"
},
"nextDue": "2026-09-30",
"nextMadeUpTo": "2024-12-31",
"overdue": false
},
"companiesHouseRegistrationNumber": "00000001",
"companyName": "TEST COMPANY LTD",
"dateOfCreation": "1989-09-20",
"registeredAddress": {
"addressLine1": "1 Test Street",
"locality": "Test City",
"postalCode": "A1 2BC",
"country": "United Kingdom"
"addressLine1": "1 Test",
"addressLine2": "Test",
"country": "England",
"locality": "London",
"postalCode": "A12 3AB"
},
"industries": [
{
"class": {
"code": "59112",
"name": "Video production activities"
},
"code": "1009",
"name": "Information and communication"
},
{
"class": {
"code": "62012",
"name": "Business and domestic software development"
},
"code": "1009",
"name": "Information and communication"
"code": "1003",
"name": "Manufacturing",
"class": {
"code": "26110",
"name": "Manufacture of electronic components"
}
},
{
"class": {
"code": "62020",
"name": "Information technology consultancy activities"
},
"code": "1009",
"name": "Information and communication"
"code": "1003",
"name": "Manufacturing",
"class": {
"code": "27120",
"name": "Manufacture of electricity distribution and control apparatus"
}
},
{
"class": {
"code": "62090",
"name": "Other information technology service activities"
},
"code": "1009",
"name": "Information and communication"
"code": "1006",
"name": "Wholesale and retail trade; repair of motor vehicles and motorcycles",
"class": {
"code": "46520",
"name": "Wholesale of electronic and telecommunications equipment and parts"
}
}
]
}
Loading

0 comments on commit 041124c

Please sign in to comment.