Skip to content

Commit

Permalink
fix requests params
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 10, 2024
1 parent c59fca4 commit f4d4623
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions ui/src/api/CWaterPumpAPIImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ui/src/api/CWaterPumpAPIImpl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f4d4623

Please sign in to comment.