From d6d68411860a6ab2469b19a0f3c256c76d843b1b Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 20 May 2022 15:10:14 +0100 Subject: [PATCH] Added benefits, offers and snippets to exporter - These are more things that we should write an importer for --- core/server/data/exporter/index.js | 5 ++++- core/server/data/exporter/table-lists.js | 15 ++++++++------- test/regression/api/admin/db.test.js | 6 ++++-- test/unit/server/data/exporter/index.test.js | 18 ++++++++++++++---- test/utils/fixtures/export/body-generator.js | 5 +++++ 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/core/server/data/exporter/index.js b/core/server/data/exporter/index.js index 06959124b7..39930b795e 100644 --- a/core/server/data/exporter/index.js +++ b/core/server/data/exporter/index.js @@ -1,5 +1,8 @@ +const {BACKUP_TABLES, TABLES_ALLOWLIST} = require('./table-lists'); + module.exports = { doExport: require('./exporter'), fileName: require('./export-filename'), - BACKUP_TABLES: require('./table-lists').BACKUP_TABLES + BACKUP_TABLES, + TABLES_ALLOWLIST }; diff --git a/core/server/data/exporter/table-lists.js b/core/server/data/exporter/table-lists.js index dd5de101da..68185e5c46 100644 --- a/core/server/data/exporter/table-lists.js +++ b/core/server/data/exporter/table-lists.js @@ -17,10 +17,7 @@ const BACKUP_TABLES = [ 'permissions', 'permissions_roles', 'permissions_users', - 'benefits', - 'products_benefits', 'webhooks', - 'snippets', 'tokens', 'sessions', 'mobiledoc_revisions', @@ -34,9 +31,8 @@ const BACKUP_TABLES = [ 'members_paid_subscription_events', 'members_subscribe_events', 'members_product_events', - 'members_newsletters', - 'offers', - 'offer_redemptions' + 'members_newsletters' + ]; // NOTE: exposing only tables which are going to be included in a "default" export file @@ -57,7 +53,12 @@ const TABLES_ALLOWLIST = [ 'stripe_products', 'stripe_prices', 'posts_products', - 'newsletters' + 'newsletters', + 'benefits', + 'products_benefits', + 'offers', + 'offer_redemptions', + 'snippets' ]; // NOTE: these are settings keys which should never end up in the export file diff --git a/test/regression/api/admin/db.test.js b/test/regression/api/admin/db.test.js index 9c3cf25574..3c27390e1a 100644 --- a/test/regression/api/admin/db.test.js +++ b/test/regression/api/admin/db.test.js @@ -14,6 +14,8 @@ const localUtils = require('./utils'); let request; let eventsTriggered; +const TABLE_ALLOWLIST_LENGTH = 20; + describe('DB API (canary)', function () { let backupKey; let schedulerKey; @@ -52,8 +54,8 @@ describe('DB API (canary)', function () { should.exist(jsonResponse.db); jsonResponse.db.should.have.length(1); - // NOTE: 16 default tables + 1 from include parameters - Object.keys(jsonResponse.db[0].data).length.should.eql(16); + // NOTE: default tables + 1 from include parameters + Object.keys(jsonResponse.db[0].data).length.should.eql(TABLE_ALLOWLIST_LENGTH + 1); }); }); diff --git a/test/unit/server/data/exporter/index.test.js b/test/unit/server/data/exporter/index.test.js index f50794d5a1..d3b90ca607 100644 --- a/test/unit/server/data/exporter/index.test.js +++ b/test/unit/server/data/exporter/index.test.js @@ -40,7 +40,7 @@ describe('Exporter', function () { it('should try to export all the correct tables (without excluded)', function (done) { exporter.doExport().then(function (exportData) { // NOTE: 15 default tables - const expectedCallCount = 15; + const expectedCallCount = exporter.TABLES_ALLOWLIST.length; should.exist(exportData); @@ -67,7 +67,12 @@ describe('Exporter', function () { 'stripe_products', 'stripe_prices', 'posts_products', - 'newsletters' + 'newsletters', + 'benefits', + 'products_benefits', + 'offers', + 'offer_redemptions', + 'snippets' ]; for (let call = 0; call < expectedCallCount; call++) { @@ -86,7 +91,7 @@ describe('Exporter', function () { exporter.doExport({include}).then(function (exportData) { // NOTE: 15 default tables + 2 includes - const expectedCallCount = 17; + const expectedCallCount = exporter.TABLES_ALLOWLIST.length + 2; should.exist(exportData); @@ -114,7 +119,12 @@ describe('Exporter', function () { 'stripe_products', 'stripe_prices', 'posts_products', - 'newsletters' + 'newsletters', + 'benefits', + 'products_benefits', + 'offers', + 'offer_redemptions', + 'snippets' ].concat(include); for (let call = 0; call < expectedCallCount; call++) { diff --git a/test/utils/fixtures/export/body-generator.js b/test/utils/fixtures/export/body-generator.js index eb1885725d..726fad7fb7 100644 --- a/test/utils/fixtures/export/body-generator.js +++ b/test/utils/fixtures/export/body-generator.js @@ -141,17 +141,22 @@ const exportedBodyLatest = () => { version: '4.1.2' }, data: { + benefits: [], custom_theme_settings: [], newsletters: [], + offers: [], + offer_redemptions: [], posts: [], posts_authors: [], posts_meta: [], posts_products: [], posts_tags: [], products: [], + products_benefits: [], roles: [], roles_users: [], settings: [], + snippets: [], stripe_prices: [], stripe_products: [], tags: [],