update devDependencies, fix lint issues
[squeep-authentication-module] / test / lib / authenticator.js
index dea4a84427e2d9634b10e401a9084b1bea5370f9..71420810f3e878edc841c7c243976fc19e24b677 100644 (file)
@@ -1,8 +1,10 @@
 /* eslint-env mocha */
+/* eslint-disable sonarjs/no-duplicate-string */
+/* eslint-disable jsdoc/require-jsdoc */
 'use strict';
 
 const assert = require('assert');
-const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
+const sinon = require('sinon');
 const Authenticator = require('../../lib/authenticator');
 const stubLogger = require('../stub-logger');
 const stubDb = require('../stub-db');
@@ -60,20 +62,20 @@ describe('Authenticator', function () {
     it('covers success', async function () {
       const otpKey = '1234567890123456789012';
       await authenticator.createIdentifier(dbCtx, identifier, credential, otpKey);
-      assert(authenticator.db.authenticationInsertIdentifier.called);
+      assert(authenticator.db.authenticationUpsert.called);
     });
     it('covers failure', async function () {
       const expected = new Error('blah');
-      await authenticator.db.authenticationInsertIdentifier.rejects(expected);
+      await authenticator.db.authenticationUpsert.rejects(expected);
       // assert.rejects was not happy to handle this for some reason
       try {
         await authenticator.createIdentifier(dbCtx, identifier, credential);
         assert.fail('no expecte exception');
       } catch (e) {
         assert.deepStrictEqual(e, expected);
-        assert(authenticator.db.authenticationInsertIdentifier.called);
+        assert(authenticator.db.authenticationUpsert.called);
         assert(authenticator.logger.error.called);
-        }
+      }
     });
   }); // createIdentifier
 
@@ -383,6 +385,22 @@ describe('Authenticator', function () {
     });
   }); // checkOTP
 
+  describe('updateOTPKey', function () {
+    let dbCtx, otpKey;
+    beforeEach(function () {
+      dbCtx = {};
+      otpKey = 'CDBGB3U3B2ILECQORMINGGSZN7LXY565';
+    });
+    it('covers success', async function () {
+      await authenticator.updateOTPKey(dbCtx, identifier, otpKey);
+      assert(authenticator.db.authenticationUpdateOTPKey.called);
+    });
+    it('covers failure', async function () {
+      authenticator.db.authenticationUpdateOTPKey.rejects();
+      assert.rejects(authenticator.updateOTPKey(dbCtx, identifier, otpKey));
+    });
+  }); // updateOTPKey
+
   describe('sessionCheck', function () {
     let req, res, loginPath, required, profilesAllowed;
     beforeEach(function () {