Skip to content

Commit f2c0d86

Browse files
Merge branch 'master' into feature/faml-746-psc-discrepancies
2 parents 4828df1 + 26043b0 commit f2c0d86

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AlphabeticalSearchService from "./services/search/alphabetical-search/ser
1111
import DissolvedSearchService from "./services/search/dissolved-search/service";
1212
import PSCDiscrepancyService from "./services/psc-discrepancies/service";
1313
import PSCDiscrepancyReportService from "./services/psc-discrepancies-report/service";
14-
import { PSCDiscrepanciesReportService } from "services/psc-discrepancies-report";
14+
import { PSCDiscrepanciesReportService } from "./services/psc-discrepancies-report";
1515

1616
/**
1717
* ApiClient is the class that all service objects hang off.

src/services/psc-discrepancies-report/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { IHttpClient } from "../../http";
22
import { PSCDiscrepancyReport } from "./types"
33
import Util from "./util"
4-
import { Result } from "services/result";
5-
import { ApiResponse, ApiErrorResponse } from "services/resource";
4+
import { Result } from "../../services/result";
5+
import { ApiResponse, ApiErrorResponse } from "../../services/resource";
66

77
const PSC_DISCREPANCY_API_URL = "/psc-discrepancy-reports";
88

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
import { IHttpClient } from "../../../http";
22
import { CompaniesResource } from "./types";
33
import Resource from "../../resource";
4+
import { start } from "repl";
45

56
export default class DissolvedSearchService {
67
constructor (private readonly client: IHttpClient) { }
7-
public async getCompanies (companyName: string, requestId: string, searchType: string): Promise<Resource<CompaniesResource>> {
8+
public async getCompanies (companyName: string, requestId: string, searchType: string, startIndex: number): Promise<Resource<CompaniesResource>> {
89
const additionalHeaders = {
910
"X-Request-ID": requestId,
1011
"Content-Type": "application/json"
1112
}
1213
const ALPHABETICAL_QUERY = "&search_type=alphabetical";
1314
const BEST_MATCH_QUERY = "&search_type=best-match";
1415
const PREVIOUS_NAME_QUERY = "&search_type=previous-name-dissolved";
16+
const START_INDEX_QUERY = "&start_index=" + startIndex;
1517

1618
let dissolvedSearchURL = "/dissolved-search/companies?q=" + companyName;
1719

1820
if (searchType === "alphabetical") {
1921
dissolvedSearchURL += ALPHABETICAL_QUERY;
2022
}
21-
if (searchType === "previousNameDissolved") {
23+
24+
if (!startIndex && searchType === "previousNameDissolved") {
2225
dissolvedSearchURL += PREVIOUS_NAME_QUERY;
2326
}
24-
if (searchType === "bestMatch") {
27+
28+
if (startIndex && searchType === "previousNameDissolved") {
29+
dissolvedSearchURL += PREVIOUS_NAME_QUERY + START_INDEX_QUERY;
30+
}
31+
32+
if (!startIndex && searchType === "bestMatch") {
2533
dissolvedSearchURL += BEST_MATCH_QUERY;
2634
}
2735

36+
if (startIndex && searchType === "bestMatch") {
37+
dissolvedSearchURL += BEST_MATCH_QUERY + START_INDEX_QUERY;
38+
}
39+
2840
const resp = await this.client.httpGet(dissolvedSearchURL, additionalHeaders);
2941

3042
const resource: Resource<CompaniesResource> = {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface CompaniesResource {
33
items: Items[];
44
kind: string;
55
top_hit: TopHit;
6+
hits: number;
67
}
78

89
export interface Items {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ const mockResponseBody : CompaniesResource = ({
5151
name: "old name"
5252
}
5353
]
54-
}
54+
},
55+
hits: 20
5556
});
5657

5758
const mockRequestId = "fdskfhsdoifhsffsif";
5859
const testCompanyName = "TEST COMPANY NAME";
5960
const searchType = "alphabetical";
61+
const startIndex = 0;
6062

6163
describe("create a dissolved search GET", () => {
6264
beforeEach(() => {
@@ -78,7 +80,7 @@ describe("create a dissolved search GET", () => {
7880

7981
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
8082
const search: DissolvedSearchService = new DissolvedSearchService(requestClient);
81-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType);
83+
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType, startIndex);
8284

8385
expect(data.httpStatusCode).to.equal(401);
8486
expect(data.resource).to.be.undefined;
@@ -92,7 +94,7 @@ describe("create a dissolved search GET", () => {
9294

9395
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetRequest);
9496
const search: DissolvedSearchService = new DissolvedSearchService(requestClient);
95-
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType);
97+
const data: Resource<CompaniesResource> = await search.getCompanies(testCompanyName, mockRequestId, searchType, startIndex);
9698
const item = data.resource.items[0];
9799
const mockItem = mockResponseBody.items[0];
98100

@@ -121,5 +123,6 @@ describe("create a dissolved search GET", () => {
121123
expect(data.resource.top_hit.previous_company_names[0].ceased_on).to.equal(mockResponseBody.top_hit.previous_company_names[0].ceased_on);
122124
expect(data.resource.top_hit.previous_company_names[0].effective_from).to.equal(mockResponseBody.top_hit.previous_company_names[0].effective_from);
123125
expect(data.resource.top_hit.previous_company_names[0].name).to.equal(mockResponseBody.top_hit.previous_company_names[0].name);
126+
expect(data.resource.hits).to.equal(mockResponseBody.hits);
124127
});
125128
});

0 commit comments

Comments
 (0)