Skip to content

Commit b14e99b

Browse files
authored
Merge pull request #287 from companieshouse/add-start-index-advanced
BI-9341 - Add start index paramater to sdk to enable paging
2 parents 54e9bb8 + c0a63af commit b14e99b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import "url-search-params-polyfill";
55

66
export default class AdvancedSearchService {
77
constructor (private readonly client: IHttpClient) { }
8-
public async getCompanies (companyNameIncludes: string | null, companyNameExcludes: string | null, location: string | null, incorporatedFrom: string | null,
8+
public async getCompanies (startIndex: number | null, companyNameIncludes: string | null, companyNameExcludes: string | null, location: string | null, incorporatedFrom: string | null,
99
incorporatedTo: string | null, sicCodes: string | null, companyStatus: string | null, companyType: string | null, dissolvedFrom: string | null,
1010
dissolvedTo: string | null, requestId: string): Promise<Resource<CompaniesResource>> {
11+
const START_INDEX_QUERY = "start_index";
1112
const COMPANY_NAME_INCLUDES_QUERY = "company_name_includes";
1213
const COMPANY_NAME_EXCLUDES_QUERY = "company_name_excludes"
1314
const LOCATION_QUERY = "location";
@@ -25,6 +26,10 @@ export default class AdvancedSearchService {
2526

2627
const buildEnhancedSearchURL = new URLSearchParams("/enhanced-search/companies?");
2728

29+
if (startIndex !== null) {
30+
buildEnhancedSearchURL.append(START_INDEX_QUERY, String(startIndex));
31+
}
32+
2833
if (companyNameIncludes !== null) {
2934
buildEnhancedSearchURL.append(COMPANY_NAME_INCLUDES_QUERY, companyNameIncludes)
3035
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const mockResponseBody : CompaniesResource = ({
6767
})
6868

6969
const mockRequestId = "fdskfhsdoifhsffsif";
70+
const testStartIndex = 0;
7071
const testCompanyNameIncludes = "INCLUDES";
7172
const testCompanyNameExcludes = "EXCLUDES"
7273
const testLocation = "TEST LOCATION";
@@ -99,7 +100,7 @@ describe("create an advanced search GET", () => {
99100

100101
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
101102
const search: AdvancedSearchService = new AdvancedSearchService(requestClient);
102-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyNameIncludes, testCompanyNameExcludes, testLocation, testIncorporatedFrom,
103+
const data: Resource<CompaniesResource> = await search.getCompanies(testStartIndex, testCompanyNameIncludes, testCompanyNameExcludes, testLocation, testIncorporatedFrom,
103104
testIncorporatedTo, testSicCodes, testCompanyStatus, testCompanyType, testDissolvedFrom, testDissolvedTo, mockRequestId);
104105

105106
expect(data.httpStatusCode).to.equal(401);
@@ -114,7 +115,7 @@ describe("create an advanced search GET", () => {
114115

115116
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
116117
const search: AdvancedSearchService = new AdvancedSearchService(requestClient);
117-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyNameIncludes, testCompanyNameExcludes, testLocation, testIncorporatedFrom,
118+
const data: Resource<CompaniesResource> = await search.getCompanies(testStartIndex, testCompanyNameIncludes, testCompanyNameExcludes, testLocation, testIncorporatedFrom,
118119
testIncorporatedTo, testSicCodes, testCompanyStatus, testCompanyNameIncludes, testDissolvedFrom, testDissolvedTo, mockRequestId);
119120
const item = data.resource.items[0];
120121
const mockItem = mockResponseBody.items[0];

0 commit comments

Comments
 (0)