Skip to content

Commit

Permalink
update type
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Mar 13, 2020
1 parent 13d60e8 commit 6ef0c5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { apiService } from '../utils';
import { HttpFetchError } from '../../../../../../../../src/core/public/http/http_fetch_error';

describe('snapshot API', () => {
let fetchMock: jest.SpyInstance<Promise<Partial<Response>>>;
let mockResponse: Partial<Response>;
let fetchMock: jest.SpyInstance<Partial<unknown>>;
let mockResponse: Partial<unknown>;

beforeEach(() => {
apiService.http = {
get: jest.fn(),
};
} as any;
fetchMock = jest.spyOn(apiService.http, 'get');
mockResponse = { up: 3, down: 12, total: 15 };
});
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('snapshot API', () => {
});

it('throws an error when response is not ok', async () => {
mockResponse = new HttpFetchError('There was an error fetching your data.', 'error', {});
mockResponse = new HttpFetchError('There was an error fetching your data.', 'error', {} as any);
fetchMock.mockReturnValue(mockResponse);
let error: Error | undefined;
try {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/uptime/public/state/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ApiService {
return ApiService.instance;
}

public async get(apiUrl: string, params: HttpFetchQuery) {
public async get(apiUrl: string, params?: HttpFetchQuery) {
const response = await this._http!.get(apiUrl, { query: params });
if (response instanceof Error) {
throw response;
Expand Down
8 changes: 2 additions & 6 deletions x-pack/legacy/plugins/uptime/public/state/effects/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { call, put, takeLatest, select } from 'redux-saga/effects';
import { call, put, takeLatest } from 'redux-saga/effects';
import { Action } from 'redux-actions';
import {
FETCH_MONITOR_DETAILS,
Expand All @@ -15,16 +15,13 @@ import {
FETCH_MONITOR_LOCATIONS_FAIL,
} from '../actions/monitor';
import { fetchMonitorDetails, fetchMonitorLocations } from '../api';
import { getBasePath } from '../selectors';
import { MonitorDetailsActionPayload } from '../actions/types';

function* monitorDetailsEffect(action: Action<any>) {
const { monitorId, dateStart, dateEnd }: MonitorDetailsActionPayload = action.payload;
try {
const basePath = yield select(getBasePath);
const response = yield call(fetchMonitorDetails, {
monitorId,
basePath,
dateStart,
dateEnd,
});
Expand All @@ -37,8 +34,7 @@ function* monitorDetailsEffect(action: Action<any>) {
function* monitorLocationsEffect(action: Action<any>) {
const payload = action.payload;
try {
const basePath = yield select(getBasePath);
const response = yield call(fetchMonitorLocations, { basePath, ...payload });
const response = yield call(fetchMonitorLocations, payload);
yield put({ type: FETCH_MONITOR_LOCATIONS_SUCCESS, payload: response });
} catch (error) {
yield put({ type: FETCH_MONITOR_LOCATIONS_FAIL, payload: error.message });
Expand Down

0 comments on commit 6ef0c5c

Please sign in to comment.