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
This commit is contained in:
kirrg001 2017-09-12 17:06:12 +02:00 committed by Hannah Wolfe
parent c99557d9a3
commit 2647b754d1

View File

@ -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);
});
});
});