708 Commits
Author SHA1 Message Date
Asbjørn AarrestadandSulka Haro 6abd6bed27 Added sanity check for the bridge interval value (#4717)
* Added sanity check for the bridge interval value, setting minimum allowed value to 30 seconds and maximum to 5 minutes. This is to avoid input of very low values which might overload the dexcom servers.

* Added missin ';'

* Fixed typoe in comment

* Added test for default interval (not set in config)

* Set lower limit to 1 second
2019-12-06 12:27:00 +02:00
Sulka HaroandGitHub 57a3f2db23 Merge pull request #5186 from PetrOndrusek/api3-readonly-documents
API3 read-only documents
2019-12-06 12:19:14 +02:00
Sulka HaroandGitHub c153a965bc Merge pull request #5137 from inventor96/update-virtual-assistants-v2
Update virtual assistants v2
2019-12-06 12:18:26 +02:00
Sulka HaroandGitHub 8b19c53222 Merge pull request #5169 from PetrOndrusek/api-prev-versions
API versions list
2019-12-06 12:17:40 +02:00
Sulka HaroandGitHub 5bc6799e48 GitHub actions build (#5168)
* Run tests using GitHub Actions

* Node 10

* Test CI fails

* Use npm to run tests

* Fix package json to run tests

* Enable v3 TEST api for both development env and CI

* Run CI on both Node 10 and 12

* Allow downgrading Mongo
2019-11-10 21:57:49 +00:00
Willem FibbeandSulka Haro c6e763521c Fix falsely suspended timeago alarms (#5170)
* Fix continuous suspension of the timeago alerts

The default hearbeat-setting is 60 seconds, so the delta between two
timeago-checks will always be >15 seconds and the timeago-alarms will
always be suspended (that's what Papertrail also shows).

To fix this, make the delta-check heartbeat-setting-dependant and also simplify
the code by using just 1 variable.

* Add test that verifies the hibernation detection behaviour

The real-world test would be to actually wait for a couple of minutes (with 2 *
heartbeat of default settings) in the unit test, but this is not feasible, so
just modify the heartbeat-setting to a lower value.

I tested it by only running tests inside `tests/timeago.test.js` and by actually
deploying this code and testing the alarms with Pushover and reading the logs in
Papertrail.

Before this change, I saw a 'Hibernation detected' log every minute. After this
change, I didn't see it anymore, probably because the app wasn't actually
hibernated (yet).

* Take sulkaharo's feedback into account and differentiate
between client and server (by introducing it in sandbox.js).

On the client the behaviour is different from the server:

> On client, the issue is browsers stop the execution of JS if the window is not
> visible and the alarm is falsely triggered immediately when the execution is
> resumed, so we need to suspend the alarm for ~10 seconds after the execution has
> resumed to give the client time to update the data to prevent false alarms.

While on the server, the default heartbeat from 60s needs to be taken
into account to prevent the timeago alarm from falsely triggering.
So detect hibernation there if the last check was more than 2 heartbeats ago.

* Fix the tests by adding settings to the context,
which is now required by timeago.

Also, change the timeago test a bit so that it both succeeds
when testing in isolation as when testing it along with the other tests.
2019-11-10 21:07:01 +00:00
PetrOndrusek 51a7c12ba3 API3: testing isReadOnly feature 2019-11-07 23:46:34 +01:00
inventor96 43a32b34fb Misc fixes for tests (even though they didn't fail 🤔) 2019-11-05 14:52:00 -07:00
PetrOndrusek 5c5821a90d adding list of supported APIs versions (GET /api/versions) 2019-10-30 22:55:23 +01:00
Sulka HaroandGitHub 243ff2e28e Load data in one pass (#5142)
* Fix layouting and load data in one go. Bonus points if you can fix the rendering for this

* fix focus target lines and high and low lines

* Remove debug logging. Change profile functions to clear the cache on new data, instead of calculating heavy hashes

* Remove unused code

* Fix tests

* Have Travis run tests on Node 10 and 12, not 13
2019-10-23 15:18:54 +03:00
inventor96 67e6cddc4b Merge branch 'update-virtual-assistants' into update-virtual-assistants-v2 2019-10-21 14:24:58 -07:00
Sulka HaroandGitHub e10d4838a8 Fix tests failing in dev (#5127)
* * Fix reporting test to match the new output
* Fix number formatter to return the expected 0 when data is NaN
* Remove excessive logging during test runs from cob plugin

* Run all tests in one go

* Fixes D3 invocations for tests. Note this also removes transition timers (most of which seemed to be timed so fast they actually had no effect as the timer was faster than what it takes to draw a frame in Nightscout)

* Run tests independently

* Try not running tap-set-exit

* Remove tap-set-exit
2019-10-22 00:10:06 +03:00
PieterGitandGitHub 36de82bffd Revert "fix/feat: Update Alexa integration and add Google Home support (#4980)" (#5131)
This reverts commit 30b88f6765.
2019-10-21 16:23:32 +02:00
CalebandPieterGit 30b88f6765 fix/feat: Update Alexa integration and add Google Home support (#4980)
* Copied work done by mdomox

* Updates and fixes to CONTRIBUTING.md

* Spacing unification

* One more fix for CONTRIBUTING.md

* Minor code formatting improvements

* One more time...

* Renamed Alexa stuff to virtAsst for generic-ness

* Corrected missed translate() text

* Updated googlehome plugin to mimic the alexa plugin

* Changed order of operations

* Fixed parameter referencing in googlehome

* Yet another CONTRIBUTING fix

* Removed extra google stuff

* Migrated standalone intents to MetricNow intent

* Simplified route handling

* Added logging

* Added forgotten path selector

* Separated instructions for adding virtual assistant support in a plugin

* A few typo fixes

* Improved logging

* Updated Google Home plugin instructions

* Attempt to trigger download of template file

* Small wording tweaks

* Updated Alexa plugin documentation

* Updated test files

* Re-added handler count tests so devs are prompted to write tests for new handlers

* Updated Alexa documentation

* Small typo fix

* Clarification

* Further clarifications and typos

* Added language info to Google Home plugin doc

* URL correction

* URL fix v2

* Wording clarification

* Ugh...

* Minor instruction fix

* Sub steps fix

* Fixed Alexa references in Google Home

* Added a couple steps for improved user experience

* One more forgotten step

* Updated pump reservoir handler to handle undefined values

* Updated titles and unknown-value responses

* Modified forecast responses to use translate()

* Updated tests

* Improved training phrases

* Wording improvements

* Google Home setup instruction corrections

* Corrected how metric selection is found
2019-10-21 14:09:49 +02:00
Petr OndrusekandSulka Haro 2dd576a629 API V3 (#4250)
* extended .gitignore for Visual Studio 2017

* creating a lib for api3 and exposing it's swagger file

* adding pilot test (for /swagger.yaml)

* implementing public GET /version

* setting api version to 3.0.0-alpha

* creating authorization skeleton + fetching some API env variables

* reusing authorization library

* implementing security

* forcing HTTPS and removing x-powered-by from response

* moving messages to constants, creating https instance fixture

* testing HTTPS requiring

* testing Date header

* testing permission check

* testing allowed operation

* refactoring + storage stub

* create architecture for generic operations

* beginning of READ operation

* tidying the code up

* basic READ part

* going further with READ operation

* DELETE operation

* handling fields parameter

* refactoring to classes

* going further with SEARCH operation

* refactoring file structure

* filtering for SEARCH operation

* preparations for fallback deduplication

* CREATE operation

* UPDATE operation

* PATCH operation

* HISTORY operation

* creating more precise variant of HISTORY operation

* autopruning

* long for timestamps in swagger

* bug fix (when search fields=srvCreated)

* creating skeleton for generic collection API test

* specific HISTORY skeleton

* distinguish between collection logical and storage name

* renaming operation to LAST MODIFIED and getting it to work

* fallback for LAST MODIFIED operation

* tidying a bit

* LAST MODIFIED documentation

* bugfix + emitting data-received

* adding some validations

* bugfix - remove 'token' parameter from filtering

* testing and debugging generic workflow

* test fix for empty db

* fixing security test fixture

* trying to fix Travis CI testing DB problem

* multiple auth callback bugfix + adding user field on authed create/update

* messages for Travis CI debugging

* messages for Travis CI debugging

* messages for Travis CI debugging

* test fix (to be prepared for future dates in db)

* test fix

* adding fallback created_at filling on each create/update

* STATUS operation with API permissions

* querying srvDate from storage + include storage version info

* bugfix of missing apiConst require

* getting mongo version with read-only user rights

* getting mongo current date with read-only user rights

* trying to diagnose travis CI timeout

* refactoring storage version caching (due to some environments problems)

* making VERSION work on empty database

* more fixes

* skipping API HTTPS test for node 8

* making code more readable using ES6 (Promises, async + await)

* extending treatments collection docs by inspecting the careportal code

* tidying existing API3 tests up to allow further grow

* tidying the authorization code up to increase readability and performance a bit

* more refactoring to ES6 and making APIv3 files structure more extendable

* normalizing incoming dates to UTC and storing utcOffset

* fixing srvDate to be of node.js server, not the mongo DB

* preparing test fixtures for permissions testing + skeleton for CREATE operation test

* intensive CREATE operation testing + minor bug fixes

* correcting the deduplication test

* more deduplication testing of CREATE operation

* adding test skeletons for other generic operations

* added variability in filtering by date, created_at, srvModified, srvCreated fields

* fixing test accordingly to previous commit

* adding new collection settings for centralized apps' settings storage

* trying to solve travis CI testing problem - adding default collections names

* another attempt to travis CI test fix

* adding some tests for READ operation

* adding custom error handler (overriding bodyparser's errors)

* securing settings collection more and updating swagger accordingly

* making HISTORY timestamp parameter more flexible + updating swagger documentation

* more testing and bug fixing

* sending only HTTP status with empty body, when there is no message + minor bug fixing

* more refactoring and testing (especially of UPDATE operation)

* PATCH testing + adding userModified field for troubleshooting purposes

* basic SEARCH operation testing

* more SEARCH operation testing

* adding alternative 'now' query parameter to 'Date' header to make GET easier

* adding 'now' to reserved query parameters for SEARCH operation

* more testing

* renaming field user to subject (and modifiedBy)

* bugfix - fixing RFC 2822 constant for moment parsing

* storageSocket: creating skeleton for new Socket.IO namespace

* storageSocket: authentication by accessToken

* storageSocket: authorizing to subscribe rooms

* storageSocket: emitting create, update and delete events

* APIv3: adding support for swagger UI at /api/v3/swagger-ui-dist

* solving some problems detected by eslint

* solving some problems detected by eslint

* APIv3: testing and debugging Socket.IO

* APIv3: testing and debugging Socket.IO

* APIv3: Socket.IO documentation

* APIv3: making the sample real

* APIv3: starting to create a simple tutorial MD file

* APIv3: small corrections

* APIv3: minor corrections after dev merge

* APIv3: adding CREATE and READ operations to the tutorial.md

* APIv3: adding SEARCH, LAST MODIFIED, UPDATE operations to the tutorial.md

* APIv3: finishing the tutorial.md

* APIv3: minor bugfix (bad location after upsert)

* APIv3: refactoring SEARCH complexity

* APIv3: refactoring mongoCollection complexity

* APIv3: refactoring complexity

* APIv3: tidying up a bit

* APIv3: refactoring security (start)

* APIv3: refactoring lastModified

* APIv3: refactoring create (start)

* APIv3: refactoring create (finish)

* APIv3: refactoring delete

* APIv3: refactoring history

* APIv3: refactoring update

* APIv3: refactoring patch

* APIv3: refactoring read

* APIv3: refactoring search + removing deprecated authorizationBuilder

* APIv3: adding best practise for identifier constructing

* APIv3: refactoring and enhancing the validation (immutable fields)

* APIv3: adding security.md documentation file

* APIv3: refactoring - splitting index.js into multiple files

* APIv3: calculating identifier on server side + deduplicating

* APIv3: refactoring cosmetics

* APIv3: updating the documentation

* APIv3: making basic and security tests more readable using async/await

* APIv3: making the rest of tests more readable using async/await

* APIv3: adapting test of previous API

* APIv3: adapting test of previous API
2019-10-09 22:53:55 +03:00
inventor96 d3346fe3dd Updated tests 2019-09-16 15:56:26 -06:00
inventor96 0a48c1d81a Re-added handler count tests so devs are prompted to write tests for new handlers 2019-09-10 00:14:21 -06:00
inventor96 3563158aae Updated test files 2019-09-10 00:06:24 -06:00
inventor96 efa35c4616 Renamed Alexa stuff to virtAsst for generic-ness 2019-09-07 17:51:31 -06:00
Sulka HaroandGitHub 35c7dc42ce * Allow users to set DE_NORMALIZE_DATES=false to have the REST API denormalize UTC dates to zoned ISO dates in the API (#4826) 2019-07-29 17:21:05 +03:00
bassettbandSulka Haro c13d847bc4 New utils.toFixed() for cleaner labels (#4822)
* Updated utils.toFixed

* tabs to spaces

* Rename the new function toFixedMin

* fix tests

* Simpler, more robust check

See https://stackoverflow.com/questions/6003884/how-do-i-check-for-null-values-in-javascript
2019-07-29 17:20:27 +03:00
Sulka HaroandGitHub b04476e1f9 Normalize Treatment, Entry and Device Status object dates to be all in UTC Strings (#4658)
* Normalize Treatment object dates to be all in UTC Strings, as expected by the codebase

* Also normalize the device status data

* Sort the results so results with mixed dates are returned in correct order

* Use MomentJS to correctly parse the offsets & output the offset to objects at all times

* Removing a debug console log message causing excessive logging

* Use UTC date values for queries even if client asks for zoned dates

* Remove extra sorting based on date. Code clarifications

* * Add missing parseZone() call to treatments
* Check isValid() date on entries

* Use isValid() to check date validity for device status data
2019-07-17 09:03:39 +03:00
Sulka Haro dfe9d1baef Fix tests 2019-07-14 20:49:03 +03:00
Jason Calabrese 99800c85a5 fix loop test to expect evBG in the pill value 2019-05-10 09:55:54 -07:00
Jeremy CunninghamandPieterGit 6223212e9f Enable id query with no date (#4481)
* Enable id query with no date

* Add unit test for query.js
2019-04-06 17:02:56 +02:00
PieterGit a6b98c3939 fix ident and add extra test to env.test.js 2019-02-03 00:56:20 +01:00
PieterGit 3104083670 fix readENVTruthy and make INSECURE_USE_HTTP, SECURE_HSTS_HEADER, SECURE_HSTS_HEADER_* and SECURE_CSP work as expected.
readENVTruthy never returned defaultValue. if not set to on|off|true|false the default value is returned
2019-02-02 22:29:02 +01:00
PieterGit e88a417d7b Merge branch 'api-insert-delete-test' of https://github.com/jpcunningh/cgm-remote-monitor into 201812_needs_testing 2019-01-01 11:19:03 +01:00
PieterGit e195fcbbb3 Merge branch 'entries-and-treatments-clean-db' of https://github.com/jpcunningh/cgm-remote-monitor into 201812_needs_testing 2018-12-31 12:38:13 +01:00
Jeremy Cunningham 8921e3ae44 Add insert, query, delete test for devicestatus api 2018-12-15 19:19:14 -06:00
Jeremy Cunningham 44d9c549c7 Add insert, query, delete test for entries api 2018-12-15 18:55:33 -06:00
Jeremy Cunningham 19e7bc3673 Add insert, query, delete test for treatments api 2018-12-15 16:02:51 -06:00
Jeremy Cunningham d3368e5311 Add unit test for cleanentriesdb.js 2018-12-10 17:51:51 -06:00
Jeremy Cunningham 83bd1a7d31 Add unit test for cleantreatmentsdb.js 2018-12-10 17:45:00 -06:00
Jeremy Cunningham d9527d399b Add unit test for removing old devicestatus records 2018-12-09 22:49:55 -06:00
Jeremy Cunningham d31099d73e Add unit test for weektoweek report 2018-12-05 21:50:21 -06:00
PieterGit 5edf2322af fix settings.test.js 2018-11-28 23:30:04 +01:00
PieterGit 9ab0f3af4c add default security settings and test 2018-11-21 23:21:51 +01:00
PieterGit 0e2ae00320 npm update and remove mqtt 2018-11-20 01:15:51 +01:00
PieterGit 2f0e834565 upgrade node to 8.12.0, and upgrade to supertest@3.3.0 and webpack@4.20.2 and reimplement #3819 (webpack) 2018-09-29 14:49:56 +02:00
Sulka HaroandGitHub cb33193e08 Server-side localization fixes, better speech api use (#3724)
* Adds API to plugin manager that calls plugins to visualize alarms

* Refactoring how the translation object is managed after discovering every server-side plugin had it's own instance of the translations and the language code wasn't propagated to any code that generated alarms

* Add more missing translations

* Some more localization fixes
Update Finnish to 100% localized
Change Mongo connection to not stop retrying connecting

* Better scaling for mmol
Fix bug in detecting new BG values

* Delta calculation was the wrong way round :D

* add missing dutch translations

* Have tests bail early & tell Mocha to exit at the end of the run

* Try if Travis likes running tests one by one better

* Enable blocking IO for Travis
2018-07-27 16:04:07 +03:00
PieterGitandSulka Haro 71103bb4b7 resolve npm audit security fixes (#3721)
* upgrade mocha from 3.5.3 to 5.0.5

This resolves these security issues

  Low             Regular Expression Denial of Service
  Package         debug
  Dependency of   mocha [dev]
  Path            mocha > debug
  More info       https://nodesecurity.io/advisories/534

  Critical        Command Injection
  Package         growl
  Dependency of   mocha [dev]
  Path            mocha > growl
  More info       https://nodesecurity.io/advisories/146

* upgrade mocha and start modularizing lodash to make sure tests pass

* more lodash modularization

* upgrade mqtt to 2.18.3

* allow npm 6.2

* upgrade share2nightscout-bridge

* incorporate express-extension-to-accept into Nightscout

the packages seems not maintained (github page is 404) and has a security issue with mime package.  so upgraded and included into Nightscout code.

if somebody knows a more efficient way of programming this with express4 please PR

* update jsdom for security fixes

* prevent wrapping of hour labels by removing the space

* Revert "update jsdom for security fixes"

This reverts commit 04f1f39d636d8d79c6b01b5f298f9a6cea3dc645.

* Revert "more lodash modularization"

This reverts commit c4fa5304db9f16b94f15c2b44793a5a11d595885.

* remove forever dependency

* Revert "Revert "more lodash modularization""

This reverts commit b13c274ebff0b5c3a48ffc0e610ca85a9f8d25bc.

* fix report.test.js with newer packages

sometimes a fix is very easy. This is to prevent:

```
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: T00:00:00, _f: undefined, _strict: undefined, _locale: [object Object]
Error
    at Function.createFromInputFallback (XXX\cgm-remote-monitor\tmp\js\bundle.js:117408:98)
    at configFromString (XXX\cgm-remote-monitor\tmp\js\bundle.js:119456:15)
```

We must use ISO8601 formatted strings and not use slashes in dates, see https://github.com/moment/moment/issues/1407#issuecomment-155630060

* upgrade webpack to 4.16.2

* Update package.json
2018-07-24 20:25:44 +03:00
PieterGit 1e429bb2ed fix mqtt.test.js because of changed mongodb url 2018-07-08 23:10:32 +02:00
PieterGit cab24e131a add mongodb port number to mqtt.test.js 2018-07-08 22:31:23 +02:00
PieterGit 2122382c3b Merge branch '201807_supertest' of https://github.com/PieterGit/cgm-remote-monitor into 201807_upgrades 2018-07-08 22:29:55 +02:00
Sulka HaroandGitHub b579a58333 Add mmol support to OpenAPS temp targets (#3670)
* Fixes issue https://github.com/nightscout/cgm-remote-monitor/issues/3660

* Fix OpenAPS temporary targets using mg/dl on mmol users

* Fixes a bug with saving

* Fix changed entry data order in API

* Clean formatting

* Fix mmol conversion on treatment save
2018-07-08 12:30:59 +03:00
PieterGit 40affa1e91 increase timeout for hasauth.test.js
because it times out with 40000ms on Travis with Node 10. See https://travis-ci.org/PieterGit/cgm-remote-monitor/jobs/401307860

not ok 192 pluginbase does stuff
  AssertionError: expected -1 to be above -1
      at Assertion.fail (node_modules/should/cjs/should.js:275:17)
      at Assertion.value (node_modules/should/cjs/should.js:356:19)
      at containsLine (tests/hashauth.test.js:163:41)
      at Window.mockConfirm [as alert] (tests/hashauth.test.js:165:7)
      at Object.u.addBasals (tmp/js/bundle.js:9:2577816)
      at Object.o.scroll (tmp/js/bundle.js:9:2485436)
      at V (tmp/js/bundle.js:9:3092518)
      at Timeout.e [as _onTimeout] (tmp/js/bundle.js:9:3106675)
# tests 192
# pass 191
# fail 1
2018-07-08 00:05:25 +02:00
PieterGit 08f8d8a1d4 add more clear message to mongo-storage-test.js as well 2018-07-07 17:14:52 +02:00
PieterGit 3d27c3bf0b temporary disable distrubition test, because it breaks travis 2018-06-24 14:41:24 +02:00
PieterGitandSulka Haro bd1db6e2b5 Fix tooltips in drawer (#3400)
* fix tooltips in drawer, this was a regression from the bower to webpack upgrade

* fix css path
2018-05-18 09:50:20 +03:00