@jahia/cypress 8.2.1 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @jahia/cypress Changelog
2
2
 
3
+ ## 8.3.0
4
+
5
+ ### New Features
6
+
7
+ * Add specs and tests marks to jahia log (#234)
8
+
9
+ ### Bug Fixes
10
+
11
+ * Update UserHelpers: unify interfaces and internal variables; add logging; extend createUser with site-level operation (#228)
12
+
3
13
  ## 8.2.1
4
14
 
5
15
  * Temporary remove bash injections which can be treated by antivirus as a potentially unsafe. They will be reworked and brought back later on. (#224)
package/README.md CHANGED
@@ -171,7 +171,4 @@ This is an Open-Source codebase, you can find more details about Open-Source @ J
171
171
 
172
172
  ## How to release
173
173
 
174
- Releases are now semi-automated using [Chachalog](https://github.com/GauBen/chachalog). To create a new release:
175
-
176
- - Merge the `chore: release` PR from `github-actions`.
177
- - From Github release panel, draft a new release with a tag named `vX.Y.Z` (use the same version as the one set by Chachalog in the `chore: release` PR) and a title `vX.Y.Z`. The release will be published to NPM automatically.
174
+ Releases are now automated using [Chachalog](https://github.com/GauBen/chachalog). To create a new release, merge the `chore: release` PR from `github-actions`: the package is then published to NPM and tagged `@jahia/cypress@X.Y.Z` automatically.
@@ -0,0 +1,3 @@
1
+ export declare const jahiaLog: {
2
+ enableSpecsMarker: () => void;
3
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jahiaLog = void 0;
4
+ // Groovy script to be used for logging test suite and test case start/end markers
5
+ var loggerScript = 'groovy/logger.groovy';
6
+ var delimeters = { spec: '='.repeat(20), test: '-'.repeat(20) };
7
+ /**
8
+ * Generates a marker for the beginning or end of a test suite.
9
+ * @param action - The action being performed (e.g., "Starting" or "Ending").
10
+ * @param name - The name of the test suite.
11
+ * @returns A formatted string representing the suite marker.
12
+ */
13
+ var specMarker = function (action, name) { return "".concat(delimeters.spec, " ").concat(action, " ").concat(name, " ").concat(delimeters.spec); };
14
+ /**
15
+ * Generates a marker for the beginning or end of a test.
16
+ * @param action - The action being performed (e.g., "Starting" or "Ending").
17
+ * @param title - The title of the test.
18
+ * @returns A formatted string representing the test marker.
19
+ */
20
+ var testMarker = function (action, title) { return "".concat(delimeters.test, " ").concat(action, " ").concat(title, " ").concat(delimeters.test); };
21
+ /**
22
+ * Enables logging markers for the start and end of test suites and individual tests.
23
+ * This function sets up hooks to log messages before and after each test and suite execution.
24
+ * It uses a Groovy script to log the messages, which can be useful for tracking test execution in Jahia logs.
25
+ */
26
+ var enableSpecsMarker = function () {
27
+ before(function () {
28
+ cy.executeGroovy(loggerScript, { MESSAGE: specMarker('[BEGIN SPEC]', Cypress.spec.name) });
29
+ });
30
+ beforeEach(function () {
31
+ cy.executeGroovy(loggerScript, { MESSAGE: testMarker('[BEGIN TEST]', this.currentTest.title) });
32
+ });
33
+ afterEach(function () {
34
+ cy.executeGroovy(loggerScript, { MESSAGE: testMarker('[END TEST]', this.currentTest.title) });
35
+ });
36
+ after(function () {
37
+ cy.executeGroovy(loggerScript, { MESSAGE: specMarker('[END SPEC]', Cypress.spec.name) });
38
+ });
39
+ };
40
+ exports.jahiaLog = { enableSpecsMarker: enableSpecsMarker };
@@ -22,6 +22,7 @@ var testStep_1 = require("./testStep");
22
22
  var jfaker_1 = require("./jfaker");
23
23
  var modSince_1 = require("./modSince");
24
24
  var contextReporter_1 = require("./contextReporter");
25
+ var jahiaLog_1 = require("./jahiaLog");
25
26
  var registerSupport = function () {
26
27
  Cypress.Commands.add('apolloClient', apollo_1.apolloClient);
27
28
  Cypress.Commands.add('apollo', { prevSubject: 'optional' }, apollo_1.apollo);
@@ -38,6 +39,7 @@ var registerSupport = function () {
38
39
  Cypress.Commands.add('step', testStep_1.step);
39
40
  // Register it.since()/describe.since()
40
41
  modSince_1.modSince.enable();
42
+ jahiaLog_1.jahiaLog.enableSpecsMarker();
41
43
  /**
42
44
  * Override Cypress `type()` command to interpret special characters (e.g., {, }, etc.) either literally or as commands.
43
45
  * The behavior is controlled by the `parseSpecialCharSequences` option, which can be set to `true`
@@ -1,11 +1,66 @@
1
+ /**
2
+ * Grants one or more roles to a principal on a target node.
3
+ * @param {string} pathOrId JCR node path or identifier where roles are granted.
4
+ * @param {Array<string>} roleNames Role names to grant.
5
+ * @param {string} principalName Principal name (user or group) receiving roles.
6
+ * @param {string} principalType Principal type expected by the mutation.
7
+ * @returns {Cypress.Chainable} Cypress chainable for the GraphQL mutation request.
8
+ */
1
9
  export declare const grantRoles: (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string) => Cypress.Chainable;
10
+ /**
11
+ * Revokes one or more roles from a principal on a target node.
12
+ * @param {string} pathOrId JCR node path or identifier where roles are revoked.
13
+ * @param {Array<string>} roleNames Role names to revoke.
14
+ * @param {string} principalName Principal name (user or group) losing roles.
15
+ * @param {string} principalType Principal type expected by the mutation.
16
+ * @returns {Cypress.Chainable} Cypress chainable for the GraphQL mutation request.
17
+ */
2
18
  export declare const revokeRoles: (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string) => Cypress.Chainable;
19
+ /**
20
+ * Creates a Jahia user using the Groovy fixture.
21
+ * @param {string} userName Username of the user to create.
22
+ * @param {string} password Password for the new user. Defaults to "password" when empty.
23
+ * @param {{name: string, value: string}[]} properties Optional user properties to set on creation.
24
+ * @param {string} siteKey Optional site key for site-scoped user creation.
25
+ * @returns {void}
26
+ */
3
27
  export declare const createUser: (userName: string, password: string, properties?: {
4
28
  name: string;
5
29
  value: string;
6
- }[]) => void;
30
+ }[], siteKey?: string) => void;
31
+ /**
32
+ * Retrieves the JCR path of a user.
33
+ * @param {string} username Username to look up.
34
+ * @param {string} siteKey Optional site key for site-scoped users.
35
+ * @returns {Cypress.Chainable} Cypress chainable containing the GraphQL query response.
36
+ */
7
37
  export declare const getUserPath: (username: string, siteKey?: string) => Cypress.Chainable;
38
+ /**
39
+ * Deletes a Jahia user using the Groovy fixture.
40
+ * @param {string} userName Username of the user to delete.
41
+ * @returns {void}
42
+ */
8
43
  export declare const deleteUser: (userName: string) => void;
44
+ /**
45
+ * Creates a Jahia users group using the Groovy fixture.
46
+ * @param {string} groupName Group name to create.
47
+ * @param {boolean} hidden Whether the group should be hidden.
48
+ * @param {string} siteKey Optional site key for site-scoped group creation.
49
+ * @returns {void}
50
+ */
9
51
  export declare const createGroup: (groupName: string, hidden?: boolean, siteKey?: string) => void;
52
+ /**
53
+ * Deletes a Jahia users group using the Groovy fixture.
54
+ * @param {string} groupName Group name to delete.
55
+ * @param {string} siteKey Optional site key for site-scoped group deletion.
56
+ * @returns {void}
57
+ */
10
58
  export declare const deleteGroup: (groupName: string, siteKey?: string) => void;
59
+ /**
60
+ * Adds an existing user to a group using the Groovy fixture.
61
+ * @param {string} userName Username to add to the group.
62
+ * @param {string} groupName Group receiving the user.
63
+ * @param {string} siteKey Optional site key for site-scoped group membership.
64
+ * @returns {void}
65
+ */
11
66
  export declare const addUserToGroup: (userName: string, groupName: string, siteKey?: string) => void;
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addUserToGroup = exports.deleteGroup = exports.createGroup = exports.deleteUser = exports.getUserPath = exports.createUser = exports.revokeRoles = exports.grantRoles = void 0;
4
+ /**
5
+ * Grants one or more roles to a principal on a target node.
6
+ * @param {string} pathOrId JCR node path or identifier where roles are granted.
7
+ * @param {Array<string>} roleNames Role names to grant.
8
+ * @param {string} principalName Principal name (user or group) receiving roles.
9
+ * @param {string} principalType Principal type expected by the mutation.
10
+ * @returns {Cypress.Chainable} Cypress chainable for the GraphQL mutation request.
11
+ */
4
12
  var grantRoles = function (pathOrId, roleNames, principalName, principalType) {
5
- cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
13
+ cy.log("Grant role(s) ".concat(roleNames, " with principal type ").concat(principalType, " to ").concat(principalName, " on node ").concat(pathOrId));
6
14
  return cy.apollo({
7
15
  variables: {
8
16
  pathOrId: pathOrId,
@@ -14,8 +22,16 @@ var grantRoles = function (pathOrId, roleNames, principalName, principalType) {
14
22
  });
15
23
  };
16
24
  exports.grantRoles = grantRoles;
25
+ /**
26
+ * Revokes one or more roles from a principal on a target node.
27
+ * @param {string} pathOrId JCR node path or identifier where roles are revoked.
28
+ * @param {Array<string>} roleNames Role names to revoke.
29
+ * @param {string} principalName Principal name (user or group) losing roles.
30
+ * @param {string} principalType Principal type expected by the mutation.
31
+ * @returns {Cypress.Chainable} Cypress chainable for the GraphQL mutation request.
32
+ */
17
33
  var revokeRoles = function (pathOrId, roleNames, principalName, principalType) {
18
- cy.log('Revoke role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
34
+ cy.log("Revoke role(s) ".concat(roleNames, " with principal type ").concat(principalType, " to ").concat(principalName, " on node ").concat(pathOrId));
19
35
  return cy.apollo({
20
36
  variables: {
21
37
  pathOrId: pathOrId,
@@ -27,20 +43,38 @@ var revokeRoles = function (pathOrId, roleNames, principalName, principalType) {
27
43
  });
28
44
  };
29
45
  exports.revokeRoles = revokeRoles;
30
- var createUser = function (userName, password, properties) {
46
+ /**
47
+ * Creates a Jahia user using the Groovy fixture.
48
+ * @param {string} userName Username of the user to create.
49
+ * @param {string} password Password for the new user. Defaults to "password" when empty.
50
+ * @param {{name: string, value: string}[]} properties Optional user properties to set on creation.
51
+ * @param {string} siteKey Optional site key for site-scoped user creation.
52
+ * @returns {void}
53
+ */
54
+ var createUser = function (userName, password, properties, siteKey) {
31
55
  if (properties === void 0) { properties = []; }
56
+ if (siteKey === void 0) { siteKey = ''; }
57
+ cy.log("Creating ".concat(siteKey === '' ? 'server-level ' : ('site-level:' + siteKey), " user with name ").concat(userName));
32
58
  var userProperties = properties.map(function (property) {
33
59
  return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
34
60
  });
35
61
  cy.executeGroovy('groovy/admin/createUser.groovy', {
36
- USER_NAME: userName,
62
+ USERNAME: userName,
37
63
  PASSWORD: password ? password : 'password',
38
- USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
64
+ USER_PROPERTIES: userProperties ? userProperties.join('\n') : '',
65
+ SITEKEY: siteKey
39
66
  });
40
67
  };
41
68
  exports.createUser = createUser;
69
+ /**
70
+ * Retrieves the JCR path of a user.
71
+ * @param {string} username Username to look up.
72
+ * @param {string} siteKey Optional site key for site-scoped users.
73
+ * @returns {Cypress.Chainable} Cypress chainable containing the GraphQL query response.
74
+ */
42
75
  var getUserPath = function (username, siteKey) {
43
76
  if (siteKey === void 0) { siteKey = ''; }
77
+ cy.log("Getting user path for ".concat(username));
44
78
  return cy.apollo({
45
79
  variables: {
46
80
  siteKey: siteKey,
@@ -50,14 +84,28 @@ var getUserPath = function (username, siteKey) {
50
84
  });
51
85
  };
52
86
  exports.getUserPath = getUserPath;
87
+ /**
88
+ * Deletes a Jahia user using the Groovy fixture.
89
+ * @param {string} userName Username of the user to delete.
90
+ * @returns {void}
91
+ */
53
92
  var deleteUser = function (userName) {
93
+ cy.log("Deleting user ".concat(userName));
54
94
  cy.executeGroovy('groovy/admin/deleteUser.groovy', {
55
- USER_NAME: userName
95
+ USERNAME: userName
56
96
  });
57
97
  };
58
98
  exports.deleteUser = deleteUser;
99
+ /**
100
+ * Creates a Jahia users group using the Groovy fixture.
101
+ * @param {string} groupName Group name to create.
102
+ * @param {boolean} hidden Whether the group should be hidden.
103
+ * @param {string} siteKey Optional site key for site-scoped group creation.
104
+ * @returns {void}
105
+ */
59
106
  var createGroup = function (groupName, hidden, siteKey) {
60
107
  if (siteKey === void 0) { siteKey = ''; }
108
+ cy.log("Creating ".concat(siteKey === '' ? 'server-level' : ('site-level:' + siteKey), " group ").concat(groupName));
61
109
  cy.executeGroovy('groovy/admin/userGroupHelper.groovy', {
62
110
  OPERATION: 'create',
63
111
  GROUPNAME: groupName,
@@ -66,8 +114,15 @@ var createGroup = function (groupName, hidden, siteKey) {
66
114
  });
67
115
  };
68
116
  exports.createGroup = createGroup;
117
+ /**
118
+ * Deletes a Jahia users group using the Groovy fixture.
119
+ * @param {string} groupName Group name to delete.
120
+ * @param {string} siteKey Optional site key for site-scoped group deletion.
121
+ * @returns {void}
122
+ */
69
123
  var deleteGroup = function (groupName, siteKey) {
70
124
  if (siteKey === void 0) { siteKey = ''; }
125
+ cy.log("Deleting ".concat(siteKey === '' ? 'server-level' : ('site-level:' + siteKey), " group ").concat(groupName));
71
126
  cy.executeGroovy('groovy/admin/userGroupHelper.groovy', {
72
127
  OPERATION: 'delete',
73
128
  GROUPNAME: groupName,
@@ -75,11 +130,20 @@ var deleteGroup = function (groupName, siteKey) {
75
130
  });
76
131
  };
77
132
  exports.deleteGroup = deleteGroup;
133
+ /**
134
+ * Adds an existing user to a group using the Groovy fixture.
135
+ * @param {string} userName Username to add to the group.
136
+ * @param {string} groupName Group receiving the user.
137
+ * @param {string} siteKey Optional site key for site-scoped group membership.
138
+ * @returns {void}
139
+ */
78
140
  var addUserToGroup = function (userName, groupName, siteKey) {
141
+ if (siteKey === void 0) { siteKey = ''; }
142
+ cy.log("Add user ".concat(userName, " to ").concat(siteKey === '' ? 'server-level' : ('site-level:' + siteKey), " group ").concat(groupName));
79
143
  cy.executeGroovy('groovy/admin/addUserToGroup.groovy', {
80
- USER_NAME: userName,
81
- GROUP_NAME: groupName,
82
- SITE_KEY: siteKey ? "\"".concat(siteKey, "\"") : 'null'
144
+ USERNAME: userName,
145
+ GROUPNAME: groupName,
146
+ SITEKEY: siteKey
83
147
  });
84
148
  };
85
149
  exports.addUserToGroup = addUserToGroup;
@@ -4,12 +4,13 @@ import org.jahia.services.usermanager.JahiaUserManagerService
4
4
  import org.jahia.services.content.decorator.JCRGroupNode
5
5
  import org.jahia.services.content.decorator.JCRUserNode
6
6
 
7
- log.info("Add user USER_NAME to group GROUP_NAME")
7
+ log.info("Add user USERNAME to group GROUPNAME")
8
+ String siteKey = "SITEKEY".equals("") ? null : "SITEKEY";
8
9
  JCRTemplate.getInstance().doExecuteWithSystemSession(session -> {
9
10
  JahiaUserManagerService userManagerService = JahiaUserManagerService.getInstance()
10
11
  JahiaGroupManagerService groupManagerService = JahiaGroupManagerService.getInstance()
11
- JCRGroupNode groupNode = groupManagerService.lookupGroup(SITE_KEY, "GROUP_NAME", session)
12
- JCRUserNode userNode = userManagerService.lookupUser("USER_NAME")
12
+ JCRGroupNode groupNode = groupManagerService.lookupGroup(siteKey, "GROUPNAME", session)
13
+ JCRUserNode userNode = userManagerService.lookupUser("USERNAME")
13
14
  if (!groupNode.isMember(userNode)) {
14
15
  groupNode.addMember(userNode)
15
16
  }
@@ -7,14 +7,16 @@ import javax.jcr.RepositoryException
7
7
  JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback() {
8
8
  @Override
9
9
  Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
10
- log.info("Create user : USER_NAME")
10
+ log.info("Create user : USERNAME")
11
+
12
+ String siteKey = "SITEKEY".equals("") ? null : "SITEKEY";
11
13
  JahiaUserManagerService userManagerService = JahiaUserManagerService.getInstance()
12
14
 
13
15
  Properties properties = new Properties()
14
16
  USER_PROPERTIES
15
17
 
16
- userManagerService.createUser("USER_NAME", null, "PASSWORD", properties, session)
18
+ userManagerService.createUser("USERNAME", siteKey, "PASSWORD", properties, session)
17
19
  session.save()
18
20
  return null
19
21
  }
20
- })
22
+ })
@@ -7,15 +7,15 @@ import javax.jcr.RepositoryException
7
7
  JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback() {
8
8
  @Override
9
9
  Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
10
- log.info("Delete user : USER_NAME" );
10
+ log.info("Delete user : USERNAME" );
11
11
 
12
12
  JahiaUserManagerService userManagerService = JahiaUserManagerService.getInstance();
13
- def user = userManagerService.getUserPath("USER_NAME");
13
+ def user = userManagerService.getUserPath("USERNAME");
14
14
  if (user) {
15
15
  userManagerService.deleteUser(user, session);
16
16
  session.save();
17
17
  } else {
18
- log.warn("User USER_NAME cannot be deleted. User not found");
18
+ log.warn("User USERNAME cannot be deleted. User not found");
19
19
  }
20
20
  return null;
21
21
  }
@@ -0,0 +1,6 @@
1
+ import org.slf4j.Logger
2
+ import org.slf4j.LoggerFactory
3
+
4
+ final Logger logger = LoggerFactory.getLogger(this.class);
5
+
6
+ logger.info("MESSAGE")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts --max-warnings=0"
@@ -13,13 +13,26 @@
13
13
  },
14
14
  "main": "dist/index.js",
15
15
  "types": "dist/index.d.ts",
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "fixtures",
20
+ "ci.build.sh",
21
+ "ci.startup.sh",
22
+ "env.debug.sh",
23
+ "env.provision.sh",
24
+ "env.run.sh",
25
+ "set-env.sh",
26
+ "env.Dockerfile",
27
+ "env.Dockerfile.dockerignore"
28
+ ],
16
29
  "license": "MIT",
17
30
  "repository": {
18
31
  "type": "git",
19
32
  "url": "git+https://github.com/Jahia/jahia-cypress.git"
20
33
  },
21
34
  "devDependencies": {
22
- "@chachalog/types": "^0.5.0",
35
+ "@chachalog/types": "^0.5.2",
23
36
  "@jahia/eslint-config": "^2.2.0",
24
37
  "@typescript-eslint/eslint-plugin": "^8.57.1",
25
38
  "@typescript-eslint/parser": "^8.57.1",
@@ -32,6 +45,7 @@
32
45
  "eslint-plugin-react": "^7.32.2",
33
46
  "eslint-plugin-react-hooks": "^4.6.0",
34
47
  "mochawesome": "^6.3.1",
48
+ "pkg-pr-new": "^0.0.86",
35
49
  "typescript": "^5.9.3"
36
50
  },
37
51
  "dependencies": {
@@ -41,6 +55,5 @@
41
55
  "cypress-real-events": "^1.11.0",
42
56
  "graphql": "^15.5.0",
43
57
  "graphql-tag": "^2.11.0"
44
- },
45
- "packageManager": "yarn@4.12.0"
58
+ }
46
59
  }
@@ -0,0 +1,45 @@
1
+
2
+ // Groovy script to be used for logging test suite and test case start/end markers
3
+ const loggerScript = 'groovy/logger.groovy';
4
+ const delimeters = {spec: '='.repeat(20), test: '-'.repeat(20)};
5
+
6
+ /**
7
+ * Generates a marker for the beginning or end of a test suite.
8
+ * @param action - The action being performed (e.g., "Starting" or "Ending").
9
+ * @param name - The name of the test suite.
10
+ * @returns A formatted string representing the suite marker.
11
+ */
12
+ const specMarker = (action: string, name: string): string => `${delimeters.spec} ${action} ${name} ${delimeters.spec}`;
13
+
14
+ /**
15
+ * Generates a marker for the beginning or end of a test.
16
+ * @param action - The action being performed (e.g., "Starting" or "Ending").
17
+ * @param title - The title of the test.
18
+ * @returns A formatted string representing the test marker.
19
+ */
20
+ const testMarker = (action: string, title: string): string => `${delimeters.test} ${action} ${title} ${delimeters.test}`;
21
+
22
+ /**
23
+ * Enables logging markers for the start and end of test suites and individual tests.
24
+ * This function sets up hooks to log messages before and after each test and suite execution.
25
+ * It uses a Groovy script to log the messages, which can be useful for tracking test execution in Jahia logs.
26
+ */
27
+ const enableSpecsMarker = (): void => {
28
+ before(() => {
29
+ cy.executeGroovy(loggerScript, {MESSAGE: specMarker('[BEGIN SPEC]', Cypress.spec.name)});
30
+ });
31
+
32
+ beforeEach(function () {
33
+ cy.executeGroovy(loggerScript, {MESSAGE: testMarker('[BEGIN TEST]', this.currentTest!.title)});
34
+ });
35
+
36
+ afterEach(function () {
37
+ cy.executeGroovy(loggerScript, {MESSAGE: testMarker('[END TEST]', this.currentTest!.title)});
38
+ });
39
+
40
+ after(() => {
41
+ cy.executeGroovy(loggerScript, {MESSAGE: specMarker('[END SPEC]', Cypress.spec.name)});
42
+ });
43
+ };
44
+
45
+ export const jahiaLog = {enableSpecsMarker};
@@ -8,6 +8,7 @@ import {step} from './testStep';
8
8
  import {jfaker} from './jfaker';
9
9
  import {modSince} from './modSince';
10
10
  import {collect as contextCollector} from './contextReporter';
11
+ import {jahiaLog} from './jahiaLog';
11
12
 
12
13
  export const registerSupport = (): void => {
13
14
  Cypress.Commands.add('apolloClient', apolloClient);
@@ -30,6 +31,7 @@ export const registerSupport = (): void => {
30
31
 
31
32
  // Register it.since()/describe.since()
32
33
  modSince.enable();
34
+ jahiaLog.enableSpecsMarker();
33
35
 
34
36
  /**
35
37
  * Override Cypress `type()` command to interpret special characters (e.g., {, }, etc.) either literally or as commands.
@@ -1,5 +1,13 @@
1
+ /**
2
+ * Grants one or more roles to a principal on a target node.
3
+ * @param {string} pathOrId JCR node path or identifier where roles are granted.
4
+ * @param {Array<string>} roleNames Role names to grant.
5
+ * @param {string} principalName Principal name (user or group) receiving roles.
6
+ * @param {string} principalType Principal type expected by the mutation.
7
+ * @returns {Cypress.Chainable} Cypress chainable for the GraphQL mutation request.
8
+ */
1
9
  export const grantRoles = (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string): Cypress.Chainable => {
2
- cy.log('Grant role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
10
+ cy.log(`Grant role(s) ${roleNames} with principal type ${principalType} to ${principalName} on node ${pathOrId}`);
3
11
  return cy.apollo({
4
12
  variables: {
5
13
  pathOrId: pathOrId,
@@ -11,8 +19,16 @@ export const grantRoles = (pathOrId: string, roleNames: Array<string>, principal
11
19
  });
12
20
  };
13
21
 
22
+ /**
23
+ * Revokes one or more roles from a principal on a target node.
24
+ * @param {string} pathOrId JCR node path or identifier where roles are revoked.
25
+ * @param {Array<string>} roleNames Role names to revoke.
26
+ * @param {string} principalName Principal name (user or group) losing roles.
27
+ * @param {string} principalType Principal type expected by the mutation.
28
+ * @returns {Cypress.Chainable} Cypress chainable for the GraphQL mutation request.
29
+ */
14
30
  export const revokeRoles = (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string): Cypress.Chainable => {
15
- cy.log('Revoke role(s) ' + roleNames + ' with principal type ' + principalType + ' to ' + principalName + ' on node ' + pathOrId);
31
+ cy.log(`Revoke role(s) ${roleNames} with principal type ${principalType} to ${principalName} on node ${pathOrId}`);
16
32
  return cy.apollo({
17
33
  variables: {
18
34
  pathOrId: pathOrId,
@@ -24,21 +40,35 @@ export const revokeRoles = (pathOrId: string, roleNames: Array<string>, principa
24
40
  });
25
41
  };
26
42
 
27
- export const createUser = (userName: string, password: string, properties: {
28
- name: string,
29
- value: string
30
- }[] = []): void => {
43
+ /**
44
+ * Creates a Jahia user using the Groovy fixture.
45
+ * @param {string} userName Username of the user to create.
46
+ * @param {string} password Password for the new user. Defaults to "password" when empty.
47
+ * @param {{name: string, value: string}[]} properties Optional user properties to set on creation.
48
+ * @param {string} siteKey Optional site key for site-scoped user creation.
49
+ * @returns {void}
50
+ */
51
+ export const createUser = (userName: string, password: string, properties: {name: string, value: string}[] = [], siteKey = ''): void => {
52
+ cy.log(`Creating ${siteKey === '' ? 'server-level ' : ('site-level:' + siteKey)} user with name ${userName}`);
31
53
  const userProperties = properties.map(property => {
32
54
  return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
33
55
  });
34
56
  cy.executeGroovy('groovy/admin/createUser.groovy', {
35
- USER_NAME: userName,
57
+ USERNAME: userName,
36
58
  PASSWORD: password ? password : 'password',
37
- USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
59
+ USER_PROPERTIES: userProperties ? userProperties.join('\n') : '',
60
+ SITEKEY: siteKey
38
61
  });
39
62
  };
40
63
 
64
+ /**
65
+ * Retrieves the JCR path of a user.
66
+ * @param {string} username Username to look up.
67
+ * @param {string} siteKey Optional site key for site-scoped users.
68
+ * @returns {Cypress.Chainable} Cypress chainable containing the GraphQL query response.
69
+ */
41
70
  export const getUserPath = (username: string, siteKey = ''): Cypress.Chainable => {
71
+ cy.log(`Getting user path for ${username}`);
42
72
  return cy.apollo({
43
73
  variables: {
44
74
  siteKey,
@@ -49,13 +79,27 @@ export const getUserPath = (username: string, siteKey = ''): Cypress.Chainable =
49
79
  );
50
80
  };
51
81
 
82
+ /**
83
+ * Deletes a Jahia user using the Groovy fixture.
84
+ * @param {string} userName Username of the user to delete.
85
+ * @returns {void}
86
+ */
52
87
  export const deleteUser = (userName: string): void => {
88
+ cy.log(`Deleting user ${userName}`);
53
89
  cy.executeGroovy('groovy/admin/deleteUser.groovy', {
54
- USER_NAME: userName
90
+ USERNAME: userName
55
91
  });
56
92
  };
57
93
 
94
+ /**
95
+ * Creates a Jahia users group using the Groovy fixture.
96
+ * @param {string} groupName Group name to create.
97
+ * @param {boolean} hidden Whether the group should be hidden.
98
+ * @param {string} siteKey Optional site key for site-scoped group creation.
99
+ * @returns {void}
100
+ */
58
101
  export const createGroup = (groupName: string, hidden?: boolean, siteKey = ''): void => {
102
+ cy.log(`Creating ${siteKey === '' ? 'server-level' : ('site-level:' + siteKey)} group ${groupName}`);
59
103
  cy.executeGroovy('groovy/admin/userGroupHelper.groovy', {
60
104
  OPERATION: 'create',
61
105
  GROUPNAME: groupName,
@@ -64,7 +108,14 @@ export const createGroup = (groupName: string, hidden?: boolean, siteKey = ''):
64
108
  });
65
109
  };
66
110
 
111
+ /**
112
+ * Deletes a Jahia users group using the Groovy fixture.
113
+ * @param {string} groupName Group name to delete.
114
+ * @param {string} siteKey Optional site key for site-scoped group deletion.
115
+ * @returns {void}
116
+ */
67
117
  export const deleteGroup = (groupName: string, siteKey = ''): void => {
118
+ cy.log(`Deleting ${siteKey === '' ? 'server-level' : ('site-level:' + siteKey)} group ${groupName}`);
68
119
  cy.executeGroovy('groovy/admin/userGroupHelper.groovy', {
69
120
  OPERATION: 'delete',
70
121
  GROUPNAME: groupName,
@@ -72,10 +123,18 @@ export const deleteGroup = (groupName: string, siteKey = ''): void => {
72
123
  });
73
124
  };
74
125
 
75
- export const addUserToGroup = (userName: string, groupName: string, siteKey?: string): void => {
126
+ /**
127
+ * Adds an existing user to a group using the Groovy fixture.
128
+ * @param {string} userName Username to add to the group.
129
+ * @param {string} groupName Group receiving the user.
130
+ * @param {string} siteKey Optional site key for site-scoped group membership.
131
+ * @returns {void}
132
+ */
133
+ export const addUserToGroup = (userName: string, groupName: string, siteKey = ''): void => {
134
+ cy.log(`Add user ${userName} to ${siteKey === '' ? 'server-level' : ('site-level:' + siteKey)} group ${groupName}`);
76
135
  cy.executeGroovy('groovy/admin/addUserToGroup.groovy', {
77
- USER_NAME: userName,
78
- GROUP_NAME: groupName,
79
- SITE_KEY: siteKey ? `"${siteKey}"` : 'null'
136
+ USERNAME: userName,
137
+ GROUPNAME: groupName,
138
+ SITEKEY: siteKey
80
139
  });
81
140
  };