Skip to content

Commit 43b86e9

Browse files
fix: convert camelCase to snake_case for GET request parameters (#380)
Co-authored-by: Claude <[email protected]>
1 parent 7f4bc44 commit 43b86e9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/rest-client.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,39 @@ describe('restClient', () => {
120120
expect(result).toBe('filter=today&ids=1%2C2%2C3')
121121
})
122122

123+
test('GET request converts camelCase parameters to snake_case in URL', async () => {
124+
mockSuccessfulResponse(DEFAULT_RESPONSE_DATA)
125+
126+
await request({
127+
httpMethod: 'GET',
128+
baseUri: DEFAULT_BASE_URI,
129+
relativePath: DEFAULT_ENDPOINT,
130+
apiToken: DEFAULT_AUTH_TOKEN,
131+
payload: {
132+
projectId: '123',
133+
isCompleted: true,
134+
parentItemId: '456',
135+
dueDatetime: '2024-01-01T12:00:00Z',
136+
},
137+
})
138+
139+
// Verify the fetch was called with URL containing snake_case parameters
140+
expect(mockFetch).toHaveBeenCalledWith(
141+
expect.stringContaining('project_id=123'),
142+
expect.objectContaining({
143+
method: 'GET',
144+
headers: AUTHORIZATION_HEADERS,
145+
}),
146+
)
147+
148+
// Verify all camelCase parameters were converted to snake_case
149+
const [actualUrl] = mockFetch.mock.calls[0]
150+
expect(actualUrl).toContain('project_id=123')
151+
expect(actualUrl).toContain('is_completed=true')
152+
expect(actualUrl).toContain('parent_item_id=456')
153+
expect(actualUrl).toContain('due_datetime=2024-01-01T12%3A00%3A00Z')
154+
})
155+
123156
test('POST request with JSON payload', async () => {
124157
mockSuccessfulResponse(DEFAULT_RESPONSE_DATA)
125158

src/rest-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ export async function request<T>(args: RequestArgs): Promise<HttpResponse<T>> {
143143
case 'GET':
144144
// For GET requests, add query parameters to URL
145145
if (payload) {
146-
const queryString = paramsSerializer(payload)
146+
// Convert payload from camelCase to snake_case
147+
const convertedPayload = snakeCaseKeys(payload)
148+
const queryString = paramsSerializer(convertedPayload)
147149
if (queryString) {
148150
const separator = url.includes('?') ? '&' : '?'
149151
finalUrl = `${url}${separator}${queryString}`

0 commit comments

Comments
 (0)