diff --git a/src/DPKpi.ts b/src/DPKpi.ts index f983d67..d56e357 100644 --- a/src/DPKpi.ts +++ b/src/DPKpi.ts @@ -12,12 +12,18 @@ export default class DPKpi { this.#token = toToken(token); } - public async getResults(kpiId: string): Promise { + public async getResults( + kpiId: string, + advancedOptions?: Record, + ): Promise { const request: AxiosRequestConfig = { method: 'get', url: `/kpi/${kpiId}`, baseURL: this.baseUrl, - params: { view: 'api' }, + params: { + ...(advancedOptions ?? {}), + view: 'api', + }, headers: { Authorization: this.#token }, }; const { data } = await query(request); diff --git a/src/__tests__/DPKpi.test.ts b/src/__tests__/DPKpi.test.ts index 14cd54e..814b8e3 100644 --- a/src/__tests__/DPKpi.test.ts +++ b/src/__tests__/DPKpi.test.ts @@ -38,3 +38,35 @@ test('get kpi from DevicePilot', async () => { timeout: 30000, }); }); + +test('get kpi from DevicePilot with advanced options', async () => { + const kpiToken = 'ghi'; + const kpiId = '1234'; + const url = 'http://url.com?If-None-Match=placeholder'; + const headers = { location: url }; + const dp = new DPKpi(kpiToken); + + m(axios).mockReset(); + m(axios) + // @ts-expect-error: return type isn't important + .mockResolvedValueOnce({ headers }) + // @ts-expect-error: return type isn't important + .mockResolvedValueOnce({ data: 'data', headers: { etag: 'placeholder' } }) + // @ts-expect-error: return type isn't important + .mockResolvedValueOnce({ data: 'data', headers: { etag: '' } }); + await dp.getResults(kpiId, { scope: 'hello' }); + + expect(axios).toHaveBeenNthCalledWith(1, { + method: 'get', + headers: { Authorization: `TOKEN ${kpiToken}` }, + baseURL: 'https://api.devicepilot.com', + params: { view: 'api', scope: 'hello' }, + url: `/kpi/${kpiId}`, + timeout: 30000, + }); + expect(axios).toHaveBeenCalledWith({ + method: 'get', + url, + timeout: 30000, + }); +});