Skip to content

Commit 9948681

Browse files
dded tests for the output of timeseries
1 parent 472b461 commit 9948681

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

api/test/timeseries.js

+63
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-env mocha */
22
/* eslint "node/no-unpublished-require": 0 */
33
const assert = require('assert');
4+
const util = require('util');
5+
const request = util.promisify(require('request'));
6+
const api = require('../index');
47

58
describe('Timeseries', () => {
69
describe('Model', () => {
@@ -493,8 +496,68 @@ describe('Timeseries', () => {
493496
});
494497

495498
describe('API', () => {
499+
let server;
500+
501+
before(() => {
502+
server = api.start();
503+
});
504+
505+
after(() => {
506+
server.close();
507+
});
508+
496509
describe('Output', () => {
510+
const timeseries = 'd3a06c6b-82a7-4efa-8f0f-6cb453deff2c';
511+
const indicator = 'indicator1';
512+
const uri = `http://localhost:8000/timeseries/${timeseries}`;
513+
let body;
514+
before(async () => {
515+
return new Promise(async (resolve, reject) => {
516+
const options = {
517+
uri,
518+
json: true
519+
};
520+
try {
521+
({body} = await request(options));
522+
resolve();
523+
} catch (err) {
524+
reject(err);
525+
}
526+
});
527+
});
528+
it('should have an id', () => {
529+
assert.strictEqual(body.data.id, timeseries);
530+
});
531+
532+
it('should have the `observation` type', () => {
533+
assert.strictEqual(body.data.type, 'timeseries');
534+
});
535+
536+
it('should have a link to itself', () => {
537+
assert.strictEqual(typeof body.data.links, 'object');
538+
assert.strictEqual(body.data.links.self, uri);
539+
});
540+
541+
it('should have an object for the `dimensions` attribute', () => {
542+
const dimensions = {
543+
geographicArea: '24'
544+
};
545+
assert.strictEqual(typeof body.data.attributes.dimensions, 'object');
546+
assert.strictEqual(JSON.stringify(body.data.attributes.dimensions), JSON.stringify(dimensions));
547+
});
548+
549+
it('should have a relationship link to the timeseries\' observations', () => {
550+
assert.strictEqual(body.data.relationships.observations.links.self, `${uri}/observations`);
551+
});
497552

553+
it('should have a relationship link to the timeseries\' indicator', () => {
554+
assert.strictEqual(body.data.relationships.indicator.links.self, `http://localhost:8000/indicators/${indicator}`);
555+
});
556+
557+
it('should have a relationship reference to the timeseries\' indicator', () => {
558+
assert.strictEqual(body.data.relationships.indicator.data.id, indicator);
559+
assert.strictEqual(body.data.relationships.indicator.data.type, 'indicator');
560+
});
498561
});
499562

500563
describe('Routes', () => {

0 commit comments

Comments
 (0)