From f4d462332166b2a49491f483aeab82ca193759d4 Mon Sep 17 00:00:00 2001 From: GreenWizard2015 Date: Wed, 10 Jan 2024 22:15:29 +0000 Subject: [PATCH] fix requests params --- ui/src/api/CWaterPumpAPIImpl.js | 7 +++---- ui/src/api/CWaterPumpAPIImpl.test.js | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ui/src/api/CWaterPumpAPIImpl.js b/ui/src/api/CWaterPumpAPIImpl.js index e83837f..995f260 100644 --- a/ui/src/api/CWaterPumpAPIImpl.js +++ b/ui/src/api/CWaterPumpAPIImpl.js @@ -13,21 +13,21 @@ class CWaterPumpAPIImpl { async start(runTimeMs) { const { response: { data }, requestTime } = await this._execute( - async () => await this._client.get('/pour_tea', { milliseconds: runTimeMs }) + async () => await this._client.get('/pour_tea', { params: { milliseconds: runTimeMs } }) ); return this.preprocessResponse({ response: data, requestTime }); } async stop() { const { response: { data }, requestTime } = await this._execute( - async () => await this._client.get('/stop', {}) + async () => await this._client.get('/stop', { params: {} }) ); return this.preprocessResponse({ response: data, requestTime }); } async status() { const { response: { data }, requestTime } = await this._execute( - async () => await this._client.get('/status', {}) + async () => await this._client.get('/status', { params: {} }) ); return this.preprocessResponse({ response: data, requestTime }); } @@ -36,7 +36,6 @@ class CWaterPumpAPIImpl { preprocessResponse({ response, requestTime }) { if(null == response) return null; if('error' in response) { - // TODO: handle errors in slice/SystemStatus.js throw new Error(response.error); } // make a deep copy of response diff --git a/ui/src/api/CWaterPumpAPIImpl.test.js b/ui/src/api/CWaterPumpAPIImpl.test.js index 8d75b99..5a61036 100644 --- a/ui/src/api/CWaterPumpAPIImpl.test.js +++ b/ui/src/api/CWaterPumpAPIImpl.test.js @@ -19,14 +19,14 @@ describe('CWaterPumpAPIImpl', () => { await expect(apiCall(api)).rejects.toThrow(errorMessage); } - async function shouldBeCalledWith(apiCall, url, params=null) { + async function shouldBeCalledWith(apiCall, url, params) { const mockClient = { get: jest.fn() }; mockClient.get.mockResolvedValue({ data: DUMMY_STATUS }); const api = new CWaterPumpAPIImpl({ client: mockClient }); await apiCall(api); - expect(mockClient.get).toHaveBeenCalledWith(url, params); + expect(mockClient.get).toHaveBeenCalledWith(url, { params }); } async function shouldRethrowError(apiCall) {