update dependencies and devDependencies, address lint issues
[squeep-indie-auther] / test / src / db / postgres.js
index 3920d340f53e2471b4fe5df55a32d25546996153..caa665266999f9d8f51f7201ee84882dcb8e52a3 100644 (file)
@@ -1,12 +1,10 @@
-/* eslint-disable sonarjs/no-identical-functions */
-/* eslint-env mocha */
 /* eslint-disable sonarjs/no-duplicate-string */
 'use strict';
 
 /* This provides implementation coverage, stubbing pg-promise. */
 
 const assert = require('assert');
-const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
+const sinon = require('sinon');
 const StubLogger = require('../../stub-logger');
 const StubDatabase = require('../../stub-db');
 const DB = require('../../../src/db/postgres');
@@ -281,7 +279,7 @@ describe('DatabasePostgres', function () {
       assert(db.db.batch.called);
     });
     it('failure', async function () {
-      sinon.stub(db.db, 'tx').rejects(expectedException)
+      sinon.stub(db.db, 'tx').rejects(expectedException);
       await assert.rejects(() => db._purgeTables(true), expectedException);
     });
   }); // _purgeTables
@@ -318,7 +316,7 @@ describe('DatabasePostgres', function () {
     let event, date;
     beforeEach(function () {
       event = 'test_event';
-      date = new Date('Fri Dec 22 03:27 UTC 2023')
+      date = new Date('Fri Dec 22 03:27 UTC 2023');
     });
     it('success', async function () {
       const dbResult = {
@@ -349,7 +347,6 @@ describe('DatabasePostgres', function () {
     });
   }); // almanacUpsert
 
-
   describe('authenticationSuccess', function () {
     let identifier;
     beforeEach(function () {
@@ -420,6 +417,60 @@ describe('DatabasePostgres', function () {
     });
   }); // authenticationUpsert
 
+  describe('authenticationUpdateCredential', function () {
+    let identifier, credential;
+    beforeEach(function () {
+      identifier = 'username';
+      credential = '$z$foo';
+    });
+    it('success', async function () {
+      const dbResult = {
+        rowCount: 1,
+        rows: undefined,
+        duration: 22,
+      };
+      sinon.stub(db.db, 'result').resolves(dbResult);
+      await db.authenticationUpdateCredential(dbCtx, identifier, credential);
+    });
+    it('failure', async function () {
+      credential = undefined;
+      const dbResult = {
+        rowCount: 0,
+        rows: undefined,
+        duration: 22,
+      };
+      sinon.stub(db.db, 'result').resolves(dbResult);
+      await assert.rejects(() => db.authenticationUpdateCredential(dbCtx, identifier, credential), DBErrors.UnexpectedResult);
+
+    });
+  }); // authenticationUpdateCredential
+
+  describe('authenticationUpdateOTPKey', function () {
+    let identifier, otpKey;
+    beforeEach(function () {
+      identifier = 'username';
+      otpKey = '1234567890123456789012';
+    });
+    it('success', async function () {
+      const dbResult = {
+        rowCount: 1,
+        rows: undefined,
+        duration: 22,
+      };
+      sinon.stub(db.db, 'result').resolves(dbResult);
+      await db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey);
+    });
+    it('failure', async function () {
+      const dbResult = {
+        rowCount: 0,
+        rows: undefined,
+        duration: 22,
+      };
+      sinon.stub(db.db, 'result').resolves(dbResult);
+      await assert.rejects(() => db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey), DBErrors.UnexpectedResult);
+    });
+  }); // authenticationUpdateOTPKey
+
   describe('profileIdentifierInsert', function () {
     let profile, identifier;
     beforeEach(function () {
@@ -770,7 +821,7 @@ describe('DatabasePostgres', function () {
         duration: 22,
       };
       sinon.stub(db.db, 'result').resolves(dbResult);
-      await db.resourceUpsert(dbCtx, resourceId, secret, description)
+      await db.resourceUpsert(dbCtx, resourceId, secret, description);
     });
     it('failure', async function () {
       const dbResult = {