X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fsqlite.js;h=33f00282d9d80ff9b1e1d2278afe4e8cebdf4481;hb=3ca7fccb306d0b23626befc3791ffa360b3db1e7;hp=8d25fc8dda85c3427559ca6a10e8203d1a1c8caf;hpb=1c37a7c533a5530390489ea9a49dcca492db1074;p=websub-hub diff --git a/test/src/db/sqlite.js b/test/src/db/sqlite.js index 8d25fc8..33f0028 100644 --- a/test/src/db/sqlite.js +++ b/test/src/db/sqlite.js @@ -43,6 +43,12 @@ describe('DatabaseSQLite', function () { sinon.restore(); }); + it('covers options', function () { + const xoptions = new Config('test'); + delete xoptions.db.connectionString; + db = new DB(stubLogger, xoptions); + }); + // Ensure all interface methods are implemented describe('Implementation', function () { it('implements interface', async function () { @@ -337,10 +343,11 @@ describe('DatabaseSQLite', function () { }); // authenticationGet describe('authenticationUpsert', function () { - let identifier, credential; + let identifier, credential, otpKey; beforeEach(function () { identifier = 'username'; credential = '$z$foo'; + otpKey = '12345678901234567890123456789012'; }); it('success', async function() { const dbResult = { @@ -348,7 +355,7 @@ describe('DatabaseSQLite', function () { lastInsertRowid: undefined, }; sinon.stub(db.statement.authenticationUpsert, 'run').returns(dbResult); - await db.authenticationUpsert(dbCtx, identifier, credential); + await db.authenticationUpsert(dbCtx, identifier, credential, otpKey); }); it('failure', async function () { const dbResult = { @@ -357,7 +364,65 @@ describe('DatabaseSQLite', function () { }; sinon.stub(db.statement.authenticationUpsert, 'run').returns(dbResult); try { - await db.authenticationUpsert(dbCtx, identifier, credential); + await db.authenticationUpsert(dbCtx, identifier, credential, otpKey); + assert.fail(noExpectedException); + } catch (e) { + assert(e instanceof DBErrors.UnexpectedResult); + } + }); + }); // authenticationUpsert + + describe('authenticationUpdateCredential', function () { + let identifier, credential; + beforeEach(function () { + identifier = 'username'; + credential = '$z$foo'; + }); + it('success', async function() { + const dbResult = { + changes: 1, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateCredential, 'run').returns(dbResult); + await db.authenticationUpdateCredential(dbCtx, identifier, credential); + }); + it('failure', async function () { + const dbResult = { + changes: 0, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateCredential, 'run').returns(dbResult); + try { + await db.authenticationUpdateCredential(dbCtx, identifier, credential); + assert.fail(noExpectedException); + } catch (e) { + assert(e instanceof DBErrors.UnexpectedResult); + } + }); + }); // authenticationUpdateCredential + + describe('authenticationUpdateOTPKey', function () { + let identifier, otpKey; + beforeEach(function () { + identifier = 'username'; + otpKey = '12345678901234567890123456789012'; + }); + it('success', async function() { + const dbResult = { + changes: 1, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateOtpKey, 'run').returns(dbResult); + await db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey); + }); + it('failure', async function () { + const dbResult = { + changes: 0, + lastInsertRowid: undefined, + }; + sinon.stub(db.statement.authenticationUpdateOtpKey, 'run').returns(dbResult); + try { + await db.authenticationUpdateOTPKey(dbCtx, identifier, otpKey); assert.fail(noExpectedException); } catch (e) { assert(e instanceof DBErrors.UnexpectedResult); @@ -1042,6 +1107,12 @@ describe('DatabaseSQLite', function () { const result = await db.topicGetByUrl(dbCtx, topicUrl); assert.deepStrictEqual(result, expected); }); + it('success, no defaults', async function() { + const expected = []; + sinon.stub(db.statement.topicGetByUrl, 'get').returns(expected); + const result = await db.topicGetByUrl(dbCtx, topicUrl, false); + assert.deepStrictEqual(result, expected); + }); it('failure', async function () { const expected = new Error(); sinon.stub(db.statement.topicGetByUrl, 'get').throws(expected);