11import { AxonOps } from '../../src/sdk' ;
22import { Axon } from '../../src/sdk/axon' ;
3- import type { AxonView , AxonListView } from '../../src/resources/axons' ;
3+ import type { AxonView } from '../../src/resources/axons' ;
44
55jest . mock ( '../../src/sdk/axon' ) ;
66
@@ -77,19 +77,25 @@ describe('AxonOps', () => {
7777 } ) ;
7878
7979 describe ( 'list' , ( ) => {
80- it ( 'should list axons and wrap as Axon instances' , async ( ) => {
81- const mockListView : AxonListView = {
82- axons : [
83- { id : 'axn_1' , created_at_ms : Date . now ( ) , name : 'axon-1' } ,
84- { id : 'axn_2' , created_at_ms : Date . now ( ) , name : 'axon-2' } ,
85- { id : 'axn_3' , created_at_ms : Date . now ( ) } ,
86- ] ,
80+ function mockPageResult ( items : AxonView [ ] ) {
81+ return {
82+ [ Symbol . asyncIterator ] : async function * ( ) {
83+ yield * items ;
84+ } ,
8785 } ;
88- mockClient . axons . list . mockResolvedValue ( mockListView ) ;
86+ }
87+
88+ it ( 'should list axons and wrap as Axon instances' , async ( ) => {
89+ const mockAxons : AxonView [ ] = [
90+ { id : 'axn_1' , created_at_ms : Date . now ( ) , name : 'axon-1' } ,
91+ { id : 'axn_2' , created_at_ms : Date . now ( ) , name : 'axon-2' } ,
92+ { id : 'axn_3' , created_at_ms : Date . now ( ) } ,
93+ ] ;
94+ mockClient . axons . list . mockResolvedValue ( mockPageResult ( mockAxons ) ) ;
8995
9096 const axons = await axonOps . list ( ) ;
9197
92- expect ( mockClient . axons . list ) . toHaveBeenCalledWith ( undefined ) ;
98+ expect ( mockClient . axons . list ) . toHaveBeenCalledWith ( undefined , undefined ) ;
9399 expect ( Axon . fromId ) . toHaveBeenCalledTimes ( 3 ) ;
94100 expect ( Axon . fromId ) . toHaveBeenCalledWith ( mockClient , 'axn_1' ) ;
95101 expect ( Axon . fromId ) . toHaveBeenCalledWith ( mockClient , 'axn_2' ) ;
@@ -98,19 +104,27 @@ describe('AxonOps', () => {
98104 } ) ;
99105
100106 it ( 'should return empty array when no axons exist' , async ( ) => {
101- mockClient . axons . list . mockResolvedValue ( { axons : [ ] } ) ;
107+ mockClient . axons . list . mockResolvedValue ( mockPageResult ( [ ] ) ) ;
102108
103109 const axons = await axonOps . list ( ) ;
104110
105111 expect ( axons ) . toHaveLength ( 0 ) ;
106112 } ) ;
107113
114+ it ( 'should pass filter params' , async ( ) => {
115+ mockClient . axons . list . mockResolvedValue ( mockPageResult ( [ ] ) ) ;
116+
117+ await axonOps . list ( { name : 'my-axon' , limit : 10 } ) ;
118+
119+ expect ( mockClient . axons . list ) . toHaveBeenCalledWith ( { name : 'my-axon' , limit : 10 } , undefined ) ;
120+ } ) ;
121+
108122 it ( 'should pass request options' , async ( ) => {
109- mockClient . axons . list . mockResolvedValue ( { axons : [ ] } ) ;
123+ mockClient . axons . list . mockResolvedValue ( mockPageResult ( [ ] ) ) ;
110124
111- await axonOps . list ( { timeout : 3000 } ) ;
125+ await axonOps . list ( undefined , { timeout : 3000 } ) ;
112126
113- expect ( mockClient . axons . list ) . toHaveBeenCalledWith ( { timeout : 3000 } ) ;
127+ expect ( mockClient . axons . list ) . toHaveBeenCalledWith ( undefined , { timeout : 3000 } ) ;
114128 } ) ;
115129 } ) ;
116130} ) ;
0 commit comments