Skip to content

Commit 3674da1

Browse files
authored
Merge pull request #122 from companieshouse/BI-7129-allow-new-query-param-alphabetical-search
Add logic to getCompanies to determine correct end point to query
2 parents 229728b + 4001787 commit 3674da1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ import Resource from "../../resource";
44

55
export default class DissolvedSearchService {
66
constructor (private readonly client: IHttpClient) { }
7-
public async getCompanies (companyName: string, requestId: string): Promise<Resource<CompaniesResource>> {
7+
public async getCompanies (companyName: string, requestId: string, searchType: string): Promise<Resource<CompaniesResource>> {
88
const additionalHeaders = {
99
"X-Request-ID": requestId,
1010
"Content-Type": "application/json"
1111
}
12-
const dissolvedSearchURL = "/dissolved-search/companies?q=" + companyName;
12+
const ALPHABETICAL_QUERY = "&search_type=alphabetical";
13+
const BEST_MATCH_QUERY = "&search_type=best-match";
14+
15+
let dissolvedSearchURL = "/dissolved-search/companies?q=" + companyName;
16+
17+
if (searchType === "alphabetical") {
18+
dissolvedSearchURL += ALPHABETICAL_QUERY;
19+
} else {
20+
dissolvedSearchURL += BEST_MATCH_QUERY;
21+
};
1322

1423
const resp = await this.client.httpGet(dissolvedSearchURL, additionalHeaders);
1524

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const mockResponseBody : CompaniesResource = ({
5656

5757
const mockRequestId = "fdskfhsdoifhsffsif";
5858
const testCompanyName = "TEST COMPANY NAME";
59+
const searchType = "alphabetical";
5960

6061
describe("create a dissolved search GET", () => {
6162
beforeEach(() => {
@@ -77,7 +78,7 @@ describe("create a dissolved search GET", () => {
7778

7879
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
7980
const search: DissolvedSearchService = new DissolvedSearchService(requestClient);
80-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId);
81+
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType);
8182

8283
expect(data.httpStatusCode).to.equal(401);
8384
expect(data.resource).to.be.undefined;
@@ -91,7 +92,7 @@ describe("create a dissolved search GET", () => {
9192

9293
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
9394
const search: DissolvedSearchService = new DissolvedSearchService(requestClient);
94-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId);
95+
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType);
9596
const item = data.resource.items[0];
9697
const mockItem = mockResponseBody.items[0];
9798

0 commit comments

Comments
 (0)