From 74cdbadedb7af2393fe4f3ff60d82ce6a92d9b78 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 25 Mar 2021 13:22:34 +1300 Subject: [PATCH] Fixed exporter tests using should.have.keys assertion refs https://github.com/TryGhost/Team/issues/555 refs https://github.com/TryGhost/Ghost/commit/080a8fc082951db294eebdc3bfbe0bfb557d5de8 - The `have.keys` assertion was not doing strict comparison neither provided any useful output when changed to `have.only.keys`. - Rewrote the tests to use manual assertion through array comparison which checks exactly what it's supposed to and gives a visual diff in case there are any missing/extra properties in config --- test/api-acceptance/admin/db_spec.js | 6 +++--- test/regression/exporter/exporter_spec.js | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/api-acceptance/admin/db_spec.js b/test/api-acceptance/admin/db_spec.js index 1d95f02545..c166b47f51 100644 --- a/test/api-acceptance/admin/db_spec.js +++ b/test/api-acceptance/admin/db_spec.js @@ -51,9 +51,9 @@ describe('DB API', function () { 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); + // NOTE: using `Object.keys` here instead of `should.have.only.keys` assertion + // because when `have.only.keys` fails there's no useful diff + Object.keys(jsonResponse.db[0].data).should.eql(dataKeys); }); it('Can delete all content', async function () { diff --git a/test/regression/exporter/exporter_spec.js b/test/regression/exporter/exporter_spec.js index b5f0914d00..1669e1ca6d 100644 --- a/test/regression/exporter/exporter_spec.js +++ b/test/regression/exporter/exporter_spec.js @@ -66,8 +66,10 @@ describe('Exporter', function () { 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)); + // NOTE: using `Object.keys` here instead of `should.have.only.keys` assertion + // because when `have.only.keys` fails there's no useful diff + Object.keys(exportData.data).should.eql(tables); + Object.keys(exportData.data).should.containDeep(Object.keys(exportedBodyLatest().db[0].data)); exportData.meta.version.should.equal(ghostVersion.full); // excludes table should contain no data