+ describe('upsertAuth', function () {
+ let id, secret, credential;
+ beforeEach(function () {
+ sinon.stub(db.statement.insertAuth, 'run').returns({ changes: 1n, lastInsertRowid: 123n });
+ sinon.stub(db.statement.updateAuth, 'run').returns({ changes: 1n, lastInsertRowid: 123n });
+ });
+ it('stubbed insert success', async function () {
+ await db.upsertAuth(dbCtx, id, secret, credential);
+ });
+ it('stubbed update success', async function () {
+ db.statement.insertAuth.run.throws({ code: 'SQLITE_CONSTRAINT_UNIQUE' });
+ await db.upsertAuth(dbCtx, id, secret, credential);
+ });
+ it('covers error', async function () {
+ const expectedException = new Error('blah');
+ db.statement.insertAuth.run.throws(expectedException);
+ try {
+ await db.upsertAuth(dbCtx, id, secret, credential);
+ assert.fail(noExpectedException);
+ } catch (e) {
+ assert.deepStrictEqual(e, expectedException, noExpectedException);
+ }
+ });
+ it('covers unexpected error', async function () {
+ const expectedException = DBErrors.UnexpectedResult;
+ const returns = {
+ changes: 0n,
+ lastInsertRowid: undefined,
+ };
+ db.statement.insertAuth.run.returns(returns);
+ try {
+ await db.upsertAuth(dbCtx, id, secret, credential);
+ assert.fail(noExpectedException);
+ } catch (e) {
+ assert(e instanceof expectedException, noExpectedException);
+ }
+ });
+ }); // upsertAuth
+