From 078b0e9ca29aec5b0615f34ca62f1eb47b6701ad Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 11 Jul 2023 03:51:42 +0300 Subject: [PATCH] Add basic `bus` tests --- test/bus.js | 34 +++++++++++++++++++++++++++++ test/bus/.eslintrc.json | 8 +++++++ test/bus/math/.service.js | 7 ++++++ test/bus/math/eval.js | 11 ++++++++++ test/bus/worldTime/.service.js | 7 ++++++ test/bus/worldTime/currentTime.js | 29 ++++++++++++++++++++++++ test/bus/worldTime/listLocations.js | 7 ++++++ test/bus/worldTime/listTimezones.js | 12 ++++++++++ test/cache.js | 1 + 9 files changed, 116 insertions(+) create mode 100644 test/bus.js create mode 100644 test/bus/.eslintrc.json create mode 100644 test/bus/math/.service.js create mode 100644 test/bus/math/eval.js create mode 100644 test/bus/worldTime/.service.js create mode 100644 test/bus/worldTime/currentTime.js create mode 100644 test/bus/worldTime/listLocations.js create mode 100644 test/bus/worldTime/listTimezones.js diff --git a/test/bus.js b/test/bus.js new file mode 100644 index 00000000..08366d2a --- /dev/null +++ b/test/bus.js @@ -0,0 +1,34 @@ +'use strict'; + +const path = require('node:path'); +const metatests = require('metatests'); +const { Place } = require('../lib/place.js'); + +const root = process.cwd(); + +const application = { + path: path.join(root, 'test'), + console, + starts: [], + watcher: { watch() {} }, + absolute(relative) { + return path.join(this.path, relative); + }, +}; + +metatests.testAsync('lib/bus', async (test) => { + const bus = new Place('bus', application); + test.strictSame(bus.place, 'bus'); + test.strictSame(bus.path, path.join(root, 'test/bus')); + test.strictSame(typeof bus.application, 'object'); + test.strictSame(bus.tree, {}); + await bus.load(); + test.strictSame(Object.keys(bus.tree), ['math', 'worldTime']); + test.strictSame(bus.tree.math.parent, bus.tree); + test.strictSame(typeof bus.tree.math, 'object'); + test.strictSame(typeof bus.tree.math.eval, 'function'); + test.strictSame(bus.tree.math.eval.constructor.name, 'AsyncFunction'); + test.strictSame(typeof bus.tree.math['.service'], 'function'); + test.strictSame(bus.tree.math['.service'].url, 'https://api.mathjs.org'); + test.end(); +}); diff --git a/test/bus/.eslintrc.json b/test/bus/.eslintrc.json new file mode 100644 index 00000000..24bae508 --- /dev/null +++ b/test/bus/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "camelcase": ["error", { "properties": "never" }] + } +} diff --git a/test/bus/math/.service.js b/test/bus/math/.service.js new file mode 100644 index 00000000..a4b3ebd0 --- /dev/null +++ b/test/bus/math/.service.js @@ -0,0 +1,7 @@ +({ + url: 'https://api.mathjs.org', + limits: [ + { calls: 10, per: '1m' }, + { calls: 10000, per: '1d' }, + ], +}); diff --git a/test/bus/math/eval.js b/test/bus/math/eval.js new file mode 100644 index 00000000..40377a2e --- /dev/null +++ b/test/bus/math/eval.js @@ -0,0 +1,11 @@ +({ + parameters: { + expr: 'string', + precision: 'number', + }, + + method: { + post: 'v4', + body: ['expr', 'precision'], + }, +}); diff --git a/test/bus/worldTime/.service.js b/test/bus/worldTime/.service.js new file mode 100644 index 00000000..bbf7ef71 --- /dev/null +++ b/test/bus/worldTime/.service.js @@ -0,0 +1,7 @@ +({ + url: 'http://worldtimeapi.org/api', + limits: [ + { calls: 10, per: '1m' }, + { calls: 10000, per: '1d' }, + ], +}); diff --git a/test/bus/worldTime/currentTime.js b/test/bus/worldTime/currentTime.js new file mode 100644 index 00000000..abe5a945 --- /dev/null +++ b/test/bus/worldTime/currentTime.js @@ -0,0 +1,29 @@ +({ + parameters: { + area: 'string', + location: 'string', + }, + + method: { + get: 'timezone', + path: ['area', 'location'], + }, + + returns: { + abbreviation: 'string', + client_ip: 'string', + datetime: 'string', + day_of_week: 'number', + day_of_year: 'number', + dst: 'boolean', + dst_from: 'string', + dst_offset: 'number', + dst_until: 'string', + raw_offset: 'number', + timezone: 'string', + unixtime: 'number', + utc_datetime: 'string', + utc_offset: 'string', + week_number: 'number', + }, +}); diff --git a/test/bus/worldTime/listLocations.js b/test/bus/worldTime/listLocations.js new file mode 100644 index 00000000..9bcc5d59 --- /dev/null +++ b/test/bus/worldTime/listLocations.js @@ -0,0 +1,7 @@ +({ + method: { + get: 'timezone', + }, + + returns: { array: 'string' }, +}); diff --git a/test/bus/worldTime/listTimezones.js b/test/bus/worldTime/listTimezones.js new file mode 100644 index 00000000..32d59f20 --- /dev/null +++ b/test/bus/worldTime/listTimezones.js @@ -0,0 +1,12 @@ +({ + parameters: { + area: 'string', + }, + + method: { + get: 'timezone', + path: ['area'], + }, + + returns: { array: 'string' }, +}); diff --git a/test/cache.js b/test/cache.js index f9905b1a..dfd28a43 100644 --- a/test/cache.js +++ b/test/cache.js @@ -29,6 +29,7 @@ metatests.testAsync('lib/cache', async (test) => { } async change(filePath) { + test.strictSame(this.constructor.name, 'EmptyCache'); test.strictSame(typeof filePath, 'string'); } }