diff --git a/src/restClient.axios.test.ts b/src/restClient.axios.test.ts index 35897ddb..61a03ab1 100644 --- a/src/restClient.axios.test.ts +++ b/src/restClient.axios.test.ts @@ -17,4 +17,32 @@ describe('axios tests without mocking', () => { }) expect(requestUri).toEqual('https://api.todoist.com/rest/v2/tasks?ids=12345%2C56789') }) + + test('GET calls do not serialise null values', () => { + const requestUri = axios.create().getUri({ + method: 'GET', + baseURL: DEFAULT_BASE_URI, + params: { + ids: null, + }, + paramsSerializer: { + serialize: paramsSerializer, + }, + }) + expect(requestUri).toEqual('https://api.todoist.com/rest/v2/tasks') + }) + + test('GET calls do not serialise undefined values', () => { + const requestUri = axios.create().getUri({ + method: 'GET', + baseURL: DEFAULT_BASE_URI, + params: { + ids: undefined, + }, + paramsSerializer: { + serialize: paramsSerializer, + }, + }) + expect(requestUri).toEqual('https://api.todoist.com/rest/v2/tasks') + }) }) diff --git a/src/restClient.ts b/src/restClient.ts index 6b3f8594..bc11bbe2 100644 --- a/src/restClient.ts +++ b/src/restClient.ts @@ -12,10 +12,12 @@ export function paramsSerializer(params: Record) { Object.keys(params).forEach((key) => { const value = params[key] - if (Array.isArray(value)) { - qs.append(key, value.join(',')) - } else { - qs.append(key, String(value)) + if (value != null) { + if (Array.isArray(value)) { + qs.append(key, value.join(',')) + } else { + qs.append(key, String(value)) + } } })