0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed users:no-owner fixture to add roles correctly

- This fixture would only work if the roles were inserted by the fixture system
- In most cases, this fixture was adding users without their associated roles
- Now we assume the roles exist already, and that we need to map users to each role
- This will allow us to more easily test user roles in e2e tests
This commit is contained in:
Hannah Wolfe 2022-09-02 08:12:31 +01:00
parent 82c3e6b6a4
commit 032a26f9f3
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037
3 changed files with 2439 additions and 2 deletions

File diff suppressed because it is too large Load diff

View file

@ -277,17 +277,21 @@ const fixtures = {
});
},
createUsersWithoutOwner: function createUsersWithoutOwner() {
createUsersWithoutOwner: async function createUsersWithoutOwner() {
const usersWithoutOwner = _.cloneDeep(DataGenerator.forKnex.users.slice(1));
let roles = await models.Role.fetchAll();
roles = roles.toJSON();
return Promise.map(usersWithoutOwner, function (user) {
let userRolesRelations = _.filter(DataGenerator.forKnex.roles_users, {user_id: user.id});
userRolesRelations = _.map(userRolesRelations, function (userRolesRelation) {
return _.find(DataGenerator.forKnex.roles, {id: userRolesRelation.role_id});
return _.find(roles, {name: userRolesRelation.role_name});
});
user.roles = userRolesRelations;
return models.User.add(user, context.internal);
});
},

View file

@ -1284,27 +1284,37 @@ DataGenerator.forKnex = (function () {
const roles_users = [
{
// owner
id: ObjectId().toHexString(),
role_name: 'Owner',
user_id: DataGenerator.Content.users[0].id,
role_id: DataGenerator.Content.roles[3].id
},
{
// admin
id: ObjectId().toHexString(),
role_name: 'Administrator',
user_id: DataGenerator.Content.users[1].id,
role_id: DataGenerator.Content.roles[0].id
},
{
// editor
id: ObjectId().toHexString(),
role_name: 'Editor',
user_id: DataGenerator.Content.users[2].id,
role_id: DataGenerator.Content.roles[1].id
},
{
// author
id: ObjectId().toHexString(),
role_name: 'Author',
user_id: DataGenerator.Content.users[3].id,
role_id: DataGenerator.Content.roles[2].id
},
{
// contributor
id: ObjectId().toHexString(),
role_name: 'Contributor',
user_id: DataGenerator.Content.users[7].id,
role_id: DataGenerator.Content.roles[4].id
}