From 979fba10a0a036a66e3a826f6e76e7919c4ba5b9 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Mon, 2 Oct 2023 12:44:41 +0200 Subject: [PATCH 1/2] Remove chakram --- package.json | 1 - tests/tests/000-root-test.js | 32 ++++++++++---- yarn.lock | 81 +----------------------------------- 3 files changed, 25 insertions(+), 89 deletions(-) diff --git a/package.json b/package.json index ace762be..f9115c52 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "@turf/invariant": "^6.5.0", "chai": "^4.3.10", "chai-http": "^4.4.0", - "chakram": "^1.5.0", "cheerio": "^1.0.0-rc.6", "csv-parse": "^4.15.4", "eslint": "7.26.0", diff --git a/tests/tests/000-root-test.js b/tests/tests/000-root-test.js index 690f52fd..2dbbe911 100644 --- a/tests/tests/000-root-test.js +++ b/tests/tests/000-root-test.js @@ -2,21 +2,35 @@ /* global describe it */ -const chakram = require('chakram'), - expect = chakram.expect; +// const chakram = require('chakram'), +// expect = chakram.expect; + +const chai = require('chai'); +const chaiHttp = require('chai-http'); +const expect = chai.expect; + +chai.use(chaiHttp); const BASE_URL = process.env.OSEM_TEST_BASE_URL; describe('openSenseMap API Routes: /', function () { it('should print available routes', function () { - return chakram.get(BASE_URL) - .then(function (response) { - expect(response).status(200); - expect(response).to.have.header('content-type', 'text/plain; charset=utf-8'); + chai.request(BASE_URL) + .get('/') + .end(function (err, res) { + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res).to.have.header('content-type', 'text/plain; charset=utf-8'); + expect(res.body).not.null; + }); + // return chakram.get(BASE_URL) + // .then(function (response) { + // expect(response).status(200); + // expect(response).to.have.header('content-type', 'text/plain; charset=utf-8'); - expect(response.body).not.empty; + // expect(response.body).not.empty; - return chakram.wait(); - }); + // return chakram.wait(); + // }); }); }); diff --git a/yarn.lock b/yarn.lock index 1e2dc07e..10dadb83 100644 --- a/yarn.lock +++ b/yarn.lock @@ -604,7 +604,7 @@ assert-plus@1.0.0, assert-plus@^1.0.0: resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= -assertion-error@^1.0.1, assertion-error@^1.1.0: +assertion-error@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== @@ -806,11 +806,6 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= -chai-as-promised@5.x.x: - version "5.3.0" - resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-5.3.0.tgz#09d7a402908aa70dfdbead53e5853fc79d3ef21c" - integrity sha1-CdekApCKpw39vq1T5YU/x50+8hw= - chai-http@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/chai-http/-/chai-http-4.4.0.tgz#bb8c346caa25b3c76118c68f7a7cecc0493669b8" @@ -825,20 +820,6 @@ chai-http@^4.4.0: qs "^6.11.2" superagent "^8.0.9" -chai-subset@1.x.x: - version "1.6.0" - resolved "https://registry.yarnpkg.com/chai-subset/-/chai-subset-1.6.0.tgz#a5d0ca14e329a79596ed70058b6646bd6988cfe9" - integrity sha1-pdDKFOMpp5WW7XAFi2ZGvWmIz+k= - -chai@3.x.x: - version "3.5.0" - resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247" - integrity sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc= - dependencies: - assertion-error "^1.0.1" - deep-eql "^0.1.3" - type-detect "^1.0.0" - chai@^4.3.10: version "4.3.10" resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.10.tgz#d784cec635e3b7e2ffb66446a63b4e33bd390384" @@ -852,20 +833,6 @@ chai@^4.3.10: pathval "^1.1.1" type-detect "^4.0.8" -chakram@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/chakram/-/chakram-1.5.0.tgz#3d8b0a88f768dd6ada592a524663cc0dc14ac1cf" - integrity sha1-PYsKiPdo3WraWSpSRmPMDcFKwc8= - dependencies: - chai "3.x.x" - chai-as-promised "5.x.x" - chai-subset "1.x.x" - extend-object "1.x.x" - q "1.x.x" - request "2.x.x" - request-debug "0.x.x" - tv4 "1.x.x" - chalk@^2.0.0: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" @@ -1200,13 +1167,6 @@ dedent@^0.7.0: resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c" integrity sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw= -deep-eql@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" - integrity sha1-71WKyrjeJSBs1xOQbXTlaTDrafI= - dependencies: - type-detect "0.1.1" - deep-eql@^4.1.3: version "4.1.3" resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d" @@ -1584,11 +1544,6 @@ ewma@^2.0.1: dependencies: assert-plus "^1.0.0" -extend-object@1.x.x: - version "1.0.0" - resolved "https://registry.yarnpkg.com/extend-object/-/extend-object-1.0.0.tgz#42514f84015d1356caf5187969dfb2bc1bda0823" - integrity sha1-QlFPhAFdE1bK9Rh5ad+yvBvaCCM= - extend@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" @@ -3047,11 +3002,6 @@ punycode@2.x.x, punycode@^2.1.0, punycode@^2.1.1: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== -q@1.x.x: - version "1.5.1" - resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" - integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc= - qs@^6.11.0, qs@^6.11.2: version "6.11.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9" @@ -3205,14 +3155,7 @@ reinterval@^1.1.0: resolved "https://registry.yarnpkg.com/reinterval/-/reinterval-1.1.0.tgz#3361ecfa3ca6c18283380dd0bb9546f390f5ece7" integrity sha1-M2Hs+jymwYKDOA3Qu5VG85D17Oc= -request-debug@0.x.x: - version "0.2.0" - resolved "https://registry.yarnpkg.com/request-debug/-/request-debug-0.2.0.tgz#fc054ec817181b04ca41a052c136f61c48abaf78" - integrity sha1-/AVOyBcYGwTKQaBSwTb2HEirr3g= - dependencies: - stringify-clone "^1.0.0" - -request@2.x.x, request@~2.88.0: +request@~2.88.0: version "2.88.2" resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw== @@ -3630,11 +3573,6 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -stringify-clone@^1.0.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/stringify-clone/-/stringify-clone-1.1.1.tgz#309a235fb4ecfccd7d388dbe18ba904facaf433b" - integrity sha1-MJojX7Ts/M19OI2+GLqQT6yvQzs= - stringify-stream@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/stringify-stream/-/stringify-stream-1.0.5.tgz#e51407a8fdc4ca0e1c62f149868bacf5cf204050" @@ -3769,11 +3707,6 @@ tunnel-agent@^0.6.0: dependencies: safe-buffer "^5.0.1" -tv4@1.x.x: - version "1.3.0" - resolved "https://registry.yarnpkg.com/tv4/-/tv4-1.3.0.tgz#d020c846fadd50c855abb25ebaecc68fc10f7963" - integrity sha1-0CDIRvrdUMhVq7JeuuzGj8EPeWM= - tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" @@ -3793,16 +3726,6 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -type-detect@0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822" - integrity sha1-C6XsKohWQORw6k6FBZcZANrFiCI= - -type-detect@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2" - integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI= - type-detect@^4.0.0, type-detect@^4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" From e9347f4f55f968ae817ef62e7217b5b1c71b07be Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Mon, 2 Oct 2023 18:50:39 +0200 Subject: [PATCH 2/2] First new tests --- tests/tests/00-cors-test.js | 56 ++- tests/tests/000-root-test.js | 16 +- tests/tests/001-stats-test.js | 104 +++-- ...location_tests.js => 002-location-test.js} | 397 +++++++++++------- 4 files changed, 342 insertions(+), 231 deletions(-) rename tests/tests/{002-location_tests.js => 002-location-test.js} (75%) diff --git a/tests/tests/00-cors-test.js b/tests/tests/00-cors-test.js index 253ba675..88ce89fa 100644 --- a/tests/tests/00-cors-test.js +++ b/tests/tests/00-cors-test.js @@ -2,35 +2,59 @@ /* global describe it */ -const chakram = require('chakram'), - expect = chakram.expect; +const chai = require('chai'); +const chaiHttp = require('chai-http'); +const expect = chai.expect; + +chai.use(chaiHttp); const BASE_URL = process.env.OSEM_TEST_BASE_URL; describe('openSenseMap API CORS test', function () { - it('should always send out CORS headers', function () { - return chakram.get(BASE_URL) - .then(function (response) { + it('should always send out CORS headers', function (done) { + chai.request(BASE_URL) + .get('/') + .end(function (err, response) { expect(response).status(200); expect(response).to.have.header('access-control-allow-origin', '*'); - expect(response).to.have.header('access-control-allow-methods', 'GET, OPTIONS'); - expect(response).to.have.header('access-control-allow-headers', /authorization/i); - expect(response).to.have.header('access-control-expose-headers', /content-disposition/i); + expect(response).to.have.header( + 'access-control-allow-methods', + 'GET, OPTIONS' + ); + expect(response).to.have.header( + 'access-control-allow-headers', + /authorization/i + ); + expect(response).to.have.header( + 'access-control-expose-headers', + /content-disposition/i + ); - return chakram.wait(); + done(); }); }); - it('should send out CORS headers for preflight requests', function () { - return chakram.options(BASE_URL, { headers: { 'access-control-request-method': 'post' } }) - .then(function (response) { + it('should send out CORS headers for preflight requests', function (done) { + chai.request(BASE_URL) + .options('/') + .set('access-control-request-method', 'post') + .end(function (err, response) { expect(response).status(204); expect(response).to.have.header('access-control-allow-origin', '*'); - expect(response).to.have.header('access-control-allow-methods', 'POST, OPTIONS'); - expect(response).to.have.header('access-control-allow-headers', /authorization/i); - expect(response).to.have.header('access-control-expose-headers', /content-disposition/i); + expect(response).to.have.header( + 'access-control-allow-methods', + 'POST, OPTIONS' + ); + expect(response).to.have.header( + 'access-control-allow-headers', + /authorization/i + ); + expect(response).to.have.header( + 'access-control-expose-headers', + /content-disposition/i + ); - return chakram.wait(); + done(); }); }); }); diff --git a/tests/tests/000-root-test.js b/tests/tests/000-root-test.js index 2dbbe911..625a53fa 100644 --- a/tests/tests/000-root-test.js +++ b/tests/tests/000-root-test.js @@ -2,9 +2,6 @@ /* global describe it */ -// const chakram = require('chakram'), -// expect = chakram.expect; - const chai = require('chai'); const chaiHttp = require('chai-http'); const expect = chai.expect; @@ -14,7 +11,7 @@ chai.use(chaiHttp); const BASE_URL = process.env.OSEM_TEST_BASE_URL; describe('openSenseMap API Routes: /', function () { - it('should print available routes', function () { + it('should print available routes', function (done) { chai.request(BASE_URL) .get('/') .end(function (err, res) { @@ -22,15 +19,8 @@ describe('openSenseMap API Routes: /', function () { expect(res).to.have.status(200); expect(res).to.have.header('content-type', 'text/plain; charset=utf-8'); expect(res.body).not.null; - }); - // return chakram.get(BASE_URL) - // .then(function (response) { - // expect(response).status(200); - // expect(response).to.have.header('content-type', 'text/plain; charset=utf-8'); - // expect(response.body).not.empty; - - // return chakram.wait(); - // }); + done(); + }); }); }); diff --git a/tests/tests/001-stats-test.js b/tests/tests/001-stats-test.js index 4aca222f..15f50f8f 100644 --- a/tests/tests/001-stats-test.js +++ b/tests/tests/001-stats-test.js @@ -1,82 +1,100 @@ 'use strict'; -/* global describe it before */ +/* global describe it */ -const chakram = require('chakram'), - expect = chakram.expect; +const chai = require('chai'); +const chaiHttp = require('chai-http'); +const expect = chai.expect; -const BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/stats`, - options = { headers: { 'x-apicache-bypass': true } }; +chai.use(chaiHttp); -describe('openSenseMap API Routes: /stats', function () { - let request, requestHumanTrue, requestHumanFalse, requestHumanWrong1, requestHumanWrong2; - before(function () { - request = chakram.get(BASE_URL, options); - requestHumanTrue = chakram.get(`${BASE_URL}?human=true`, options); - requestHumanFalse = chakram.get(`${BASE_URL}?human=false`, options); - requestHumanWrong1 = chakram.get(`${BASE_URL}?human=tr`, options); - requestHumanWrong2 = chakram.get(`${BASE_URL}?human=fulse`, options); - }); +const BASE_URL = `${process.env.OSEM_TEST_BASE_URL}`; +const options = { headers: { 'x-apicache-bypass': true } }; +const ROUTE = '/stats'; - it('should return a json array with three numbers', function () { - return request - .then(function (response) { +describe('openSenseMap API Routes: /stats', function () { + it('should return a json array with three numbers', function (done) { + chai.request(BASE_URL) + .get(ROUTE) + .set(options.headers) + .end(function (err, response) { expect(response).status(200); - expect(response).to.have.header('content-type', 'application/json; charset=utf-8'); + expect(response).to.have.header( + 'content-type', + 'application/json; charset=utf-8' + ); expect(response.body).not.empty; expect(Array.isArray(response.body)).true; - expect(response.body.every(n => typeof n === 'number')).true; + expect(response.body.every((n) => typeof n === 'number')).true; - return chakram.wait(); + done(); }); }); - it('should return a json array with three strings when called with parameter human=true', function () { - return requestHumanTrue - .then(function (response) { + it('should return a json array with three strings when called with parameter human=true', function (done) { + chai.request(BASE_URL) + .get(ROUTE) + .set(options.headers) + .query({ human: true }) + .end(function (err, response) { expect(response).status(200); - expect(response).to.have.header('content-type', 'application/json; charset=utf-8'); + expect(response).to.have.header( + 'content-type', + 'application/json; charset=utf-8' + ); expect(response.body).not.empty; expect(Array.isArray(response.body)).true; - expect(response.body.every(n => typeof n === 'string')).true; + expect(response.body.every((n) => typeof n === 'string')).true; - return chakram.wait(); + done(); }); }); - it('should return a json array with three numbers when called with parameter human=false', function () { - return requestHumanFalse - .then(function (response) { + it('should return a json array with three numbers when called with parameter human=false', function (done) { + chai.request(BASE_URL) + .get(ROUTE) + .set(options.headers) + .query({ human: false }) + .end(function (err, response) { expect(response).status(200); - expect(response).to.have.header('content-type', 'application/json; charset=utf-8'); + expect(response).to.have.header( + 'content-type', + 'application/json; charset=utf-8' + ); expect(response.body).not.empty; expect(Array.isArray(response.body)).true; - expect(response.body.every(n => typeof n === 'number')).true; + expect(response.body.every((n) => typeof n === 'number')).true; - return chakram.wait(); + done(); }); }); - it('should return an error if parameter human is not true or false', function () { - return chakram.all([requestHumanWrong1, requestHumanWrong2]) - .then(function (responses) { - for (const response of responses) { - expect(response).status(422); - expect(response).to.have.header('content-type', 'application/json; charset=utf-8'); - - expect(response).to.have.json('message', 'Illegal value for parameter human. allowed values: true, false'); - } - - return chakram.wait(); + it('should return an error if parameter human is not true or false', function (done) { + chai.request(BASE_URL) + .get(ROUTE) + .set(options.headers) + .query({ human: 'tr' }) + .end(function (err, response) { + expect(response).status(422); + expect(response).to.have.header( + 'content-type', + 'application/json; charset=utf-8' + ); + expect(response).to.be.json; + expect(response.body).to.have.a.property('message'); + expect(response.body.message).to.equal( + 'Illegal value for parameter human. allowed values: true, false' + ); + done(); }); }); }); diff --git a/tests/tests/002-location_tests.js b/tests/tests/002-location-test.js similarity index 75% rename from tests/tests/002-location_tests.js rename to tests/tests/002-location-test.js index 63c4ae03..ddc2eb07 100644 --- a/tests/tests/002-location_tests.js +++ b/tests/tests/002-location-test.js @@ -2,21 +2,28 @@ /* global describe it before after */ -const chakram = require('chakram'), - expect = chakram.expect, - parseCSV = require('csv-parse/lib/sync'), - moment = require('moment'); +const chai = require('chai'); +const chaiHttp = require('chai-http'); +const expect = chai.expect; +const parseCSV = require('csv-parse/lib/sync'); +const moment = require('moment'); + +chai.use(chaiHttp); + +const BASE_URL = process.env.OSEM_TEST_BASE_URL; +const BOXES_ROUTE = '/boxes'; +const BOXES_DATA_ROUTE = `${BOXES_ROUTE}/data`; const modelsRequirePath = '../../node_modules/@sensebox/opensensemap-api-models'; -const logResponseIfError = function logResponseIfError (r) { - if (r.response.statusCode >= 400) { +const logResponseIfError = function logResponseIfError (response) { + if (response.statusCode >= 400) { /* eslint-disable no-console */ - console.error(r.body); + console.error(response.body); /* eslint-enable no-console */ } - return r; + return response; }; const minimalSensebox = function minimalSensebox (location = [123, 12, 34], exposure = 'mobile') { @@ -29,21 +36,26 @@ describe('openSenseMap API locations tests', function () { before('add test user', function () { const user = { name: 'locationtestuser', email: 'locationtestuser@test.test', password: '12345678' }; - return chakram.post(`${process.env.OSEM_TEST_BASE_URL}/users/register`, user) + return chai.request(BASE_URL) + .post('/users/register') + .send(user) .then(logResponseIfError) .then(function (response) { expect(response.body.token).to.exist; - authHeader = { headers: { 'Authorization': `Bearer ${response.body.token}` } }; - - return chakram.wait(); + authHeader = { + headers: { Authorization: `Bearer ${response.body.token}` } + }; }); }); - after('delete user', function () { - return chakram.delete(`${process.env.OSEM_TEST_BASE_URL}/users/me`, { password: '12345678' }, authHeader) + after('delete user', function (done) { + chai.request(BASE_URL) + .delete('/users/me') + .set(authHeader.headers) + .send({ password: '12345678' }) .then(logResponseIfError) - .then(() => { - return chakram.wait(); + .then(function () { + done(); }); }); @@ -98,33 +110,48 @@ describe('openSenseMap API locations tests', function () { }); describe('POST /boxes', function () { - const BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes`; + // const BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes`; it('should allow to set the location for a new box as array', function () { const loc = [0, 0, 0]; - return chakram.post(BASE_URL, minimalSensebox(loc), authHeader) + return chai.request(BASE_URL) + .post(BOXES_ROUTE) + .set(authHeader.headers) + .send(minimalSensebox(loc)) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); expect(response.body.data.currentLocation).to.exist; - expect(response.body.data.currentLocation.coordinates).to.deep.equal(loc); + expect(response.body.data.currentLocation.coordinates).to.deep.equal( + loc + ); expect(response.body.data.currentLocation.timestamp).to.exist; - expect(moment().diff(response.body.data.currentLocation.timestamp)).to.be.below(300); + expect( + moment().diff(response.body.data.currentLocation.timestamp) + ).to.be.below(300); box = response.body.data; - authHeaderBox = { headers: { 'Authorization': `${response.body.data.access_token}` } }; - csvAndAuthHeader = { json: false, headers: { 'Content-Type': 'text/csv', 'Authorization': response.body.data.access_token } }; - - return chakram.wait(); + authHeaderBox = { + headers: { Authorization: `${response.body.data.access_token}` } + }; + csvAndAuthHeader = { + json: false, + headers: { + 'Content-Type': 'text/csv', + Authorization: response.body.data.access_token + } + }; }); - // .then(done, done); }); it('should allow to set the location for a new box as latLng object', function () { const loc = { lng: 120.123456, lat: 60.654321, height: 12.123 }; - return chakram.post(BASE_URL, minimalSensebox(loc), authHeader) + return chai.request(BASE_URL) + .post(BOXES_ROUTE) + .set(authHeader.headers) + .send(minimalSensebox(loc)) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); @@ -136,20 +163,21 @@ describe('openSenseMap API locations tests', function () { ]); expect(response.body.data.currentLocation.timestamp).to.exist; expect(moment().diff(response.body.data.currentLocation.timestamp)).to.be.below(300); - - return chakram.wait(); }); }); it('should reject a new box with invalid coords', function () { const boxReq = minimalSensebox([52]); - return chakram.post(BASE_URL, boxReq, authHeader) + return chai.request(BASE_URL) + .post(BOXES_ROUTE) + .set(authHeader.headers) + .send(boxReq) .then(function (response) { expect(response).to.have.status(422); - expect(response.body.message).to.equal('Illegal value for parameter location. missing latitude or longitude in location [52]'); - - return chakram.wait(); + expect(response.body.message).to.equal( + 'Illegal value for parameter location. missing latitude or longitude in location [52]' + ); }); }); @@ -157,46 +185,58 @@ describe('openSenseMap API locations tests', function () { const boxReq = minimalSensebox(); delete boxReq.location; - return chakram.post(BASE_URL, boxReq, authHeader) + return chai.request(BASE_URL) + .post(BOXES_ROUTE) + .set(authHeader.headers) + .send(boxReq) .then(function (response) { expect(response).to.have.status(400); - expect(response.body.message).to.equal('missing required parameter location'); - - return chakram.wait(); + expect(response.body.message).to.equal( + 'missing required parameter location' + ); }); }); }); describe('PUT /boxes', function () { - let BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes`; + let BOX_ENDPOINT = ''; before(function () { - BASE_URL = `${BASE_URL}/${box._id}`; // need to append at test runtime, not at parsetime + BOX_ENDPOINT = `/${BOXES_ROUTE}/${box._id}`; // need to append at test runtime, not at parsetime }); it('should allow updating a boxes location via array', function () { const loc = [1, 1, 1]; - return chakram.put(BASE_URL, { location: loc }, authHeader) + return chai + .request(BASE_URL) + .put(BOX_ENDPOINT) + .set(authHeader.headers) + .send({ location: loc }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.data.currentLocation).to.exist; - expect(response.body.data.currentLocation.coordinates).to.deep.equal(loc); + expect(response.body.data.currentLocation.coordinates).to.deep.equal( + loc + ); expect(response.body.data.currentLocation.timestamp).to.exist; - expect(moment().diff(response.body.data.currentLocation.timestamp)).to.be.below(300); + expect( + moment().diff(response.body.data.currentLocation.timestamp) + ).to.be.below(300); submitTimeLoc1 = response.body.data.currentLocation.timestamp; - - return chakram.wait(); }); }); it('should allow updating a boxes location via latlng object', function () { const loc = { lng: 2, lat: 2, height: 2 }; - return chakram.put(BASE_URL, { location: loc }, authHeader) + return chai.request(BASE_URL) + .put(BOX_ENDPOINT) + .set(authHeader.headers) + .send({ location: loc }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -210,28 +250,21 @@ describe('openSenseMap API locations tests', function () { expect(moment().diff(response.body.data.currentLocation.timestamp)).to.be.below(300); box = response.body.data; - - return chakram.wait(); }); }); }); describe('GET /boxes/:boxID', function () { - let BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes`; let result; before('get box', function () { - BASE_URL = `${BASE_URL}/${box._id}`; // need to append at test runtime, not at parsetime - - return chakram.get(BASE_URL) + return chai.request(BASE_URL) + .get(`${BOXES_ROUTE}/${box._id}`) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); result = response.body; - // done(); - - return chakram.wait(); }); }); @@ -252,10 +285,9 @@ describe('openSenseMap API locations tests', function () { }); describe('GET /boxes', function () { - const BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes`; - it('should do the same as tested above in GET /boxes/:boxID', function () { - return chakram.get(BASE_URL) + return chai.request(BASE_URL) + .get(BOXES_ROUTE) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -265,15 +297,15 @@ describe('openSenseMap API locations tests', function () { expect(box.currentLocation).to.exist; expect(box.locations).to.not.exist; } - - return chakram.wait(); }); }); it('should allow filtering boxes by bounding box', () => { const loc = [120.123456, 60.654321, 12.123]; - return chakram.get(`${BASE_URL}?bbox=120,60,121,61`) + return chai.request(BASE_URL) + .get(BOXES_ROUTE) + .query({ bbox: '120,60,121,61' }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -285,11 +317,12 @@ describe('openSenseMap API locations tests', function () { }); it('should reject filtering boxes near a location with wrong parameter values', function () { - return chakram.get(`${BASE_URL}?near=test,60`).then(function (response) { - expect(response).to.have.status(422); - - return chakram.wait(); - }); + return chai.request(BASE_URL) + .get(BOXES_ROUTE) + .query({ near: 'test,60' }) + .then(function (response) { + expect(response).to.have.status(422); + }); }); }); @@ -298,40 +331,44 @@ describe('openSenseMap API locations tests', function () { let POST_MEASUREMENT_URL, GET_MEASUREMENTS_URL, GET_BOX_URL; before(function () { - POST_MEASUREMENT_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}/${box.sensors[0]._id}`; - GET_MEASUREMENTS_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}/data/${box.sensors[0]._id}`; - GET_BOX_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}`; + POST_MEASUREMENT_URL = `/${BOXES_ROUTE}/${box._id}/${box.sensors[0]._id}`; + GET_MEASUREMENTS_URL = `/${BOXES_ROUTE}/${box._id}/data/${box.sensors[0]._id}`; + GET_BOX_URL = `/${BOXES_ROUTE}/${box._id}`; }); it('should allow updating a boxes location via new measurement (array)', function () { const measurement = { value: 3, location: [3, 3, 3] }; - return chakram.post(POST_MEASUREMENT_URL, measurement, authHeaderBox) + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(GET_BOX_URL); + return chai.request(BASE_URL).get(GET_BOX_URL); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.currentLocation.coordinates) .to.deep.equal(measurement.location); - - return chakram.wait(); }); }); it('should allow updating a boxes location via new measurement (latLng)', function () { const measurement = { value: 4, location: { lat: 4, lng: 4, height: 4 } }; - return chakram.post(POST_MEASUREMENT_URL, measurement, authHeaderBox) + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(GET_BOX_URL); + return chai.request(BASE_URL).get(GET_BOX_URL); }) .then(logResponseIfError) .then(function (response) { @@ -342,8 +379,6 @@ describe('openSenseMap API locations tests', function () { measurement.location.lat, measurement.location.height, ]); - - return chakram.wait(); }); }); @@ -354,20 +389,21 @@ describe('openSenseMap API locations tests', function () { createdAt: moment().subtract(1, 'm'), }; - return chakram.post(POST_MEASUREMENT_URL, measurement, authHeaderBox) + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(GET_BOX_URL); + return chai.request(BASE_URL).get(GET_BOX_URL); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.currentLocation.coordinates) .to.deep.equal([4, 4, 4]); - - return chakram.wait(); }); }); @@ -375,20 +411,21 @@ describe('openSenseMap API locations tests', function () { const createdAt = moment().subtract(10, 'm'); const measurement = { value: -1, createdAt }; - return chakram.post(POST_MEASUREMENT_URL, measurement, authHeaderBox) + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(`${GET_BOX_URL}/locations`); + return chai.request(BASE_URL).get(`${GET_BOX_URL}/locations`); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(moment(response.body[0].timestamp).diff(createdAt)) .to.equal(0); - - return chakram.wait(); }); }); @@ -398,17 +435,23 @@ describe('openSenseMap API locations tests', function () { // timestamp exactly at time of location set through PUT /boxes/:boxID const measurement2 = { value: 1, createdAt: submitTimeLoc1 }; - return chakram.post(POST_MEASUREMENT_URL, measurement1, authHeaderBox) + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement1) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.post(POST_MEASUREMENT_URL, measurement2, authHeaderBox); + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement2); }) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(GET_MEASUREMENTS_URL); + return chai.request(BASE_URL).get(GET_MEASUREMENTS_URL); }) .then(logResponseIfError) .then(function (response) { @@ -422,8 +465,6 @@ describe('openSenseMap API locations tests', function () { const m2 = response.body.find(m => m.value === '1'); expect(m2).to.be.not.undefined; expect(m2.location).to.deep.equal([1, 1, 1]); - - return chakram.wait(); }); }); @@ -444,24 +485,33 @@ describe('openSenseMap API locations tests', function () { createdAt: measurement2.createdAt.clone().subtract(2, 'ms') }; - return chakram.post(POST_MEASUREMENT_URL, measurement3, authHeaderBox) + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement3) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.post(POST_MEASUREMENT_URL, measurement2, authHeaderBox); + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement2); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.post(POST_MEASUREMENT_URL, measurement1, authHeaderBox); + return chai.request(BASE_URL) + .post(POST_MEASUREMENT_URL) + .set(authHeaderBox.headers) + .send(measurement1); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(GET_MEASUREMENTS_URL); + return chai.request(BASE_URL).get(GET_MEASUREMENTS_URL); }) .then(logResponseIfError) .then(function (response) { @@ -478,18 +528,15 @@ describe('openSenseMap API locations tests', function () { const m3 = response.body.find(m => m.value === '6'); expect(m3).to.be.not.undefined; expect(m3.location).to.deep.equal(measurement3.location); - - return chakram.wait(); }); }); - }); describe('POST /boxes/:boxID/data', function () { - let BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes`; + let BOX_DATA_ENDPOINT; before(function () { - BASE_URL = `${BASE_URL}/${box._id}/data`; + BOX_DATA_ENDPOINT = `/${BOXES_ROUTE}/${box._id}/data`; }); describe('application/json', function () { @@ -499,20 +546,21 @@ describe('openSenseMap API locations tests', function () { measurements[box.sensors[1]._id] = [7, moment().subtract(2, 'ms'), [7, 7, 7]]; measurements[box.sensors[2]._id] = [8, moment(), { lat: 8, lng: 8, height: 8 }]; - return chakram.post(BASE_URL, measurements, authHeaderBox) + return chai.request(BASE_URL) + .post(BOX_DATA_ENDPOINT) + .set(authHeaderBox.headers) + .send(measurements) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(`${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}`); + return chai.request(BASE_URL).get(`${BOXES_ROUTE}/${box._id}`); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.currentLocation.coordinates) .to.deep.equal([8, 8, 8]); - - return chakram.wait(); }); }); @@ -526,26 +574,28 @@ describe('openSenseMap API locations tests', function () { { sensor_id: sensor, value: 10.5 }, ]; - return chakram.post(BASE_URL, measurements, authHeaderBox) + return chai.request(BASE_URL) + .post(BOX_DATA_ENDPOINT) + .set(authHeaderBox.headers) + .send(measurements) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(`${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}`); + return chai.request(BASE_URL).get(`${BOXES_ROUTE}/${box._id}`); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.currentLocation.coordinates) .to.deep.equal([10, 10, 10]); - - return chakram.wait(); }); }); it('should set & infer locations correctly for measurements', function () { - return chakram.get(`${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}/data/${box.sensors[3]._id}`) + return chai.request(BASE_URL) + .get(`${BOX_DATA_ENDPOINT}/${box.sensors[3]._id}`) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -554,8 +604,6 @@ describe('openSenseMap API locations tests', function () { for (const m of response.body) { expect(m.location).to.deep.equal(Array(3).fill(parseInt(m.value, 10))); } - - return chakram.wait(); }); }); @@ -568,20 +616,21 @@ describe('openSenseMap API locations tests', function () { it('should accept 2D locations', function () { const measurements = `${box.sensors[3]._id},11,${moment().toISOString()},11,11`; - return chakram.post(BASE_URL, measurements, csvAndAuthHeader) + return chai.request(BASE_URL) + .post(BOX_DATA_ENDPOINT) + .set(csvAndAuthHeader.headers) + .send(measurements) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(`${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}`); + return chai.request(BASE_URL).get(`${BOXES_ROUTE}/${box._id}`); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.currentLocation.coordinates) .to.deep.equal([11, 11]); - - return chakram.wait(); }); }); @@ -593,37 +642,40 @@ describe('openSenseMap API locations tests', function () { [sensor, 12.6, moment().subtract(2, 'ms').toISOString(), 12, 12, 12].join(','), // eslint-disable-line newline-per-chained-call ].join('\n'); - return chakram.post(BASE_URL, measurements, csvAndAuthHeader) + return chai.request(BASE_URL) + .post(BOX_DATA_ENDPOINT) + .set(csvAndAuthHeader.headers) + .send(measurements) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(201); - return chakram.get(`${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}`); + return chai.request(BASE_URL).get(`${BOXES_ROUTE}/${box._id}`); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); expect(response.body.currentLocation.coordinates) .to.deep.equal([12, 12, 12]); - - return chakram.wait(); }); }); it('should reject measurements with location & w/out createdAt', function () { const measurements = `${box.sensors[3]._id},13,13,13,13`; // id,value,lng,lat,height - return chakram.post(BASE_URL, measurements, csvAndAuthHeader) + return chai.request(BASE_URL) + .post(BOX_DATA_ENDPOINT) + .set(csvAndAuthHeader.headers) + .send(measurements) .then(function (response) { expect(response).to.have.status(422); - - return chakram.wait(); }); }); it('should set & infer locations correctly for measurements', function () { - return chakram.get(`${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}/data/${box.sensors[3]._id}`) + return chai.request(BASE_URL) + .get(`${BOX_DATA_ENDPOINT}/${box.sensors[3]._id}`) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -633,8 +685,6 @@ describe('openSenseMap API locations tests', function () { const numCoords = m.value === '11' ? 2 : 3; expect(m.location).to.deep.equal(Array(numCoords).fill(parseInt(m.value, 10))); } - - return chakram.wait(); }); }); @@ -643,21 +693,28 @@ describe('openSenseMap API locations tests', function () { }); describe('GET /boxes/data', function () { - let BASE_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes/data`; - let CURRENT_LOC_DATA_URL = `${process.env.OSEM_TEST_BASE_URL}/boxes/data`; + // let BASE_URL; + let CURRENT_LOC_DATA_URL; + let QUERY; before(function () { - BASE_URL = `${BASE_URL}?phenomenon=${box.sensors[0].title}`; + // BASE_URL = `${BOXES_DATA_ROUTE}?phenomenon=${box.sensors[0].title}`; + QUERY = { + boxId: box._id, + phenomenon: box.sensors[0].title + }; // currentLocation === [10,10,10] - CURRENT_LOC_DATA_URL = `${CURRENT_LOC_DATA_URL}?phenomenon=${box.sensors[3].title}&bbox=9.9,9.9,10.1,10.1`; + CURRENT_LOC_DATA_URL = `${BOXES_DATA_ROUTE}?phenomenon=${box.sensors[3].title}&bbox=9.9,9.9,10.1,10.1`; }); it('should send lat lon columns by default', function () { - return chakram.get(`${BASE_URL}&boxId=${box._id}`) + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query(QUERY) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body); + const data = parseCSV(response.text); const lngColumn = data[0].indexOf('lon'); const latColumn = data[0].indexOf('lat'); const heightColumn = data[0].indexOf('height'); @@ -665,33 +722,39 @@ describe('openSenseMap API locations tests', function () { expect(lngColumn).to.be.greaterThan(-1); expect(latColumn).to.be.greaterThan(-1); expect(heightColumn).to.equal(-1); - - return chakram.wait(); }); }); it('should send height column on request', function () { - return chakram.get(`${BASE_URL}&boxId=${box._id}&columns=value,height`) + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query({ + ...QUERY, + columns: 'value,height' + }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body); + const data = parseCSV(response.text); const heightColumn = data[0].indexOf('height'); expect(heightColumn).to.be.greaterThan(-1); - - return chakram.wait(); }); }); it('should send per measurement coordinates for mobile boxes', function () { expect(box.exposure).to.equal('mobile'); - return chakram.get(`${BASE_URL}&boxId=${box._id}&columns=value,lat,lon,height`) + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query({ + ...QUERY, + columns: 'value,lat,lon,height' + }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body, { columns: true }); + const data = parseCSV(response.text, { columns: true }); for (const m of data) { // filter measurements with inferred location @@ -701,19 +764,21 @@ describe('openSenseMap API locations tests', function () { expect(m.height).to.equal(m.value); } } - - return chakram.wait(); }); }); it('should filter measurements by bbox for mobile boxes', function () { expect(box.exposure).to.equal('mobile'); - return chakram.get(`${BASE_URL}&bbox=-1,-1,0,0`) + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query({ + bbox: '-1,-1,0,0' + }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body, { columns: true }); + const data = parseCSV(response.text, { columns: true }); const measuresFiltered = data.filter(m => ( m.lat >= -1 && m.lat <= 0 && @@ -723,12 +788,12 @@ describe('openSenseMap API locations tests', function () { expect(data).to.be.an('array').with.length(3); expect(measuresFiltered).to.be.an('array').with.length(3); - return chakram.get(CURRENT_LOC_DATA_URL); + return chai.request(BASE_URL).get(CURRENT_LOC_DATA_URL); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body, { columns: true }); + const data = parseCSV(response.text, { columns: true }); const measuresFiltered = data.filter(m => ( m.lat >= 9.9 && m.lat <= 10.1 && @@ -737,15 +802,14 @@ describe('openSenseMap API locations tests', function () { expect(data).to.be.an('array').with.length(2); expect(measuresFiltered).to.be.an('array').with.length(2); - - return chakram.wait(); }); }); it('should send per measurement coordinates for stationary boxes', function () { - const updateBoxUrl = `${process.env.OSEM_TEST_BASE_URL}/boxes/${box._id}`; - - return chakram.put(updateBoxUrl, { exposure: 'outdoor' }, authHeader) + return chai.request(BASE_URL) + .put(`${BOXES_ROUTE}/${box._id}`) + .set(authHeader.headers) + .send({ exposure: 'outdoor' }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -753,12 +817,18 @@ describe('openSenseMap API locations tests', function () { box = response.body.data; - return chakram.get(`${BASE_URL}&boxId=${box._id}&columns=value,lat,lon,height`); + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query({ + ...QUERY, + boxId: box._id, + columns: 'value,lat,lon,height' + }); }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body, { columns: true }); + const data = parseCSV(response.text, { columns: true }); for (const m of data) { // filter measurements with inferred location @@ -768,19 +838,23 @@ describe('openSenseMap API locations tests', function () { expect(m.height).to.equal(m.value); } } - - return chakram.wait(); }); }); it('should filter measurements by bbox for stationary boxes', function () { expect(box.exposure).to.not.equal('mobile'); - return chakram.get(`${BASE_URL}&bbox=0,0,-1,-1&columns=value,lat,lon,height`) + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query({ + ...QUERY, + bbox: '0,0,-1,-1', + columns: 'value,lat,lon,height' + }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); - const data = parseCSV(response.body, { columns: true }); + const data = parseCSV(response.text, { columns: true }); const measuresFiltered = data.filter(m => ( m.lat >= -1 && m.lat <= 0 && @@ -790,7 +864,12 @@ describe('openSenseMap API locations tests', function () { expect(data).to.be.an('array').with.length(3); expect(measuresFiltered).to.be.an('array').with.length(3); - return chakram.get(CURRENT_LOC_DATA_URL); + return chai.request(BASE_URL) + .get(BOXES_DATA_ROUTE) + .query({ + phenomenon: box.sensors[3].title, + bbox: '9.9,9.9,10.1,10.1' + }); }) .then(logResponseIfError) .then(function (response) { @@ -804,8 +883,6 @@ describe('openSenseMap API locations tests', function () { expect(data).to.be.an('array').with.length(2); expect(measuresFiltered).to.be.an('array').with.length(2); - - return chakram.wait(); }); }); @@ -906,7 +983,11 @@ describe('openSenseMap API locations tests', function () { }); it('should return all locations of a box as GeoJSON LineString', function () { - return chakram.get(`${BASE_URL}?format=geojson`) + return chai.request(BASE_URL) + .get(BOXES_ROUTE) + .query({ + format: 'geojson' + }) .then(logResponseIfError) .then(function (response) { expect(response).to.have.status(200); @@ -918,8 +999,6 @@ describe('openSenseMap API locations tests', function () { expect(geom).to.have.property('type', 'LineString'); expect(geom.coordinates).to.be.an('array').with.length(14); }); - - return chakram.wait(); }); });