From 70e2c07f2e387f3e9afab0311615f14143515cbb Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Mon, 20 Feb 2023 11:06:14 +0000 Subject: [PATCH] Data generator: Ensure user roles are only generated if roles already exist no issue Fixes the build, as in the test environment there are no user roles --- ghost/data-generator/lib/tables/roles-users.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ghost/data-generator/lib/tables/roles-users.js b/ghost/data-generator/lib/tables/roles-users.js index 25ec530a10..e9d25b42e5 100644 --- a/ghost/data-generator/lib/tables/roles-users.js +++ b/ghost/data-generator/lib/tables/roles-users.js @@ -20,9 +20,14 @@ class RolesUsersImporter extends TableImporter { min: 0, max: userRoles.length - 1 })]; + const actualRole = this.roles.find(role => role.name === userRole); + if (!actualRole) { + // No roles defined in database, don't bother creating user role + return; + } return { id: faker.database.mongodbObjectId(), - role_id: this.roles.find(role => role.name === userRole).id, + role_id: actualRole.id, user_id: this.model.id }; }