Skip to content

Commit 83537c4

Browse files
authored
Merge branch 'main' into TW-3761-node-sdk-events-import-support
2 parents c519a09 + b555cde commit 83537c4

File tree

2 files changed

+109
-18
lines changed

2 files changed

+109
-18
lines changed

src/resources/grants.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import {
1010
ListGrantsQueryParams,
1111
UpdateGrantRequest,
1212
} from '../models/grants.js';
13+
import { ListQueryParams } from '../models/listQueryParams.js';
14+
15+
/**
16+
* @property queryParams The query parameters to include in the request
17+
*/
18+
export interface ListGrantsParams {
19+
queryParams?: ListGrantsQueryParams;
20+
}
1321

1422
/**
1523
* @property grantId The id of the Grant to retrieve.
@@ -45,13 +53,16 @@ export class Grants extends Resource {
4553
* @return The list of Grants
4654
*/
4755
public async list(
48-
{ overrides }: Overrides = {},
49-
queryParams?: ListGrantsQueryParams
56+
{ overrides, queryParams }: Overrides & ListGrantsParams = {},
57+
/**
58+
* @deprecated Use `queryParams` instead.
59+
*/
60+
_queryParams?: ListQueryParams
5061
): Promise<NylasListResponse<Grant>> {
5162
return super._list<NylasListResponse<Grant>>({
52-
queryParams,
63+
queryParams: queryParams ?? _queryParams ?? undefined,
5364
path: `/v3/grants`,
54-
overrides,
65+
overrides: overrides ?? {},
5566
});
5667
}
5768

tests/resources/grants.spec.ts

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import APIClient from '../../src/apiClient';
22
import { Grants } from '../../src/resources/grants';
3-
jest.mock('../src/apiClient');
3+
jest.mock('../../src/apiClient');
44

55
describe('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

Comments
 (0)