Skip to content

Commit 4ee0660

Browse files
Merge pull request #22 from sentinel-hub/feature/tests-mock
Feature/tests mock
2 parents fc90cf7 + 3ec9bcb commit 4ee0660

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/layer/__mocks__/axios.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
get: jest.fn(() => {
3+
// axios.get() response:
4+
return Promise.resolve({ data: {} });
5+
}),
6+
interceptors: {
7+
request: {
8+
use: () => {},
9+
},
10+
response: {
11+
use: () => {},
12+
},
13+
},
14+
};

src/layer/__tests__/WmsLayer.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'jest-setup';
2+
import axios from 'src/layer/__mocks__/axios';
23

34
import { BBox, CRS_EPSG4326, ApiType, MimeTypes, WmsLayer } from 'src';
45

@@ -36,3 +37,45 @@ test('WmsLayer.getMapUrl returns an URL', () => {
3637
expect(imageUrl).not.toHaveQueryParams(['showlogo']);
3738
expect(imageUrl).not.toHaveQueryParams(['transparent']);
3839
});
40+
41+
test('WmsLayer.getMap makes an appropriate request', () => {
42+
const bbox = new BBox(CRS_EPSG4326, 19, 20, 20, 21);
43+
const layerId = 'PROBAV_S1_TOA_333M';
44+
const layer = new WmsLayer(
45+
'https://proba-v-mep.esa.int/applications/geo-viewer/app/geoserver/ows',
46+
layerId,
47+
);
48+
49+
const getMapParams = {
50+
bbox: bbox,
51+
fromTime: new Date(Date.UTC(2020, 1 - 1, 10, 0, 0, 0)), // 2020-01-10/2020-01-10
52+
toTime: new Date(Date.UTC(2020, 1 - 1, 10, 23, 59, 59)),
53+
width: 512,
54+
height: 512,
55+
format: MimeTypes.JPEG,
56+
};
57+
layer.getMap(getMapParams, ApiType.WMS);
58+
59+
expect(axios.get).toHaveBeenCalledTimes(1);
60+
61+
const call: any = axios.get.mock.calls[0]; // cast to `any` so we can access the parameters
62+
const [url, axiosParams] = call;
63+
64+
expect(url).toHaveOrigin('https://proba-v-mep.esa.int');
65+
expect(url).toHaveQueryParamsValues({
66+
service: 'WMS',
67+
version: '1.1.1',
68+
request: 'GetMap',
69+
format: 'image/jpeg',
70+
layers: layerId,
71+
crs: 'EPSG:4326',
72+
bbox: '19,20,20,21',
73+
time: '2020-01-10T00:00:00.000Z/2020-01-10T23:59:59.000Z',
74+
width: '512',
75+
height: '512',
76+
});
77+
expect(axiosParams).toEqual({
78+
responseType: 'blob',
79+
useCache: true,
80+
});
81+
});

0 commit comments

Comments
 (0)