11import APIClient from '../../src/apiClient' ;
22import { Grants } from '../../src/resources/grants' ;
3- jest . mock ( '../src/apiClient' ) ;
3+ jest . mock ( '../../ src/apiClient' ) ;
44
55describe ( 'Grants' , ( ) => {
66 let apiClient : jest . Mocked < APIClient > ;
77 let grants : Grants ;
88
9- beforeAll ( ( ) => {
9+ beforeEach ( ( ) => {
1010 apiClient = new APIClient ( {
1111 apiKey : 'apiKey' ,
1212 apiUri : 'https://api.nylas.com' ,
@@ -15,7 +15,15 @@ describe('Grants', () => {
1515 } ) as jest . Mocked < APIClient > ;
1616
1717 grants = new Grants ( apiClient ) ;
18- apiClient . request . mockResolvedValue ( { } ) ;
18+
19+ // Create a spy implementation that captures the inputs
20+ apiClient . request = jest . fn ( ) . mockImplementation ( input => {
21+ // eslint-disable-next-line no-console
22+ console . log ( 'Request input:' , JSON . stringify ( input , null , 2 ) ) ;
23+ return Promise . resolve ( {
24+ data : [ ] ,
25+ } ) ;
26+ } ) ;
1927 } ) ;
2028
2129 describe ( 'list' , ( ) => {
@@ -27,23 +35,95 @@ describe('Grants', () => {
2735 } ,
2836 } ) ;
2937
30- expect ( apiClient . request ) . toHaveBeenCalledWith ( {
31- method : 'GET' ,
32- path : '/v3/grants' ,
33- overrides : {
34- apiUri : 'https://test.api.nylas.com' ,
35- headers : { override : 'bar' } ,
36- } ,
37- } ) ;
38+ expect ( apiClient . request ) . toHaveBeenCalledWith (
39+ expect . objectContaining ( {
40+ method : 'GET' ,
41+ path : '/v3/grants' ,
42+ overrides : {
43+ apiUri : 'https://test.api.nylas.com' ,
44+ headers : { override : 'bar' } ,
45+ } ,
46+ } )
47+ ) ;
3848 } ) ;
3949
4050 it ( 'should call apiClient.request even without overrides set' , async ( ) => {
4151 await grants . list ( ) ;
4252
43- expect ( apiClient . request ) . toHaveBeenCalledWith ( {
44- method : 'GET' ,
45- path : '/v3/grants' ,
53+ expect ( apiClient . request ) . toHaveBeenCalledWith (
54+ expect . objectContaining ( {
55+ method : 'GET' ,
56+ path : '/v3/grants' ,
57+ } )
58+ ) ;
59+ } ) ;
60+
61+ it ( 'should properly pass queryParams when provided in the first parameter' , async ( ) => {
62+ await grants . list ( {
63+ queryParams : {
64+ limit : 10 ,
65+ offset : 5 ,
66+ provider : 'google' ,
67+ } ,
4668 } ) ;
69+
70+ expect ( apiClient . request ) . toHaveBeenCalledWith (
71+ expect . objectContaining ( {
72+ method : 'GET' ,
73+ path : '/v3/grants' ,
74+ queryParams : {
75+ limit : 10 ,
76+ offset : 5 ,
77+ provider : 'google' ,
78+ } ,
79+ } )
80+ ) ;
81+ } ) ;
82+
83+ it ( 'should properly pass both queryParams and overrides when provided' , async ( ) => {
84+ await grants . list ( {
85+ queryParams : {
86+ limit : 20 ,
87+ provider : 'microsoft' ,
88+ } ,
89+ overrides : {
90+ apiUri : 'https://custom.api.nylas.com' ,
91+ headers : { custom : 'header' } ,
92+ } ,
93+ } ) ;
94+
95+ expect ( apiClient . request ) . toHaveBeenCalledWith (
96+ expect . objectContaining ( {
97+ method : 'GET' ,
98+ path : '/v3/grants' ,
99+ queryParams : {
100+ limit : 20 ,
101+ provider : 'microsoft' ,
102+ } ,
103+ overrides : {
104+ apiUri : 'https://custom.api.nylas.com' ,
105+ headers : { custom : 'header' } ,
106+ } ,
107+ } )
108+ ) ;
109+ } ) ;
110+
111+ it ( 'should support the deprecated _queryParams parameter' , async ( ) => {
112+ await grants . list ( { } , {
113+ limit : 15 ,
114+ provider : 'imap' ,
115+ } as any ) ;
116+
117+ expect ( apiClient . request ) . toHaveBeenCalledWith (
118+ expect . objectContaining ( {
119+ method : 'GET' ,
120+ path : '/v3/grants' ,
121+ queryParams : {
122+ limit : 15 ,
123+ provider : 'imap' ,
124+ } ,
125+ } )
126+ ) ;
47127 } ) ;
48128 } ) ;
49129
0 commit comments