Skip to content

Commit 3a34ce4

Browse files
Merge pull request #811 from companieshouse/feature/dynamo/ci
CSE-867 - Condensed SIC Code API
2 parents ef3f148 + 2fcf78d commit 3a34ce4

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { AccountsFilingService } from "./services/accounts-filing";
3737
import PscService from "./services/psc/service";
3838
import { LimitedPartnershipsService } from "./services/limited-partnerships"
3939
import AssociationsService from "./services/associations/service";
40+
import { CondensedSicCodeService } from "./services/sic-code";
4041

4142
/**
4243
* ApiClient is the class that all service objects hang off.
@@ -78,6 +79,7 @@ export default class ApiClient {
7879
public readonly pscService: PscService;
7980
public readonly limitedPartnershipsService: LimitedPartnershipsService;
8081
public readonly associationsService: AssociationsService;
82+
public readonly sicCodeService: CondensedSicCodeService;
8183

8284
constructor (readonly apiClient: IHttpClient, readonly accountClient: IHttpClient) {
8385
// services on the api domain using the apiClient
@@ -118,5 +120,6 @@ export default class ApiClient {
118120
this.pscService = new PscService(apiClient);
119121
this.limitedPartnershipsService = new LimitedPartnershipsService(apiClient);
120122
this.associationsService = new AssociationsService(accountClient);
123+
this.sicCodeService = new CondensedSicCodeService(apiClient);
121124
}
122125
}

src/services/sic-code/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./types";
2+
export { default as CondensedSicCodeService } from "./service";

src/services/sic-code/service.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { CondensedSicCodeData } from "./types";
2+
import { HttpResponse, IHttpClient } from "../../http";
3+
import Resource from "../resource";
4+
5+
export default class {
6+
constructor (private readonly client: IHttpClient) {}
7+
8+
public async getCondensedSicCodes (): Promise<Resource<CondensedSicCodeData[]>> {
9+
const url: string = "/internal/condensed-sic-codes";
10+
11+
const resp: HttpResponse = await this.client.httpGet(url);
12+
13+
const resource: Resource<CondensedSicCodeData[]> = {
14+
httpStatusCode: resp.status
15+
};
16+
17+
if (resp.error && resp.status !== 400) {
18+
resource.resource = resp.error;
19+
return resource;
20+
}
21+
22+
const apiResource: CondensedSicCodeData[] = resp.body ? resp.body : resp.error;
23+
24+
if (!apiResource) {
25+
throw new Error(`No body or error body returned from ${url} API call - http status from API = ${resp.status}`);
26+
}
27+
resource.resource = apiResource;
28+
29+
return resource;
30+
}
31+
}

src/services/sic-code/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface CondensedSicCodeData {
2+
sic_code: string,
3+
sic_description: string,
4+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { CondensedSicCodeService, CondensedSicCodeData } from "../../../src/services/sic-code";
2+
import sinon from "sinon";
3+
import chai from "chai";
4+
import Resource, { ApiErrorResponse } from "../../../src/services/resource";
5+
import { RequestClient } from "../../../src/http";
6+
7+
const requestClient = new RequestClient({ baseUrl: "URL-NOT-USED", oauthToken: "TOKEN-NOT-USED" });
8+
const expect = chai.expect;
9+
10+
beforeEach(() => {
11+
sinon.reset();
12+
sinon.restore();
13+
});
14+
15+
afterEach((done) => {
16+
sinon.reset();
17+
sinon.restore();
18+
done();
19+
});
20+
21+
describe("Get Condensed SIC Code data", () => {
22+
it("Should return Condensed SIC Code data", async () => {
23+
const mockResponseBody = [
24+
{ sic_code: "00001", sic_description: "SIC 1" },
25+
{ sic_code: "00002", sic_description: "SIC 2" },
26+
{ sic_code: "00003", sic_description: "SIC 3" }
27+
];
28+
29+
sinon.stub(requestClient, "httpGet").resolves({
30+
status: 200,
31+
body: mockResponseBody
32+
});
33+
34+
const service: CondensedSicCodeService = new CondensedSicCodeService(requestClient);
35+
36+
const response = await service.getCondensedSicCodes() as Resource<CondensedSicCodeData[]>;
37+
38+
expect(response.httpStatusCode).to.be.equal(200);
39+
expect(response.resource).to.be.equal(mockResponseBody);
40+
});
41+
});

0 commit comments

Comments
 (0)