X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fpostgres.js;h=d6bf6746524e88275078233d041195b356d4f966;hb=b2b6739161c11c0b4344ac335ebe9f2d0ba592f3;hp=4a0ecd98516372ecc1adada38595c1ce4c63fa61;hpb=d5e7908d3e60ee0cb3149163d4749563cdfafeb3;p=websub-hub diff --git a/test/src/db/postgres.js b/test/src/db/postgres.js index 4a0ecd9..d6bf674 100644 --- a/test/src/db/postgres.js +++ b/test/src/db/postgres.js @@ -141,7 +141,7 @@ describe('DatabasePostgres', function () { columnTwo: 4, }, ]; - db.pgpInitOptions.receive(data, result, event) + db.pgpInitOptions.receive({ data, result, ctx: event }); assert(db.logger.debug.called); assert.deepStrictEqual(data, expectedData); }); @@ -170,7 +170,7 @@ describe('DatabasePostgres', function () { columnTwo: 4, }, ]; - db.pgpInitOptions.receive(data, result, event) + db.pgpInitOptions.receive({ data, result, ctx: event }); assert(!db.logger.debug.called); assert.deepStrictEqual(data, expectedData); }); @@ -1322,6 +1322,21 @@ describe('DatabasePostgres', function () { }); }); + describe('topicPublishHistory', function () { + beforeEach(function () { + sinon.stub(db.db, 'manyOrNone'); + }); + it('success', async function () { + db.db.manyOrNone.returns([ + { daysAgo: 1, contentUpdates: 1 }, + { daysAgo: 3, contentUpdates: 2 }, + ]); + const result = await db.topicPublishHistory(dbCtx, topicId, 7); + const expected = [0, 1, 0, 2, 0, 0, 0]; + assert.deepStrictEqual(result, expected); + }); + }); // topicPublishHistory + describe('topicSet', function () { let data; beforeEach(function () { @@ -1392,6 +1407,7 @@ describe('DatabasePostgres', function () { contentType: 'text/plain', contentHash: 'abc123', }; + sinon.stub(db.db, 'result'); }); it('success', async function() { const dbResult = { @@ -1404,7 +1420,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 +1430,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);