fix topic update integration test, topicGetByUrl now optionally applies defaults
authorJustin Wind <justin.wind+git@gmail.com>
Sat, 30 Jul 2022 18:08:12 +0000 (11:08 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Sat, 30 Jul 2022 18:08:12 +0000 (11:08 -0700)
src/db/base.js
src/db/postgres/index.js
src/db/sqlite/index.js
test/src/db/integration.js

index 36cca60328875280620395ae5a4578ebef3136ee..c5ea237c7e1f33c71abfd23f0e4b3136af507f9c 100644 (file)
@@ -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);
   }
 
index 34511102ec5a0e596d0408e2a2bb8bfedeb94eab..2eca12f4909799f6d60ab2249d79d47a3cb4e6e1 100644 (file)
@@ -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;
index 56afa000cb886f900277e4bf819139b93e926707..76309d6c039f623749b575b2f1b1b20f9fb212e5 100644 (file)
@@ -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;
index b92202d41b0e30a04e759872ee984e756f95a13c..bd28e92a9124c7ba1d7cb2c0a7bc9d256e10c983 100644 (file)
@@ -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 () {