Skip to content

Commit 4fc6d77

Browse files
authored
Merge pull request #451 from companieshouse/feature/fix_order_item_error_model
Change data structure of order item err model
2 parents 2dc8592 + 83b10b5 commit 4fc6d77

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/services/order/order-item/service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { IHttpClient } from "../../../http";
2-
import { ApiResult } from "../../../services/resource";
3-
import { failure, success } from "../../../services/result";
2+
import { failure, Result, success } from "../../../services/result";
43
import Mapping from "../../../mapping/mapping";
54
import { Item, ItemResource } from "../order";
65

6+
export type OrderItemErrorResponse = {
7+
httpStatusCode?: number;
8+
error?: string;
9+
};
10+
711
export default class OrderItemService {
812
private static readonly EXCLUDED_FIELDS = {
913
deep: true,
@@ -16,13 +20,13 @@ export default class OrderItemService {
1620

1721
constructor (private readonly client: IHttpClient) { }
1822

19-
public async getOrderItem (orderId: string, itemId: string): Promise<ApiResult<Item>> {
23+
public async getOrderItem (orderId: string, itemId: string): Promise<Result<Item, OrderItemErrorResponse>> {
2024
const resp = await this.client.httpGet(`/orders/${orderId}/items/${itemId}`);
2125

2226
if (resp.error) {
2327
return failure({
2428
httpStatusCode: resp.status,
25-
errors: resp?.error?.errors || resp.error
29+
error: resp.error?.error
2630
});
2731
}
2832

test/services/order-item/service.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sinon from "sinon";
22
import { IHttpClient, RequestClient } from "../../../src";
3-
import OrderItemService from "../../../src/services/order/order-item/service";
3+
import OrderItemService, { OrderItemErrorResponse } from "../../../src/services/order/order-item/service";
44
import { expect } from "chai";
55
import { Success } from "../../../src/services/result";
66
import { Item } from "../../../src/services/order/order";
@@ -154,7 +154,9 @@ describe("OrderItemService", () => {
154154
// given
155155
const serverResponse = {
156156
status: 401,
157-
error: "An error occurred"
157+
error: {
158+
error: "An error occurred"
159+
}
158160
};
159161
sandbox.mock(requestClient)
160162
.expects("httpGet")
@@ -164,11 +166,11 @@ describe("OrderItemService", () => {
164166
const orderItemService = new OrderItemService(requestClient);
165167

166168
// when
167-
const actual = await orderItemService.getOrderItem("ORD-123123-123123", "CCD-123456-123456") as Failure<Item, ApiErrorResponse>;
169+
const actual = await orderItemService.getOrderItem("ORD-123123-123123", "CCD-123456-123456") as Failure<Item, OrderItemErrorResponse>;
168170

169171
expect(actual.isFailure()).to.be.true;
170172
expect(actual.value.httpStatusCode).to.equal(401);
171-
expect(actual.value.errors).to.equal("An error occurred");
173+
expect(actual.value.error).to.equal("An error occurred");
172174
});
173175
});
174176
});

0 commit comments

Comments
 (0)