From 5680c93b83db8eb15885f3516f2f03b9c35a5991 Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 21 May 2021 19:13:44 +0400 Subject: [PATCH] Added exporter fields integrity check refs https://github.com/TryGhost/Team/issues/610 - When either schema or default settings changes it's often forgotten to check if exporter handles updated tables/keys properly - These tests are meant to serve as a reminder to check exporter and modify what's needed when changes are introduced into schema/default settings --- test/unit/data/exporter/index_spec.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/unit/data/exporter/index_spec.js b/test/unit/data/exporter/index_spec.js index 655c433875..6c63067358 100644 --- a/test/unit/data/exporter/index_spec.js +++ b/test/unit/data/exporter/index_spec.js @@ -164,4 +164,34 @@ describe('Exporter', function () { }).catch(done); }); }); + + describe('Export table whitelists', function () { + it('should be fixed when db schema introduces new tables', function () { + const { + BACKUP_TABLES, + TABLES_ALLOWLIST + } = require('../../../../core/server/data/exporter/table-lists.js'); + + const nonSchemaTables = ['migrations', 'migrations_lock']; + + // NOTE: this test is serving a role of a reminder to have a look into exported tables allowlists + // if it failed you probably need to add or remove a table entry from table-lists module + [...Object.keys(schema.tables), ...nonSchemaTables].sort().should.eql([...BACKUP_TABLES, ...TABLES_ALLOWLIST].sort()); + }); + + it('should be fixed when default settings is changed', function () { + const { + SETTING_KEYS_BLOCKLIST + } = require('../../../../core/server/data/exporter/table-lists.js'); + const defaultSettings = require('../../../../core/server/data/schema/default-settings.json'); + + const totalKeysLength = Object.keys(defaultSettings).reduce((acc, curr, index) => { + return acc + Object.keys(defaultSettings[curr]).length; + }, 0); + + // NOTE: if default settings changed either modify the settings keys blocklist or increase allowedKeysLength + const allowedKeysLength = 76; + totalKeysLength.should.eql(SETTING_KEYS_BLOCKLIST.length + allowedKeysLength); + }); + }); });