File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
src/services/order/order-item Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 11import { IHttpClient } from "../../../http" ;
2- import { ApiResult } from "../../../services/resource" ;
3- import { failure , success } from "../../../services/result" ;
2+ import { failure , Result , success } from "../../../services/result" ;
43import Mapping from "../../../mapping/mapping" ;
54import { Item , ItemResource } from "../order" ;
65
6+ export type OrderItemErrorResponse = {
7+ httpStatusCode ?: number ;
8+ error ?: string ;
9+ } ;
10+
711export 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
Original file line number Diff line number Diff line change 11import sinon from "sinon" ;
22import { 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" ;
44import { expect } from "chai" ;
55import { Success } from "../../../src/services/result" ;
66import { 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} ) ;
You can’t perform that action at this time.
0 commit comments