From 1d571ced238ac89098fa690bd35f5c9f58cb18f2 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Sat, 30 Jul 2022 11:08:12 -0700 Subject: [PATCH] fix topic update integration test, topicGetByUrl now optionally applies defaults --- src/db/base.js | 3 ++- src/db/postgres/index.js | 7 +++++-- src/db/sqlite/index.js | 7 +++++-- test/src/db/integration.js | 7 +++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/db/base.js b/src/db/base.js index 36cca60..c5ea237 100644 --- a/src/db/base.js +++ b/src/db/base.js @@ -550,8 +550,9 @@ class Database { * Get topic data, without content. * @param {*} dbCtx * @param {String} topicUrl + * @param {Boolean} applyDefaults */ - async topicGetByUrl(dbCtx, topicUrl) { + async topicGetByUrl(dbCtx, topicUrl, applyDefaults = true) { this._notImplemented('topicGetByUrl', arguments); } diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index 3451110..2eca12f 100644 --- a/src/db/postgres/index.js +++ b/src/db/postgres/index.js @@ -789,14 +789,17 @@ class DatabasePostgres extends Database { } - async topicGetByUrl(dbCtx, topicUrl) { + async topicGetByUrl(dbCtx, topicUrl, applyDefaults = true) { const _scope = _fileScope('topicGetByUrl'); this.logger.debug(_scope, 'called', { topicUrl }); let topic; try { topic = await dbCtx.oneOrNone(this.statement.topicGetByUrl, { topicUrl }); - return this._topicDefaults(topic); + if (applyDefaults) { + topic = this._topicDefaults(topic); + } + return topic; } catch (e) { this.logger.error(_scope, 'failed', { error: e, topic, topicUrl }); throw e; diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 56afa00..76309d6 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -759,7 +759,7 @@ class DatabaseSQLite extends Database { } - topicGetByUrl(dbCtx, topicUrl) { + topicGetByUrl(dbCtx, topicUrl, applyDefaults = true) { const _scope = _fileScope('topicGetByUrl'); this.logger.debug(_scope, 'called', { topicUrl }); @@ -767,7 +767,10 @@ class DatabaseSQLite extends Database { try { topic = this.statement.topicGetByUrl.get({ topicUrl }); DatabaseSQLite._topicDataToNative(topic); - return this._topicDefaults(topic); + if (applyDefaults) { + topic = this._topicDefaults(topic); + } + return topic; } catch (e) { this.logger.error(_scope, 'failed', { error: e, topic, topicUrl }); throw e; diff --git a/test/src/db/integration.js b/test/src/db/integration.js index b92202d..bd28e92 100644 --- a/test/src/db/integration.js +++ b/test/src/db/integration.js @@ -153,12 +153,15 @@ describe('Database Integration', function () { const data = { topicId, leaseSecondsMin: 60, - } + }; await db.context(async(dbCtx) => { - let topic = await db.topicGetByUrl(dbCtx, testData.topicSet.url); + const expected = await db.topicGetByUrl(dbCtx, testData.topicSet.url, true); + expected.leaseSecondsMin = data.leaseSecondsMin; + let topic = await db.topicGetByUrl(dbCtx, testData.topicSet.url, false); await db.topicUpdate(dbCtx, { ...topic, ...data }); topic = await db.topicGetByUrl(dbCtx, testData.topicSet.url); assert.strictEqual(Number(topic.leaseSecondsMin), data.leaseSecondsMin); + assert.deepEqual(topic, expected); }); }); step('gets topic by id', async function () { -- 2.45.2