Skip to content

Commit df56375

Browse files
authored
Merge pull request #164 from companieshouse/BI-7008-add-paging-to-dissolved-alpha-search
add query params for dissolved search alphabetical update tests
2 parents 9b1482b + 5633fd6 commit df56375

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/services/search/dissolved-search/service.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
import { IHttpClient } from "../../../http";
22
import { CompaniesResource } from "./types";
33
import Resource from "../../resource";
4-
import { start } from "repl";
5-
64
export default class DissolvedSearchService {
75
constructor (private readonly client: IHttpClient) { }
8-
public async getCompanies (companyName: string, requestId: string, searchType: string, startIndex: number): Promise<Resource<CompaniesResource>> {
6+
public async getCompanies (companyName: string, requestId: string, searchType: string, startIndex: number | null, searchBefore: string | null, searchAfter: string | null, size: number | null): Promise<Resource<CompaniesResource>> {
97
const additionalHeaders = {
108
"X-Request-ID": requestId,
119
"Content-Type": "application/json"
1210
}
1311
const ALPHABETICAL_QUERY = "&search_type=alphabetical";
1412
const BEST_MATCH_QUERY = "&search_type=best-match";
1513
const PREVIOUS_NAME_QUERY = "&search_type=previous-name-dissolved";
16-
const START_INDEX_QUERY = "&start_index=" + startIndex;
14+
const START_INDEX_QUERY = "&start_index=";
15+
const SEARCH_BEFORE_QUERY = "&search_before=";
16+
const SEARCH_AFTER_QUERY = "&search_after=";
17+
const SIZE_QUERY = "&size=";
1718

1819
let dissolvedSearchURL = "/dissolved-search/companies?q=" + companyName;
1920

2021
if (searchType === "alphabetical") {
21-
dissolvedSearchURL += ALPHABETICAL_QUERY;
22+
dissolvedSearchURL += ALPHABETICAL_QUERY
23+
if (searchAfter !== null) {
24+
dissolvedSearchURL += SEARCH_AFTER_QUERY + searchAfter;
25+
}
26+
if (searchBefore !== null) {
27+
dissolvedSearchURL += SEARCH_BEFORE_QUERY + searchBefore;
28+
}
29+
if (size !== null) {
30+
dissolvedSearchURL += SIZE_QUERY + size;
31+
}
2232
}
2333

2434
if (!startIndex && searchType === "previousNameDissolved") {

src/services/search/dissolved-search/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Items {
1414
date_of_cessation: Date;
1515
date_of_creation: Date;
1616
kind: string;
17+
ordered_alpha_key_with_id: string;
1718
previous_company_names: PreviousCompanyNames[];
1819
}
1920

@@ -36,5 +37,6 @@ export interface TopHit {
3637
date_of_cessation: Date;
3738
date_of_creation: Date;
3839
kind: string;
40+
ordered_alpha_key_with_id: string;
3941
previous_company_names: PreviousCompanyNames[];
4042
}

test/services/search/dissolved-search/service.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const mockResponseBody : CompaniesResource = ({
2323
date_of_cessation: (new Date("19910212")),
2424
date_of_creation: (new Date("19910212")),
2525
kind: "kind",
26+
ordered_alpha_key_with_id: "testcompany:0000789",
2627
previous_company_names: [
2728
{
2829
ceased_on: (new Date("19910212")),
@@ -44,6 +45,7 @@ const mockResponseBody : CompaniesResource = ({
4445
date_of_cessation: (new Date("19910212")),
4546
date_of_creation: (new Date("19910212")),
4647
kind: "kind",
48+
ordered_alpha_key_with_id: "testcompany:0000789",
4749
previous_company_names: [
4850
{
4951
ceased_on: (new Date("19910212")),
@@ -59,6 +61,9 @@ const mockRequestId = "fdskfhsdoifhsffsif";
5961
const testCompanyName = "TEST COMPANY NAME";
6062
const searchType = "alphabetical";
6163
const startIndex = 0;
64+
const searchBefore = "testcompany:0000784"
65+
const searchafter = "testcompany:0000794"
66+
const page = 0
6267

6368
describe("create a dissolved search GET", () => {
6469
beforeEach(() => {
@@ -80,7 +85,7 @@ describe("create a dissolved search GET", () => {
8085

8186
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
8287
const search: DissolvedSearchService = new DissolvedSearchService(requestClient);
83-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType, startIndex);
88+
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType, startIndex, searchBefore, searchafter, page);
8489

8590
expect(data.httpStatusCode).to.equal(401);
8691
expect(data.resource).to.be.undefined;
@@ -94,7 +99,7 @@ describe("create a dissolved search GET", () => {
9499

95100
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
96101
const search: DissolvedSearchService = new DissolvedSearchService(requestClient);
97-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType, startIndex);
102+
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType, startIndex, searchBefore, searchafter, page);
98103
const item = data.resource.items[0];
99104
const mockItem = mockResponseBody.items[0];
100105

0 commit comments

Comments
 (0)