X-Git-Url: http://git.squeep.com/?p=websub-hub;a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fpostgres.js;h=da071f2ab28566b53b73ba3ff25858c7e96e0355;hp=4a0ecd98516372ecc1adada38595c1ce4c63fa61;hb=f793d88a96b9495172f5dd0c342f2036c902902d;hpb=f97144a77f0ee18efa4b5f0290d030baa2757044 diff --git a/test/src/db/postgres.js b/test/src/db/postgres.js index 4a0ecd9..da071f2 100644 --- a/test/src/db/postgres.js +++ b/test/src/db/postgres.js @@ -1392,6 +1392,7 @@ describe('DatabasePostgres', function () { contentType: 'text/plain', contentHash: 'abc123', }; + sinon.stub(db.db, 'result'); }); it('success', async function() { const dbResult = { @@ -1404,7 +1405,7 @@ describe('DatabasePostgres', function () { lastInsertRowid: undefined, duration: 10, }; - sinon.stub(db.db, 'result').resolves(dbResult); + db.db.result.resolves(dbResult); const result = await db.topicSetContent(dbCtx, data); assert.deepStrictEqual(result, expected); }); @@ -1414,7 +1415,28 @@ describe('DatabasePostgres', function () { rows: [], duration: 10, }; - sinon.stub(db.db, 'result').resolves(dbResult); + db.db.result.resolves(dbResult); + try { + await db.topicSetContent(dbCtx, data); + assert.fail(noExpectedException); + } catch (e) { + assert(e instanceof DBErrors.UnexpectedResult); + } + }); + it('failure 2', async function () { + const dbResultSuccess = { + rowCount: 1, + rows: [], + duration: 10, + }; + const dbResultFail = { + rowCount: 0, + rows: [], + duration: 10, + }; + db.db.result + .onCall(0).resolves(dbResultSuccess) + .onCall(1).resolves(dbResultFail); try { await db.topicSetContent(dbCtx, data); assert.fail(noExpectedException);