|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | /* eslint "node/no-unpublished-require": 0 */
|
3 | 3 | const assert = require('assert');
|
| 4 | +const util = require('util'); |
| 5 | +const request = util.promisify(require('request')); |
| 6 | +const api = require('../index'); |
4 | 7 |
|
5 | 8 | describe('Timeseries', () => {
|
6 | 9 | describe('Model', () => {
|
@@ -493,8 +496,68 @@ describe('Timeseries', () => {
|
493 | 496 | });
|
494 | 497 |
|
495 | 498 | describe('API', () => {
|
| 499 | + let server; |
| 500 | + |
| 501 | + before(() => { |
| 502 | + server = api.start(); |
| 503 | + }); |
| 504 | + |
| 505 | + after(() => { |
| 506 | + server.close(); |
| 507 | + }); |
| 508 | + |
496 | 509 | 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 | + }); |
497 | 552 |
|
| 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 | + }); |
498 | 561 | });
|
499 | 562 |
|
500 | 563 | describe('Routes', () => {
|
|
0 commit comments