From d30ecf70c08285db8748617d39e65037be981572 Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 12 Mar 2021 19:42:33 +1300 Subject: [PATCH] Added latest export body generator refs https://github.com/TryGhost/Team/issues/555 - Export/Import test suite clean up ctd. See previous commits for context - Main goal here was to update latest JSON export data. Also hardened tests to make sure this fixture is updated whenever the endpoint changes structure --- test/api-acceptance/admin/db_spec.js | 6 ++ test/regression/exporter/exporter_spec.js | 86 ++++++++++++++++++-- test/utils/fixtures/export/body-generator.js | 44 ++++++++++ 3 files changed, 128 insertions(+), 8 deletions(-) diff --git a/test/api-acceptance/admin/db_spec.js b/test/api-acceptance/admin/db_spec.js index 9eacb0bb15..ebeaf3eea8 100644 --- a/test/api-acceptance/admin/db_spec.js +++ b/test/api-acceptance/admin/db_spec.js @@ -5,6 +5,7 @@ const sinon = require('sinon'); const config = require('../../../core/shared/config'); const {events} = require('../../../core/server/lib/common'); const testUtils = require('../../utils'); +const {exportedBodyLatest} = require('../../utils/fixtures/export/body-generator'); const localUtils = require('./utils'); describe('DB API', function () { @@ -47,7 +48,12 @@ describe('DB API', function () { const jsonResponse = res.body; should.exist(jsonResponse.db); jsonResponse.db.should.have.length(1); + + const dataKeys = Object.keys(exportedBodyLatest().db[0].data); + Object.keys(jsonResponse.db[0].data).length.should.eql(28); + Object.keys(jsonResponse.db[0].data).length.should.eql(dataKeys.length); + jsonResponse.db[0].data.should.have.only.keys(...dataKeys); }); it('Can import a JSON database exported from Ghost v2', async function () { diff --git a/test/regression/exporter/exporter_spec.js b/test/regression/exporter/exporter_spec.js index ce4e98fb5f..b5f0914d00 100644 --- a/test/regression/exporter/exporter_spec.js +++ b/test/regression/exporter/exporter_spec.js @@ -3,11 +3,12 @@ const sinon = require('sinon'); const testUtils = require('../../utils'); const _ = require('lodash'); +const ghostVersion = require('../../../core/server/lib/ghost-version'); +const {exportedBodyLatest} = require('../../utils/fixtures/export/body-generator'); + // Stuff we are testing const exporter = require('../../../core/server/data/exporter'); -const ghostVersion = require('../../../core/server/lib/ghost-version'); - describe('Exporter', function () { before(testUtils.teardownDb); afterEach(testUtils.teardownDb); @@ -18,20 +19,89 @@ describe('Exporter', function () { should.exist(exporter); - it('exports data', function (done) { + it('exports expected table data', function (done) { exporter.doExport().then(function (exportData) { - const tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', - 'permissions_users', 'settings', 'tags', 'posts_tags']; + const tables = [ + 'actions', + 'api_keys', + 'brute', + 'email_batches', + 'email_recipients', + 'emails', + 'integrations', + 'invites', + 'labels', + 'members', + 'members_email_change_events', + 'members_labels', + 'members_login_events', + 'members_paid_subscription_events', + 'members_payment_events', + 'members_status_events', + 'members_stripe_customers', + 'members_stripe_customers_subscriptions', + 'members_subscribe_events', + 'migrations', + 'migrations_lock', + 'mobiledoc_revisions', + 'permissions', + 'permissions_roles', + 'permissions_users', + 'posts', + 'posts_authors', + 'posts_meta', + 'posts_tags', + 'roles', + 'roles_users', + 'sessions', + 'settings', + 'snippets', + 'tags', + 'tokens', + 'users', + 'webhooks' + ]; should.exist(exportData); - should.exist(exportData.meta); should.exist(exportData.data); + exportData.data.should.have.only.keys(...tables); + exportData.data.should.have.keys(...Object.keys(exportedBodyLatest().db[0].data)); exportData.meta.version.should.equal(ghostVersion.full); - _.each(tables, function (name) { - should.exist(exportData.data[name]); + // excludes table should contain no data + const excludedTables = [ + 'sessions', + 'mobiledoc_revisions', + 'email_batches', + 'email_recipients', + 'members_payment_events', + 'members_login_events', + 'members_email_change_events', + 'members_status_events', + 'members_paid_subscription_events', + 'members_subscribe_events' + ]; + + excludedTables.forEach((tableName) => { + // NOTE: why is this undefined? The key should probably not even be present + should.equal(exportData.data[tableName], undefined); + }); + + // excludes settings with sensitive data + const excludedSettings = [ + 'stripe_connect_publishable_key', + 'stripe_connect_secret_key', + 'stripe_connect_account_id', + 'stripe_secret_key', + 'stripe_publishable_key', + 'members_stripe_webhook_id', + 'members_stripe_webhook_secret' + ]; + + excludedSettings.forEach((settingKey) => { + should.not.exist(_.find(exportData.data.settings, {key: settingKey})); }); should.not.exist(_.find(exportData.data.settings, {key: 'permalinks'})); diff --git a/test/utils/fixtures/export/body-generator.js b/test/utils/fixtures/export/body-generator.js index 82cd7550ec..76b5a38141 100644 --- a/test/utils/fixtures/export/body-generator.js +++ b/test/utils/fixtures/export/body-generator.js @@ -91,6 +91,50 @@ const exportedBodyLegacy = () => { }); }; +// NOTE: clone the fixture before changing in and alias to v5, v6 or whatever the newest version is +const exportedBodyLatest = () => { + return _.clone({ + db: [{ + meta: { + exported_on: 1615520875631, + version: '4.0.0' + }, + data: { + actions: [], + api_keys: [], + brute: [], + emails: [], + integrations: [], + invites: [], + labels: [], + members: [], + members_labels: [], + members_stripe_customers: [], + members_stripe_customers_subscriptions: [], + migrations: [], + migrations_lock: [], + permissions: [], + permissions_roles: [], + permissions_users: [], + posts: [], + posts_authors: [], + posts_meta: [], + posts_tags: [], + roles: [], + roles_users: [], + settings: [], + snippets: [], + tags: [], + tokens: [], + users: [], + webhooks: [] + } + }] + }); +}; + +module.exports.exportedBodyLatest = exportedBodyLatest; +module.exports.exportedBodyV4 = exportedBodyLatest; module.exports.exportedBodyV2 = exportedBodyV2; module.exports.exportedBodyV1 = exportedBodyV1; module.exports.exportedBodyLegacy = exportedBodyLegacy;