Skip to content

Commit 3ce97b6

Browse files
refactor: Convert functions with 2+ params to use named parameters (#373)
Co-authored-by: Claude <[email protected]>
1 parent 34504b5 commit 3ce97b6

18 files changed

+1311
-1268
lines changed

src/TodoistApi.activities.test.ts

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ describe('TodoistApi activity endpoints', () => {
6969
await api.getActivityLogs()
7070

7171
expect(requestMock).toHaveBeenCalledTimes(1)
72-
expect(requestMock).toHaveBeenCalledWith(
73-
'GET',
74-
getSyncBaseUri(),
75-
ENDPOINT_REST_ACTIVITIES,
76-
DEFAULT_AUTH_TOKEN,
77-
{},
78-
)
72+
expect(requestMock).toHaveBeenCalledWith({
73+
httpMethod: 'GET',
74+
baseUri: getSyncBaseUri(),
75+
relativePath: ENDPOINT_REST_ACTIVITIES,
76+
apiToken: DEFAULT_AUTH_TOKEN,
77+
payload: {},
78+
})
7979
})
8080

8181
test('returns activity events from response', async () => {
@@ -105,16 +105,16 @@ describe('TodoistApi activity endpoints', () => {
105105
limit: 10,
106106
})
107107

108-
expect(requestMock).toHaveBeenCalledWith(
109-
'GET',
110-
getSyncBaseUri(),
111-
ENDPOINT_REST_ACTIVITIES,
112-
DEFAULT_AUTH_TOKEN,
113-
{
108+
expect(requestMock).toHaveBeenCalledWith({
109+
httpMethod: 'GET',
110+
baseUri: getSyncBaseUri(),
111+
relativePath: ENDPOINT_REST_ACTIVITIES,
112+
apiToken: DEFAULT_AUTH_TOKEN,
113+
payload: {
114114
cursor: 'prev_cursor',
115115
limit: 10,
116116
},
117-
)
117+
})
118118
expect(result.nextCursor).toBe('next_cursor_token')
119119
})
120120

@@ -131,17 +131,17 @@ describe('TodoistApi activity endpoints', () => {
131131
parentProjectId: '789',
132132
})
133133

134-
expect(requestMock).toHaveBeenCalledWith(
135-
'GET',
136-
getSyncBaseUri(),
137-
ENDPOINT_REST_ACTIVITIES,
138-
DEFAULT_AUTH_TOKEN,
139-
{
134+
expect(requestMock).toHaveBeenCalledWith({
135+
httpMethod: 'GET',
136+
baseUri: getSyncBaseUri(),
137+
relativePath: ENDPOINT_REST_ACTIVITIES,
138+
apiToken: DEFAULT_AUTH_TOKEN,
139+
payload: {
140140
objectType: 'item',
141141
eventType: 'completed',
142142
parentProjectId: '789',
143143
},
144-
)
144+
})
145145
})
146146

147147
test('handles unknown event types and fields without crashing', async () => {
@@ -177,16 +177,16 @@ describe('TodoistApi activity endpoints', () => {
177177
until: untilDate,
178178
})
179179

180-
expect(requestMock).toHaveBeenCalledWith(
181-
'GET',
182-
getSyncBaseUri(),
183-
ENDPOINT_REST_ACTIVITIES,
184-
DEFAULT_AUTH_TOKEN,
185-
{
180+
expect(requestMock).toHaveBeenCalledWith({
181+
httpMethod: 'GET',
182+
baseUri: getSyncBaseUri(),
183+
relativePath: ENDPOINT_REST_ACTIVITIES,
184+
apiToken: DEFAULT_AUTH_TOKEN,
185+
payload: {
186186
since: '2025-01-15',
187187
until: '2025-01-20',
188188
},
189-
)
189+
})
190190
})
191191

192192
test('leaves string dates as-is for backward compatibility', async () => {
@@ -201,16 +201,16 @@ describe('TodoistApi activity endpoints', () => {
201201
until: '2025-01-20',
202202
})
203203

204-
expect(requestMock).toHaveBeenCalledWith(
205-
'GET',
206-
getSyncBaseUri(),
207-
ENDPOINT_REST_ACTIVITIES,
208-
DEFAULT_AUTH_TOKEN,
209-
{
204+
expect(requestMock).toHaveBeenCalledWith({
205+
httpMethod: 'GET',
206+
baseUri: getSyncBaseUri(),
207+
relativePath: ENDPOINT_REST_ACTIVITIES,
208+
apiToken: DEFAULT_AUTH_TOKEN,
209+
payload: {
210210
since: '2025-01-15',
211211
until: '2025-01-20',
212212
},
213-
)
213+
})
214214
})
215215

216216
test('converts Date objects with correct timezone handling', async () => {
@@ -229,15 +229,15 @@ describe('TodoistApi activity endpoints', () => {
229229

230230
const expectedSince = `${sinceDate.getFullYear()}-01-15`
231231

232-
expect(requestMock).toHaveBeenCalledWith(
233-
'GET',
234-
getSyncBaseUri(),
235-
ENDPOINT_REST_ACTIVITIES,
236-
DEFAULT_AUTH_TOKEN,
237-
{
232+
expect(requestMock).toHaveBeenCalledWith({
233+
httpMethod: 'GET',
234+
baseUri: getSyncBaseUri(),
235+
relativePath: ENDPOINT_REST_ACTIVITIES,
236+
apiToken: DEFAULT_AUTH_TOKEN,
237+
payload: {
238238
since: expectedSince,
239239
},
240-
)
240+
})
241241
})
242242

243243
test('converts modern objectType "task" to legacy "item" in API request', async () => {
@@ -251,15 +251,15 @@ describe('TodoistApi activity endpoints', () => {
251251
objectType: 'task',
252252
})
253253

254-
expect(requestMock).toHaveBeenCalledWith(
255-
'GET',
256-
getSyncBaseUri(),
257-
ENDPOINT_REST_ACTIVITIES,
258-
DEFAULT_AUTH_TOKEN,
259-
{
254+
expect(requestMock).toHaveBeenCalledWith({
255+
httpMethod: 'GET',
256+
baseUri: getSyncBaseUri(),
257+
relativePath: ENDPOINT_REST_ACTIVITIES,
258+
apiToken: DEFAULT_AUTH_TOKEN,
259+
payload: {
260260
objectType: 'item',
261261
},
262-
)
262+
})
263263
})
264264

265265
test('converts modern objectType "comment" to legacy "note" in API request', async () => {
@@ -273,15 +273,15 @@ describe('TodoistApi activity endpoints', () => {
273273
objectType: 'comment',
274274
})
275275

276-
expect(requestMock).toHaveBeenCalledWith(
277-
'GET',
278-
getSyncBaseUri(),
279-
ENDPOINT_REST_ACTIVITIES,
280-
DEFAULT_AUTH_TOKEN,
281-
{
276+
expect(requestMock).toHaveBeenCalledWith({
277+
httpMethod: 'GET',
278+
baseUri: getSyncBaseUri(),
279+
relativePath: ENDPOINT_REST_ACTIVITIES,
280+
apiToken: DEFAULT_AUTH_TOKEN,
281+
payload: {
282282
objectType: 'note',
283283
},
284-
)
284+
})
285285
})
286286

287287
test('leaves project objectType unchanged', async () => {
@@ -295,15 +295,15 @@ describe('TodoistApi activity endpoints', () => {
295295
objectType: 'project',
296296
})
297297

298-
expect(requestMock).toHaveBeenCalledWith(
299-
'GET',
300-
getSyncBaseUri(),
301-
ENDPOINT_REST_ACTIVITIES,
302-
DEFAULT_AUTH_TOKEN,
303-
{
298+
expect(requestMock).toHaveBeenCalledWith({
299+
httpMethod: 'GET',
300+
baseUri: getSyncBaseUri(),
301+
relativePath: ENDPOINT_REST_ACTIVITIES,
302+
apiToken: DEFAULT_AUTH_TOKEN,
303+
payload: {
304304
objectType: 'project',
305305
},
306-
)
306+
})
307307
})
308308

309309
test('converts legacy "item" to modern "task" in response', async () => {
@@ -389,15 +389,15 @@ describe('TodoistApi activity endpoints', () => {
389389
objectType: 'item',
390390
})
391391

392-
expect(requestMock).toHaveBeenCalledWith(
393-
'GET',
394-
getSyncBaseUri(),
395-
ENDPOINT_REST_ACTIVITIES,
396-
DEFAULT_AUTH_TOKEN,
397-
{
392+
expect(requestMock).toHaveBeenCalledWith({
393+
httpMethod: 'GET',
394+
baseUri: getSyncBaseUri(),
395+
relativePath: ENDPOINT_REST_ACTIVITIES,
396+
apiToken: DEFAULT_AUTH_TOKEN,
397+
payload: {
398398
objectType: 'item',
399399
},
400-
)
400+
})
401401
})
402402

403403
test('supports backward compatibility with legacy "note" in request', async () => {
@@ -411,15 +411,15 @@ describe('TodoistApi activity endpoints', () => {
411411
objectType: 'note',
412412
})
413413

414-
expect(requestMock).toHaveBeenCalledWith(
415-
'GET',
416-
getSyncBaseUri(),
417-
ENDPOINT_REST_ACTIVITIES,
418-
DEFAULT_AUTH_TOKEN,
419-
{
414+
expect(requestMock).toHaveBeenCalledWith({
415+
httpMethod: 'GET',
416+
baseUri: getSyncBaseUri(),
417+
relativePath: ENDPOINT_REST_ACTIVITIES,
418+
apiToken: DEFAULT_AUTH_TOKEN,
419+
payload: {
420420
objectType: 'note',
421421
},
422-
)
422+
})
423423
})
424424
})
425425
})

src/TodoistApi.comments.test.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ describe('TodoistApi comment endpoints', () => {
3131
await api.getComments(getCommentsArgs)
3232

3333
expect(requestMock).toHaveBeenCalledTimes(1)
34-
expect(requestMock).toHaveBeenCalledWith(
35-
'GET',
36-
getSyncBaseUri(),
37-
ENDPOINT_REST_COMMENTS,
38-
DEFAULT_AUTH_TOKEN,
39-
getCommentsArgs,
40-
)
34+
expect(requestMock).toHaveBeenCalledWith({
35+
httpMethod: 'GET',
36+
baseUri: getSyncBaseUri(),
37+
relativePath: ENDPOINT_REST_COMMENTS,
38+
apiToken: DEFAULT_AUTH_TOKEN,
39+
payload: getCommentsArgs,
40+
})
4141
})
4242

4343
test('returns result from rest client', async () => {
@@ -72,12 +72,12 @@ describe('TodoistApi comment endpoints', () => {
7272
await api.getComment(commentId)
7373

7474
expect(requestMock).toHaveBeenCalledTimes(1)
75-
expect(requestMock).toHaveBeenCalledWith(
76-
'GET',
77-
getSyncBaseUri(),
78-
`${ENDPOINT_REST_COMMENTS}/${commentId}`,
79-
DEFAULT_AUTH_TOKEN,
80-
)
75+
expect(requestMock).toHaveBeenCalledWith({
76+
httpMethod: 'GET',
77+
baseUri: getSyncBaseUri(),
78+
relativePath: `${ENDPOINT_REST_COMMENTS}/${commentId}`,
79+
apiToken: DEFAULT_AUTH_TOKEN,
80+
})
8181
})
8282

8383
test('returns result from rest client', async () => {
@@ -103,14 +103,14 @@ describe('TodoistApi comment endpoints', () => {
103103
await api.addComment(addCommentArgs, DEFAULT_REQUEST_ID)
104104

105105
expect(requestMock).toHaveBeenCalledTimes(1)
106-
expect(requestMock).toHaveBeenCalledWith(
107-
'POST',
108-
getSyncBaseUri(),
109-
ENDPOINT_REST_COMMENTS,
110-
DEFAULT_AUTH_TOKEN,
111-
addCommentArgs,
112-
DEFAULT_REQUEST_ID,
113-
)
106+
expect(requestMock).toHaveBeenCalledWith({
107+
httpMethod: 'POST',
108+
baseUri: getSyncBaseUri(),
109+
relativePath: ENDPOINT_REST_COMMENTS,
110+
apiToken: DEFAULT_AUTH_TOKEN,
111+
payload: addCommentArgs,
112+
requestId: DEFAULT_REQUEST_ID,
113+
})
114114
})
115115

116116
test('returns result from rest client', async () => {
@@ -136,14 +136,14 @@ describe('TodoistApi comment endpoints', () => {
136136
await api.updateComment(taskId, updateCommentArgs, DEFAULT_REQUEST_ID)
137137

138138
expect(requestMock).toHaveBeenCalledTimes(1)
139-
expect(requestMock).toHaveBeenCalledWith(
140-
'POST',
141-
getSyncBaseUri(),
142-
`${ENDPOINT_REST_COMMENTS}/${taskId}`,
143-
DEFAULT_AUTH_TOKEN,
144-
updateCommentArgs,
145-
DEFAULT_REQUEST_ID,
146-
)
139+
expect(requestMock).toHaveBeenCalledWith({
140+
httpMethod: 'POST',
141+
baseUri: getSyncBaseUri(),
142+
relativePath: `${ENDPOINT_REST_COMMENTS}/${taskId}`,
143+
apiToken: DEFAULT_AUTH_TOKEN,
144+
payload: updateCommentArgs,
145+
requestId: DEFAULT_REQUEST_ID,
146+
})
147147
})
148148

149149
test('returns success result from rest client', async () => {
@@ -167,14 +167,14 @@ describe('TodoistApi comment endpoints', () => {
167167
await api.deleteComment(taskId, DEFAULT_REQUEST_ID)
168168

169169
expect(requestMock).toHaveBeenCalledTimes(1)
170-
expect(requestMock).toHaveBeenCalledWith(
171-
'DELETE',
172-
getSyncBaseUri(),
173-
`${ENDPOINT_REST_COMMENTS}/${taskId}`,
174-
DEFAULT_AUTH_TOKEN,
175-
undefined,
176-
DEFAULT_REQUEST_ID,
177-
)
170+
expect(requestMock).toHaveBeenCalledWith({
171+
httpMethod: 'DELETE',
172+
baseUri: getSyncBaseUri(),
173+
relativePath: `${ENDPOINT_REST_COMMENTS}/${taskId}`,
174+
apiToken: DEFAULT_AUTH_TOKEN,
175+
payload: undefined,
176+
requestId: DEFAULT_REQUEST_ID,
177+
})
178178
})
179179

180180
test('returns success result from rest client', async () => {

0 commit comments

Comments
 (0)