From 2647b754d17b9b0eb0d40448ebdcfdb6d62170af Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Tue, 12 Sep 2017 17:06:12 +0200 Subject: [PATCH] Tests: Improve random failures and optimise comment id tests refs #7470 - the importer test causes problems with the order of posts - the importer is greedy and tries to add data in parallel, but the tests simply fetch the raw data from knex without any order - while i was improving the order problem, i found this amp/disqus edge case Order Random Failure Example: 1) Import (new test structure) 1.0: basic import test keeps the value of the amp field: AssertionError: expected '59a952be7d79ed06b0d21128' to equal '1' + expected - actual -59a952be7d79ed06b0d21128 +1 --- .../data/importer/importers/data_spec.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/test/integration/data/importer/importers/data_spec.js b/core/test/integration/data/importer/importers/data_spec.js index dd4cadffcf..b62fcb273c 100644 --- a/core/test/integration/data/importer/importers/data_spec.js +++ b/core/test/integration/data/importer/importers/data_spec.js @@ -272,7 +272,7 @@ describe('Import', function () { // Grab the data from tables return Promise.all([ knex('users').select(), - knex('posts').select(), + models.Post.findPage(testUtils.context.internal), knex('settings').select(), knex('tags').select() ]); @@ -282,7 +282,7 @@ describe('Import', function () { importedData.length.should.equal(4, 'Did not get data successfully'); var users = importedData[0], - posts = importedData[1], + posts = importedData[1].posts, settings = importedData[2], tags = importedData[3]; @@ -299,6 +299,7 @@ describe('Import', function () { // import no longer requires all data to be dropped, and adds posts posts.length.should.equal(exportData.data.posts.length, 'Wrong number of posts'); + posts[0].comment_id.should.eql(exportData.data.posts[0].id.toString()); // active_theme should NOT have been overridden _.find(settings, {key: 'active_theme'}).value.should.equal('casper', 'Wrong theme'); @@ -1677,12 +1678,15 @@ describe('Import (new test structure)', function () { after(testUtils.teardown); it('keeps the value of the amp field', function () { - return knex('posts').select().then(function (posts) { - should.exist(posts); + return models.Post.findPage(_.merge({formats: 'amp'}, testUtils.context.internal)).then(function (response) { + should.exist(response.posts); - posts.length.should.eql(exportData.data.posts.length); - posts[0].amp.should.eql(exportData.data.posts[0].amp); - posts[1].amp.should.eql(exportData.data.posts[1].id); + response.posts.length.should.eql(exportData.data.posts.length); + response.posts[0].amp.should.eql(exportData.data.posts[1].id); + response.posts[1].amp.should.eql(exportData.data.posts[0].amp); + + response.posts[0].comment_id.should.eql(response.posts[0].amp); + response.posts[1].comment_id.should.eql(response.posts[1].amp); }); }); });