X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fpostgres.js;h=caa665266999f9d8f51f7201ee84882dcb8e52a3;hb=f0bf29c75b0fd405ff92fa76f058e61162b87e43;hp=3920d340f53e2471b4fe5df55a32d25546996153;hpb=726cd980f0ed5588cfe8cbb2d994d5e4aef6e292;p=squeep-indie-auther diff --git a/test/src/db/postgres.js b/test/src/db/postgres.js index 3920d34..caa6652 100644 --- a/test/src/db/postgres.js +++ b/test/src/db/postgres.js @@ -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 = {