From 84fcedb036a1ab49a83514669001057965b513bb Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Sat, 6 Oct 2018 02:09:07 +0200 Subject: [PATCH] Fixed travis no issue - last commit failed on mysql - reverted added a new user to knex test utility - added the user in the target test @TODO: we should in the future add resources per test, without using a "global" set, otherwise you always run into trouble that you have to update a lot of tests when you add a new resource to the test set --- .../test/functional/routes/api/public_api_spec.js | 8 ++++---- core/test/integration/api/api_users_spec.js | 13 ++++++++++--- core/test/integration/model/model_posts_spec.js | 4 ++-- core/test/integration/model/model_users_spec.js | 6 +++--- .../integration/services/url/UrlService_spec.js | 15 +++------------ core/test/utils/fixtures/data-generator.js | 8 +------- 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/core/test/functional/routes/api/public_api_spec.js b/core/test/functional/routes/api/public_api_spec.js index 6f958eaa38..e4ed24a82c 100644 --- a/core/test/functional/routes/api/public_api_spec.js +++ b/core/test/functional/routes/api/public_api_spec.js @@ -462,7 +462,7 @@ describe('Public API', function () { var jsonResponse = res.body; should.exist(jsonResponse.users); testUtils.API.checkResponse(jsonResponse, 'users'); - jsonResponse.users.should.have.length(7); + jsonResponse.users.should.have.length(6); // We don't expose the email address. testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true}); @@ -485,7 +485,7 @@ describe('Public API', function () { var jsonResponse = res.body; should.exist(jsonResponse.users); testUtils.API.checkResponse(jsonResponse, 'users'); - jsonResponse.users.should.have.length(7); + jsonResponse.users.should.have.length(6); // We don't expose the email address. testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true}); @@ -635,7 +635,7 @@ describe('Public API', function () { var jsonResponse = res.body; should.exist(jsonResponse.users); testUtils.API.checkResponse(jsonResponse, 'users'); - jsonResponse.users.should.have.length(7); + jsonResponse.users.should.have.length(6); // We don't expose the email address. testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true}); @@ -658,7 +658,7 @@ describe('Public API', function () { var jsonResponse = res.body; should.exist(jsonResponse.users); testUtils.API.checkResponse(jsonResponse, 'users'); - jsonResponse.users.should.have.length(7); + jsonResponse.users.should.have.length(6); // We don't expose the email address. testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true}); diff --git a/core/test/integration/api/api_users_spec.js b/core/test/integration/api/api_users_spec.js index cd14ee7aaa..89507efc69 100644 --- a/core/test/integration/api/api_users_spec.js +++ b/core/test/integration/api/api_users_spec.js @@ -23,6 +23,13 @@ describe('Users API', function () { 'settings', 'users:roles', 'users:extra', 'user-token', 'perms:user', 'perms:role', 'perms:setting', 'perms:init', 'posts' )); + before(function () { + return testUtils.createUser({ + user: testUtils.DataGenerator.Content.users[6], + role: 'Administrator' + }); + }); + beforeEach(function () { eventsTriggered = {}; @@ -915,7 +922,7 @@ describe('Users API', function () { return db.knex('users'); }).then(function (result) { - _.flatten(result).length.should.eql(10); + _.flatten(result).length.should.eql(9); return UserAPI.destroy(_.extend({}, context.owner, _.merge({}, options, {id: userIdFor.editor}))); }).then(function () { @@ -963,8 +970,8 @@ describe('Users API', function () { return db.knex('users'); }).then(function (allUsers) { - // one user was deleted, that's why 9 - allUsers.length.should.eql(9); + // one user was deleted, that's why 8 + allUsers.length.should.eql(8); done(); }).catch(done); }); diff --git a/core/test/integration/model/model_posts_spec.js b/core/test/integration/model/model_posts_spec.js index a6b1a5e845..f9ec544848 100644 --- a/core/test/integration/model/model_posts_spec.js +++ b/core/test/integration/model/model_posts_spec.js @@ -1705,11 +1705,11 @@ describe('Post Model', function () { return models.Post.destroyByAuthor(authorData); }).then(function (results) { // User 1 has 10 posts in the database - results.length.should.equal(9); + results.length.should.equal(10); return models.Post.findAll({context: {internal: true}}); }).then(function (found) { // Only 40 should remain - found.length.should.equal(41); + found.length.should.equal(40); done(); }).catch(done); }); diff --git a/core/test/integration/model/model_users_spec.js b/core/test/integration/model/model_users_spec.js index 80680a2233..02899f78a7 100644 --- a/core/test/integration/model/model_users_spec.js +++ b/core/test/integration/model/model_users_spec.js @@ -201,7 +201,7 @@ describe('User Model', function run() { it('can findAll', function (done) { UserModel.findAll().then(function (results) { should.exist(results); - results.length.should.equal(6); + results.length.should.equal(5); done(); }).catch(done); @@ -214,7 +214,7 @@ describe('User Model', function run() { results.meta.pagination.page.should.equal(1); results.meta.pagination.limit.should.equal(15); results.meta.pagination.pages.should.equal(1); - results.data.length.should.equal(6); + results.data.length.should.equal(5); done(); }).catch(done); @@ -260,7 +260,7 @@ describe('User Model', function run() { results.meta.pagination.page.should.equal(1); results.meta.pagination.limit.should.equal('all'); results.meta.pagination.pages.should.equal(1); - results.data.length.should.equal(10); + results.data.length.should.equal(9); }); }); diff --git a/core/test/integration/services/url/UrlService_spec.js b/core/test/integration/services/url/UrlService_spec.js index 693f62a5ff..92725e9cf3 100644 --- a/core/test/integration/services/url/UrlService_spec.js +++ b/core/test/integration/services/url/UrlService_spec.js @@ -148,7 +148,7 @@ describe('Integration: services/url/UrlService', function () { } if (generator.router.getResourceType() === 'users') { - generator.getUrls().length.should.eql(6); + generator.getUrls().length.should.eql(5); } }); @@ -190,9 +190,6 @@ describe('Integration: services/url/UrlService', function () { url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[4].id); url.should.eql('/author/contributor/'); - - url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[5].id); - url.should.eql('/author/ad-2/'); }); it('getResource', function () { @@ -455,7 +452,7 @@ describe('Integration: services/url/UrlService', function () { } if (generator.router.getResourceType() === 'users') { - generator.getUrls().length.should.eql(6); + generator.getUrls().length.should.eql(5); } }); @@ -498,9 +495,6 @@ describe('Integration: services/url/UrlService', function () { url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[4].id); url.should.eql('/persons/contributor/'); - - url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[5].id); - url.should.eql('/persons/ad-2/'); }); describe('update resource', function () { @@ -698,7 +692,7 @@ describe('Integration: services/url/UrlService', function () { } if (generator.router.getResourceType() === 'users') { - generator.getUrls().length.should.eql(6); + generator.getUrls().length.should.eql(5); } }); @@ -741,9 +735,6 @@ describe('Integration: services/url/UrlService', function () { url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[4].id); url.should.eql('/persons/contributor/'); - - url = urlService.getUrlByResourceId(testUtils.DataGenerator.forKnex.users[5].id); - url.should.eql('/persons/ad-2/'); }); }); }); diff --git a/core/test/utils/fixtures/data-generator.js b/core/test/utils/fixtures/data-generator.js index 692bd2aa5a..30000bca46 100644 --- a/core/test/utils/fixtures/data-generator.js +++ b/core/test/utils/fixtures/data-generator.js @@ -702,8 +702,7 @@ DataGenerator.forKnex = (function () { createUser(DataGenerator.Content.users[1]), createUser(DataGenerator.Content.users[2]), createUser(DataGenerator.Content.users[3]), - createUser(DataGenerator.Content.users[7]), - createUser(DataGenerator.Content.users[6]), + createUser(DataGenerator.Content.users[7]) ]; const clients = [ @@ -738,11 +737,6 @@ DataGenerator.forKnex = (function () { id: ObjectId.generate(), user_id: DataGenerator.Content.users[7].id, role_id: DataGenerator.Content.roles[4].id - }, - { - id: ObjectId.generate(), - user_id: DataGenerator.Content.users[6].id, - role_id: DataGenerator.Content.roles[0].id } ];