X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fsqlite.js;h=46163b88e9510b53f409be139cbb2b540f9a2c1a;hb=f0bf29c75b0fd405ff92fa76f058e61162b87e43;hp=e79e75fa421db1526db49f523de99bd9d18428ce;hpb=726cd980f0ed5588cfe8cbb2d994d5e4aef6e292;p=squeep-indie-auther diff --git a/test/src/db/sqlite.js b/test/src/db/sqlite.js index e79e75f..46163b8 100644 --- a/test/src/db/sqlite.js +++ b/test/src/db/sqlite.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 parts of better-sqlite3. */ const assert = require('assert'); -const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require +const sinon = require('sinon'); const StubDatabase = require('../../stub-db'); const StubLogger = require('../../stub-logger'); const DB = require('../../../src/db/sqlite'); @@ -112,7 +110,7 @@ describe('DatabaseSQLite', function () { db._optimize(); assert(db.db.pragma.called); assert(db.statement._optimize.all.called); - assert.strictEqual(db.changesSinceLastOptimize, 0n) + assert.strictEqual(db.changesSinceLastOptimize, 0n); }); }); // _optimize @@ -220,7 +218,7 @@ describe('DatabaseSQLite', function () { let event, date, dbResult; 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'); sinon.stub(db.statement.almanacUpsert, 'run'); dbResult = { changes: 1, @@ -309,6 +307,54 @@ describe('DatabaseSQLite', function () { }); }); // authenticationUpsert + describe('authenticationUpdateCredential', function () { + let identifier, credential; + beforeEach(function () { + identifier = 'username'; + credential = '$z$foo'; + }); + it('success', function() { + const dbResult = { + changes: 1, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateCredential, 'run').returns(dbResult); + db.authenticationUpdateCredential(dbCtx, identifier, credential); + }); + it('failure', function () { + const dbResult = { + changes: 0, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateCredential, 'run').returns(dbResult); + assert.throws(() => db.authenticationUpdateCredential(dbCtx, identifier, credential), DBErrors.UnexpectedResult); + }); + }); // authenticationUpdateCredential + + describe('authenticationUpdateOTPKey', function () { + let identifier, otpKey; + beforeEach(function () { + identifier = 'username'; + otpKey = '1234567890123456789012'; + }); + it('success', function() { + const dbResult = { + changes: 1, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateOtpKey, 'run').returns(dbResult); + db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey); + }); + it('failure', function () { + const dbResult = { + changes: 0, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateOtpKey, 'run').returns(dbResult); + assert.throws(() => db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey), DBErrors.UnexpectedResult); + }); + }); // authenticationUpdateOTPKey + describe('profileIdentifierInsert', function () { let profile, identifier; beforeEach(function () { @@ -526,7 +572,7 @@ describe('DatabaseSQLite', function () { expires: new Date(refreshResponse.expires * 1000), refreshExpires: new Date(refreshResponse.refreshExpires * 1000), scopes: ['blah'], - } + }; const response = db.refreshCode(dbCtx, codeId, refreshed, removeScopes); assert.deepStrictEqual(response, expectedResponse); }); @@ -536,7 +582,7 @@ describe('DatabaseSQLite', function () { const expectedResponse = { expires: new Date(refreshResponse.expires * 1000), refreshExpires: new Date(refreshResponse.refreshExpires * 1000), - } + }; removeScopes = []; const response = db.refreshCode(dbCtx, codeId, refreshed, removeScopes); assert.deepStrictEqual(response, expectedResponse); @@ -548,7 +594,7 @@ describe('DatabaseSQLite', function () { expires: new Date(refreshResponse.expires * 1000), refreshExpires: new Date(refreshResponse.refreshExpires * 1000), scopes: [], - } + }; const response = db.refreshCode(dbCtx, codeId, refreshed, removeScopes); assert.deepStrictEqual(response, expectedResponse); }); @@ -675,7 +721,7 @@ describe('DatabaseSQLite', function () { sinon.stub(db.statement.scopeInUse, 'get'); dbGetResult = { inUse: false, - } + }; sinon.stub(db.statement.scopeDelete, 'run'); dbRunResult = { changes: 1, @@ -850,7 +896,7 @@ describe('DatabaseSQLite', function () { let dbResult, codeId; beforeEach(function () { codeId = '2f226616-3e79-11ec-ad0f-0025905f714a'; - sinon.stub(db.statement.tokenRevokeByCodeId, 'run') + sinon.stub(db.statement.tokenRevokeByCodeId, 'run'); dbResult = { changes: 1, lastInsertRowid: undefined, @@ -1001,7 +1047,7 @@ describe('DatabaseSQLite', function () { const dbResultAlmanac = { ...dbResult, changes: 0, - } + }; db.statement.ticketTokenPublished.run.returns(dbResult); db.statement.almanacUpsert.run.returns(dbResultAlmanac); assert.throws(() => db.ticketTokenPublished(dbCtx, redeemedData), DBErrors.UnexpectedResult);