Skip to content

Commit 9717834

Browse files
Added more test data for observations unit tests
1 parent 7a5b921 commit 9717834

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed

api/test/indicators.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ describe('Indicators', () => {
3636

3737
it('should offset the list by the `start` argument', async () => {
3838
return new Promise(async (resolve, reject) => {
39-
const list = await indicators.list(1, 10).catch(reject);
39+
const start0 = await indicators.list(0, 10).catch(reject);
40+
const start1 = await indicators.list(1, 10).catch(reject);
4041
try {
41-
assert.strictEqual(list.list[0].id, 'indicator2');
42+
assert.strictEqual(start1.list[0].id, start0.list[1].id);
4243
resolve();
4344
} catch (e) {
4445
reject(e);
@@ -144,7 +145,7 @@ describe('Indicators', () => {
144145
const indicator = 'indicator1';
145146
const observationsList = await indicators.listObservations(indicator, 0, 10).catch(reject);
146147
try {
147-
assert.strictEqual(observationsList.length, 7);
148+
assert.strictEqual(observationsList.length, 5);
148149
for (const {type, relationships: {indicator: {data: {id: observationIndicator}}}} of observationsList.list) {
149150
assert.strictEqual(type, 'observation');
150151
assert.strictEqual(indicator, observationIndicator);

test_data/test_data.sql

+68-13
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ VALUES ('699b644d-dd26-430d-9f56-b4fc6760569c', (SELECT id FROM type_sex WHERE n
156156
INSERT INTO timeseries_dimension_sex (timeseries_id, value_id)
157157
VALUES ('ac139d12-22ce-45ba-a63e-14f1dc9f3ec4', (SELECT id FROM type_sex WHERE name = 'male'));
158158

159+
REFRESH MATERIALIZED VIEW "mvTimeseriesDimensions";
160+
159161
WITH o AS (
160162
INSERT INTO observations (period, timeseries_id)
161163
VALUES ('2019-01-01', 'd3a06c6b-82a7-4efa-8f0f-6cb453deff2c')
@@ -180,46 +182,99 @@ WITH o AS (
180182
RETURNING id
181183
)
182184
INSERT INTO observation_values (observation_id, value)
183-
SELECT id, 2.5 FROM o;
185+
SELECT id, 29 FROM o;
184186

185187
WITH o AS (
186188
INSERT INTO observations (period, timeseries_id)
187189
VALUES ('2019-02-01', '3d9e3917-8a39-4eb6-917c-bf485dd0b20b')
188190
RETURNING id
189191
)
190192
INSERT INTO observation_values (observation_id, value)
191-
SELECT id, 2.9 FROM o;
193+
SELECT id, 35 FROM o;
194+
195+
WITH o AS (
196+
INSERT INTO observations (period, timeseries_id)
197+
VALUES ('2019-03-01', '3d9e3917-8a39-4eb6-917c-bf485dd0b20b')
198+
RETURNING id
199+
), v AS (
200+
INSERT INTO observation_values (observation_id)
201+
SELECT id FROM o
202+
RETURNING id
203+
)
204+
INSERT INTO observation_status (observation_value_id, observation_status_id)
205+
SELECT id, (SELECT id FROM status WHERE name = 'not_available') FROM v;
192206

193207
---
194208

195209
WITH o AS (
196210
INSERT INTO observations (period, timeseries_id)
197-
VALUES ('2019-01-01', '3d9e3917-8a39-4eb6-917c-bf485dd0b20b')
211+
VALUES ('2019-01-01', 'e052c4b3-ae8b-43ca-a6f7-ff75fcfc49c5')
198212
RETURNING id
199213
)
200214
INSERT INTO observation_values (observation_id, value)
201-
SELECT id, 29 FROM o;
215+
SELECT id, 234.3 FROM o;
202216

203217
WITH o AS (
204218
INSERT INTO observations (period, timeseries_id)
205-
VALUES ('2019-02-01', '3d9e3917-8a39-4eb6-917c-bf485dd0b20b')
219+
VALUES ('2019-02-01', 'e052c4b3-ae8b-43ca-a6f7-ff75fcfc49c5')
206220
RETURNING id
207221
)
208222
INSERT INTO observation_values (observation_id, value)
209-
SELECT id, 35 FROM o;
223+
SELECT id, 240.8 FROM o;
224+
225+
---
210226

211227
WITH o AS (
212228
INSERT INTO observations (period, timeseries_id)
213-
VALUES ('2019-03-01', '3d9e3917-8a39-4eb6-917c-bf485dd0b20b')
229+
VALUES ('2019-01-01', 'e6c20549-b6a6-4107-8bfe-6f67f962d65a')
214230
RETURNING id
215-
), v AS (
216-
INSERT INTO observation_values (observation_id)
217-
SELECT id FROM o
231+
)
232+
INSERT INTO observation_values (observation_id, value)
233+
SELECT id, 256 FROM o;
234+
235+
WITH o AS (
236+
INSERT INTO observations (period, timeseries_id)
237+
VALUES ('2019-02-01', 'e6c20549-b6a6-4107-8bfe-6f67f962d65a')
218238
RETURNING id
219239
)
220-
INSERT INTO observation_status (observation_value_id, observation_status_id)
221-
SELECT id, (SELECT id FROM status WHERE name = 'not_available') FROM v;
240+
INSERT INTO observation_values (observation_id, value)
241+
SELECT id, 270 FROM o;
222242

223243
---
224244

225-
REFRESH MATERIALIZED VIEW "mvTimeseriesDimensions";
245+
WITH o AS (
246+
INSERT INTO observations (period, timeseries_id)
247+
VALUES ('2019-01-01', '699b644d-dd26-430d-9f56-b4fc6760569c')
248+
RETURNING id
249+
)
250+
INSERT INTO observation_values (observation_id, value)
251+
SELECT id, 120.5 FROM o;
252+
253+
WITH o AS (
254+
INSERT INTO observations (period, timeseries_id)
255+
VALUES ('2019-02-01', '699b644d-dd26-430d-9f56-b4fc6760569c')
256+
RETURNING id
257+
)
258+
INSERT INTO observation_values (observation_id, value)
259+
SELECT id, 140.2 FROM o;
260+
261+
---
262+
263+
264+
WITH o AS (
265+
INSERT INTO observations (period, timeseries_id)
266+
VALUES ('2019-01-01', 'ac139d12-22ce-45ba-a63e-14f1dc9f3ec4')
267+
RETURNING id
268+
)
269+
INSERT INTO observation_values (observation_id, value)
270+
SELECT id, 45.2 FROM o;
271+
272+
WITH o AS (
273+
INSERT INTO observations (period, timeseries_id)
274+
VALUES ('2019-02-01', 'ac139d12-22ce-45ba-a63e-14f1dc9f3ec4')
275+
RETURNING id
276+
)
277+
INSERT INTO observation_values (observation_id, value)
278+
SELECT id, 19.9 FROM o;
279+
280+
---

0 commit comments

Comments
 (0)