Skip to content

Commit 472b461

Browse files
Added tests for the output of observations
1 parent 8d31797 commit 472b461

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

api/test/indicators.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ describe('Indicators', () => {
519519
assert.strictEqual(body.data.id, indicator);
520520
});
521521

522-
it('should have the indicator` type', () => {
522+
it('should have the `indicator` type', () => {
523523
assert.strictEqual(body.data.type, 'indicator');
524524
});
525525

@@ -565,7 +565,7 @@ describe('Indicators', () => {
565565

566566
it('should have a `dateModified` attribute', () => {
567567
assert.strictEqual(typeof body.data.attributes.dateModified, 'string');
568-
assert.ok(!isNaN(new Date(body.data.attributes.dateModified)), 'attribute `dateModified` is not a valid date');
568+
assert.strictEqual(body.data.attributes.dateModified, new Date(body.data.attributes.dateModified).toISOString());
569569
});
570570

571571
it('should have a relationship link to the indicator\'s observations', () => {

api/test/observations.js

Lines changed: 100 additions & 0 deletions
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('Observations', () => {
69
describe('Model', () => {
@@ -605,8 +608,105 @@ describe('Observations', () => {
605608
});
606609

607610
describe('API', () => {
611+
let server;
612+
613+
before(() => {
614+
server = api.start();
615+
});
616+
617+
after(() => {
618+
server.close();
619+
});
620+
608621
describe('Output', () => {
622+
const observation = '41f7ef3e-2dd1-4864-ac77-5daa4c13f04f';
623+
const indicator = 'indicator1';
624+
const timeseries = 'd3a06c6b-82a7-4efa-8f0f-6cb453deff2c';
625+
const uri = `http://localhost:8000/observations/${observation}`;
626+
let body;
627+
before(async () => {
628+
return new Promise(async (resolve, reject) => {
629+
const options = {
630+
uri,
631+
json: true
632+
};
633+
try {
634+
({body} = await request(options));
635+
resolve();
636+
} catch (err) {
637+
reject(err);
638+
}
639+
});
640+
});
641+
it('should have an id', () => {
642+
assert.strictEqual(body.data.id, observation);
643+
});
644+
645+
it('should have the `observation` type', () => {
646+
assert.strictEqual(body.data.type, 'observation');
647+
});
648+
649+
it('should have a link to itself', () => {
650+
assert.strictEqual(typeof body.data.links, 'object');
651+
assert.strictEqual(body.data.links.self, uri);
652+
});
653+
654+
it('should have a valid ISO date as the `period` attribute', () => {
655+
const options = {
656+
year: 'numeric',
657+
month: '2-digit',
658+
day: '2-digit'
659+
};
660+
assert.notStrictEqual(body.data.attributes.period, undefined);
661+
assert.strictEqual(body.data.attributes.period, new Date(body.data.attributes.period).toLocaleDateString(undefined, options));
662+
});
609663

664+
it('should have an object for the `dimensions` attribute', () => {
665+
const dimensions = {
666+
geographicArea: '24'
667+
};
668+
assert.strictEqual(typeof body.data.attributes.dimensions, 'object');
669+
assert.strictEqual(JSON.stringify(body.data.attributes.dimensions), JSON.stringify(dimensions));
670+
});
671+
672+
it('should have a a `value` attribute', () => {
673+
assert.notStrictEqual(body.data.attributes.value, undefined);
674+
});
675+
676+
it('should have a a `status` attribute', () => {
677+
assert.notStrictEqual(body.data.attributes.status, undefined);
678+
});
679+
680+
it('should have a valid ISO timestamp as the `dateModified` attribute', () => {
681+
assert.notStrictEqual(body.data.attributes.dateModified, undefined);
682+
assert.strictEqual(body.data.attributes.dateModified, new Date(body.data.attributes.dateModified).toISOString());
683+
});
684+
685+
it('should have a relationship link to the observations\'s revisions', () => {
686+
assert.strictEqual(body.data.relationships.revisions.links.self, `${uri}/revisions`);
687+
});
688+
689+
it('should have a relationship link to the observations\'s notes', () => {
690+
assert.strictEqual(body.data.relationships.notes.links.self, `${uri}/notes`);
691+
});
692+
693+
it('should have a relationship link to the observations\'s indicator', () => {
694+
assert.strictEqual(body.data.relationships.indicator.links.self, `http://localhost:8000/indicators/${indicator}`);
695+
});
696+
697+
it('should have a relationship reference to the observations\'s indicator', () => {
698+
assert.strictEqual(body.data.relationships.indicator.data.id, indicator);
699+
assert.strictEqual(body.data.relationships.indicator.data.type, 'indicator');
700+
});
701+
702+
it('should have a relationship link to the observations\'s timeseries', () => {
703+
assert.strictEqual(body.data.relationships.timeseries.links.self, `http://localhost:8000/timeseries/${timeseries}`);
704+
});
705+
706+
it('should have a relationship reference to the observations\'s timeseries', () => {
707+
assert.strictEqual(body.data.relationships.timeseries.data.id, timeseries);
708+
assert.strictEqual(body.data.relationships.timeseries.data.type, 'timeseries');
709+
});
610710
});
611711

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

0 commit comments

Comments
 (0)