11import  nock  from  'nock' 
22import  {  Client  }  from  '../../Client' 
3- import  {  mockOrderCancellations  }  from  './mockOrderCancellations' 
3+ import  {  mockOrderCancellation  }  from  './mockOrderCancellations' 
44import  {  OrderCancellations  }  from  './OrderCancellations' 
55
66describe ( 'OrderCancellations' ,  ( )  =>  { 
@@ -11,7 +11,7 @@ describe('OrderCancellations', () => {
1111  test ( 'should create a order cancellation' ,  async  ( )  =>  { 
1212    nock ( / ( .* ) / ) 
1313      . post ( `/air/order_cancellations` ) 
14-       . reply ( 200 ,  {  data : mockOrderCancellations  } ) 
14+       . reply ( 200 ,  {  data : mockOrderCancellation  } ) 
1515
1616    const  response  =  await  new  OrderCancellations ( 
1717      new  Client ( {  token : 'mockToken'  } ) 
@@ -24,13 +24,59 @@ describe('OrderCancellations', () => {
2424  test ( 'should confirm the order cancellation' ,  async  ( )  =>  { 
2525    nock ( / ( .* ) / ) 
2626      . post ( 
27-         `/air/order_cancellations/${ mockOrderCancellations . id }  /actions/confirm` 
27+         `/air/order_cancellations/${ mockOrderCancellation . id }  /actions/confirm` 
2828      ) 
29-       . reply ( 200 ,  {  data : mockOrderCancellations  } ) 
29+       . reply ( 200 ,  {  data : mockOrderCancellation  } ) 
3030
3131    const  response  =  await  new  OrderCancellations ( 
3232      new  Client ( {  token : 'mockToken'  } ) 
3333    ) . confirm ( 'ore_00009qzZWzjDipIkqpaUAj' ) 
3434    expect ( response . data ?. order_id ) . toBe ( 'ord_00009hthhsUZ8W4LxQgkjo' ) 
3535  } ) 
36+ 
37+   test ( 'should get a page of order cancellations' ,  async  ( )  =>  { 
38+     nock ( / ( .* ) / ) 
39+       . get ( `/air/order_cancellations` ) 
40+       . query ( ( queryObject )  =>  { 
41+         expect ( queryObject ?. order_id ) . toBe ( 'ord_123' ) 
42+         expect ( queryObject ?. limit ) . toEqual ( '1' ) 
43+         return  true 
44+       } ) 
45+       . reply ( 200 ,  { 
46+         data : [ mockOrderCancellation ] , 
47+         meta : {  limit : 1 ,  before : null ,  after : null  } , 
48+       } ) 
49+ 
50+     const  response  =  await  new  OrderCancellations ( 
51+       new  Client ( {  token : 'mockToken'  } ) 
52+     ) . list ( { 
53+       order_id : 'ord_123' , 
54+       limit : 1 , 
55+     } ) 
56+     expect ( response . data ) . toHaveLength ( 1 ) 
57+     expect ( response . data [ 0 ] . id ) . toBe ( mockOrderCancellation . id ) 
58+   } ) 
59+ 
60+   test ( 'should get all order cancellations paginated' ,  async  ( )  =>  { 
61+     nock ( / ( .* ) / ) 
62+       . get ( `/air/order_cancellations` ) 
63+       . query ( ( queryObject )  =>  { 
64+         expect ( queryObject ?. order_id ) . toBe ( 'ord_123' ) 
65+         return  true 
66+       } ) 
67+       . reply ( 200 ,  { 
68+         data : [ mockOrderCancellation ] , 
69+         meta : {  limit : 50 ,  before : null ,  after : null  } , 
70+       } ) 
71+ 
72+     const  response  =  await  new  OrderCancellations ( 
73+       new  Client ( {  token : 'mockToken'  } ) 
74+     ) . listWithGenerator ( { 
75+       order_id : 'ord_123' , 
76+     } ) 
77+ 
78+     for  await  ( const  page  of  response )  { 
79+       expect ( page . data . id ) . toBe ( mockOrderCancellation . id ) 
80+     } 
81+   } ) 
3682} ) 
0 commit comments