From 05aa73890ae575cf3a98d18113c1b850b29a289c Mon Sep 17 00:00:00 2001 From: xbgmsharp Date: Mon, 2 Dec 2024 21:36:25 +0100 Subject: [PATCH] Update API tests, enforce all metrics are from the past --- tests/index.js | 8 +++++++- tests/index2.js | 6 +++--- tests/index3.js | 2 +- tests/index6.js | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/index.js b/tests/index.js index 407d51a..880f7cf 100644 --- a/tests/index.js +++ b/tests/index.js @@ -600,7 +600,7 @@ request.set('User-Agent', 'PostgSail unit tests'); for (i = 0; i < test.vessel_metrics['metrics'].length; i++) { data[i] = test.vessel_metrics['metrics'][i]; // Override time, -2h to allow to new data later without delay. - data[i]['time'] = moment.utc().subtract(2, 'hours').add(i, 'minutes').format(); + data[i]['time'] = moment.utc().subtract(1, 'day').add(i, 'minutes').format(); // Override client_id data[i]['client_id'] = test.vessel_metadata.client_id; } @@ -611,6 +611,11 @@ request.set('User-Agent', 'PostgSail unit tests'); // Force last valid entry to be back in time from previous, it should be ignore silently data.at(-1).time = moment.utc(data.at(-3).time).subtract(1, 'minutes').format(); //console.log(data[0]); + // Force the -2 entry to be in the future add 1 year, it should be ignore silently + data.splice(i-2, 1, data.at(-2)) + data.at(-3).time = moment.utc(data.at(-3).time).add(1, 'year').format(); + //console.log(data.at(-2)); + //console.log(data.at(-1)); it('/metrics?select=time', function(done) { request = supertest.agent(test.cname); @@ -629,6 +634,7 @@ request.set('User-Agent', 'PostgSail unit tests'); res.header['content-type'].should.match(new RegExp('json','g')); res.header['server'].should.match(new RegExp('postgrest','g')); should.exist(res.body); + //console.log(res.body); res.body.length.should.match(test.vessel_metrics['metrics'].length-3); done(err); }); diff --git a/tests/index2.js b/tests/index2.js index e5ddb35..6efd2b1 100644 --- a/tests/index2.js +++ b/tests/index2.js @@ -6,7 +6,7 @@ * * npm install supertest should mocha mochawesome moment * alias mocha="./node_modules/mocha/bin/_mocha" -* mocha index.js --reporter mochawesome --reporter-options reportDir=/mnt/postgsail/,reportFilename=report_api.html +* mocha index2.js --reporter mochawesome --reporter-options reportDir=/mnt/postgsail/,reportFilename=report_api.html * */ @@ -432,11 +432,11 @@ request.set('User-Agent', 'PostgSail unit tests'); for (i = 0; i < test.vessel_metrics['metrics'].length; i++) { data[i] = test.vessel_metrics['metrics'][i]; // Override time, +1h because previous sample include 47 entry. - data[i]['time'] = moment().add(1, 'hour').add(i, 'minutes').format(); + data[i]['time'] = moment.utc().subtract(2, 'hours').add(i, 'minutes').format(); // Override client_id data[i]['client_id'] = test.vessel_metadata.client_id; } - console.log(data[0]); + //console.log(data[0]); it('/metrics?select=time', function(done) { request = supertest.agent(test.cname); diff --git a/tests/index3.js b/tests/index3.js index c07009c..71b5b4e 100644 --- a/tests/index3.js +++ b/tests/index3.js @@ -6,7 +6,7 @@ * * npm install supertest should mocha mochawesome moment * alias mocha="./node_modules/mocha/bin/_mocha" -* mocha index.js --reporter mochawesome --reporter-options reportDir=/mnt/postgsail/,reportFilename=report_api.html +* mocha index3.js --reporter mochawesome --reporter-options reportDir=/mnt/postgsail/,reportFilename=report_api.html * */ diff --git a/tests/index6.js b/tests/index6.js index 7969a01..0025459 100644 --- a/tests/index6.js +++ b/tests/index6.js @@ -1,13 +1,13 @@ "use strict"; /* - * Unit test #5 + * Unit test #6 * Public/Anonymous access * * process.env.PGSAIL_API_URI = from inside the docker * * npm install supertest should mocha mochawesome moment * alias mocha="./node_modules/mocha/bin/_mocha" - * mocha index5.js --reporter mochawesome --reporter-options reportDir=/mnt/postgsail/,reportFilename=report_api.html + * mocha index6.js --reporter mochawesome --reporter-options reportDir=/mnt/postgsail/,reportFilename=report_api.html * */