@jahia/cypress 3.0.0 → 3.2.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.
@@ -1,6 +1,7 @@
1
1
  export declare const setNodeProperty: (pathOrId: string, property: string, value: string, language: string) => Cypress.Chainable;
2
2
  export declare const deleteNode: (pathOrId: string) => Cypress.Chainable;
3
3
  export declare const grantRoles: (pathOrId: string, roleNames: Array<string>, principalName: string, principalType: string) => Cypress.Chainable;
4
+ export declare const publishAndWaitJobEnding: (path: string, languages?: string[]) => void;
4
5
  export declare const waitAllJobsFinished: (errorMessage?: string, timeout?: number) => void;
5
6
  export declare const addNode: (variables: {
6
7
  parentPathOrId: string;
@@ -10,3 +11,10 @@ export declare const addNode: (variables: {
10
11
  children?: any[];
11
12
  }) => Cypress.Chainable;
12
13
  export declare const getNodeByPath: (path: string) => Cypress.Chainable;
14
+ export declare const createSite: (siteKey: string, templateSet?: string, serverName?: string, locale?: string, languages?: string) => void;
15
+ export declare const deleteSite: (siteKey: string) => void;
16
+ export declare const createUser: (userName: string, password: string, properties?: {
17
+ name: string;
18
+ value: string;
19
+ }[]) => void;
20
+ export declare const deleteUser: (userName: string) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.getNodeByPath = exports.addNode = exports.waitAllJobsFinished = exports.grantRoles = exports.deleteNode = exports.setNodeProperty = void 0;
3
+ exports.deleteUser = exports.createUser = exports.deleteSite = exports.createSite = exports.getNodeByPath = exports.addNode = exports.waitAllJobsFinished = exports.publishAndWaitJobEnding = exports.grantRoles = exports.deleteNode = exports.setNodeProperty = void 0;
4
4
  var setNodeProperty = function (pathOrId, property, value, language) {
5
5
  return cy.apollo({
6
6
  variables: {
@@ -35,6 +35,20 @@ var grantRoles = function (pathOrId, roleNames, principalName, principalType) {
35
35
  });
36
36
  };
37
37
  exports.grantRoles = grantRoles;
38
+ var publishAndWaitJobEnding = function (path, languages) {
39
+ if (languages === void 0) { languages = ['en']; }
40
+ cy.apollo({
41
+ variables: {
42
+ pathOrId: path,
43
+ languages: languages,
44
+ publishSubNodes: true,
45
+ includeSubTree: true
46
+ },
47
+ mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
48
+ });
49
+ exports.waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
50
+ };
51
+ exports.publishAndWaitJobEnding = publishAndWaitJobEnding;
38
52
  var waitAllJobsFinished = function (errorMessage, timeout) {
39
53
  if (timeout === void 0) { timeout = 60000; }
40
54
  cy.waitUntil(function () {
@@ -77,3 +91,38 @@ var getNodeByPath = function (path) {
77
91
  });
78
92
  };
79
93
  exports.getNodeByPath = getNodeByPath;
94
+ var createSite = function (siteKey, templateSet, serverName, locale, languages) {
95
+ var definedLocale = locale ? locale : 'en';
96
+ cy.executeGroovy('groovy/admin/createSite.groovy', {
97
+ SITEKEY: siteKey,
98
+ TEMPLATES_SET: templateSet ? templateSet : 'dx-base-demo-templates',
99
+ SERVERNAME: serverName ? serverName : 'localhost',
100
+ LOCALE: definedLocale,
101
+ LANGUAGES: languages ? "Arrays.asList(" + languages + ")" : "Arrays.asList(\"" + definedLocale + "\")"
102
+ });
103
+ };
104
+ exports.createSite = createSite;
105
+ var deleteSite = function (siteKey) {
106
+ cy.executeGroovy('groovy/admin/deleteSite.groovy', {
107
+ SITEKEY: siteKey
108
+ });
109
+ };
110
+ exports.deleteSite = deleteSite;
111
+ var createUser = function (userName, password, properties) {
112
+ if (properties === void 0) { properties = []; }
113
+ var userProperties = properties.map(function (property) {
114
+ return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
115
+ });
116
+ cy.executeGroovy('groovy/admin/createUser.groovy', {
117
+ USER_NAME: userName,
118
+ PASSWORD: password ? password : 'password',
119
+ USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
120
+ });
121
+ };
122
+ exports.createUser = createUser;
123
+ var deleteUser = function (userName) {
124
+ cy.executeGroovy('groovy/admin/deleteUser.groovy', {
125
+ USER_NAME: userName
126
+ });
127
+ };
128
+ exports.deleteUser = deleteUser;
@@ -0,0 +1,7 @@
1
+ mutation publishNode($pathOrId: String!, $languages: [String]!, $publishSubNodes: Boolean!, $includeSubTree: Boolean!) {
2
+ jcr(workspace: EDIT) {
3
+ mutateNode(pathOrId: $pathOrId) {
4
+ publish(publishSubNodes: $publishSubNodes, languages: $languages, includeSubTree: $includeSubTree)
5
+ }
6
+ }
7
+ }
@@ -1,14 +1,25 @@
1
+ import org.jahia.api.Constants
2
+ import org.jahia.services.content.JCRTemplate
3
+ import org.jahia.services.content.decorator.JCRSiteNode
1
4
  import org.jahia.services.sites.JahiaSite
2
5
  import org.jahia.services.sites.JahiaSitesService
3
6
  import org.jahia.services.sites.SiteCreationInfo
7
+ import org.jahia.services.usermanager.JahiaUserManagerService
4
8
 
5
9
  JahiaSitesService sitesService = JahiaSitesService.getInstance();
6
10
  if (sitesService.getSiteByKey("SITEKEY") == null) {
7
11
  JahiaSite site = sitesService.addSite(SiteCreationInfo.builder().
8
12
  siteKey("SITEKEY").
9
- serverName("localhost").
13
+ serverName("SERVERNAME").
10
14
  title("SITEKEY").
11
15
  templateSet("TEMPLATES_SET").
12
- locale("en").build())
13
- }
16
+ locale("LOCALE").build())
14
17
 
18
+ JCRTemplate.instance.doExecuteWithSystemSessionAsUser(JahiaUserManagerService.instance.lookupUser("root").jahiaUser,
19
+ Constants.EDIT_WORKSPACE, Locale.ENGLISH, jcrsession -> {
20
+ JCRSiteNode siteByKey = sitesService.getSiteByKey("SITEKEY", jcrsession)
21
+ siteByKey.setLanguages(new HashSet<String>(LANGUAGES))
22
+ jcrsession.save()
23
+ return null
24
+ })
25
+ }
@@ -0,0 +1,20 @@
1
+ import org.jahia.services.content.JCRCallback
2
+ import org.jahia.services.content.JCRSessionWrapper
3
+ import org.jahia.services.content.JCRTemplate
4
+ import org.jahia.services.usermanager.JahiaUserManagerService
5
+ import javax.jcr.RepositoryException
6
+
7
+ JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback() {
8
+ @Override
9
+ Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
10
+ log.info("Create user : USER_NAME")
11
+ JahiaUserManagerService userManagerService = JahiaUserManagerService.getInstance()
12
+
13
+ Properties properties = new Properties()
14
+ USER_PROPERTIES
15
+
16
+ userManagerService.createUser("USER_NAME", null, "PASSWORD", properties, session)
17
+ session.save()
18
+ return null
19
+ }
20
+ })
@@ -0,0 +1,17 @@
1
+ import org.jahia.services.content.JCRCallback
2
+ import org.jahia.services.content.JCRSessionWrapper
3
+ import org.jahia.services.content.JCRTemplate
4
+ import org.jahia.services.usermanager.JahiaUserManagerService
5
+ import javax.jcr.RepositoryException
6
+
7
+ JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback() {
8
+ @Override
9
+ Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
10
+ log.info("Delete user : USER_NAME" );
11
+
12
+ JahiaUserManagerService userManagerService = JahiaUserManagerService.getInstance();
13
+ userManagerService.deleteUser(userManagerService.getUserPath("USER_NAME"), session);
14
+ session.save();
15
+ return null;
16
+ }
17
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts"
@@ -32,6 +32,19 @@ export const grantRoles = (pathOrId: string, roleNames: Array<string>, principal
32
32
  });
33
33
  };
34
34
 
35
+ export const publishAndWaitJobEnding = (path: string, languages: string[] = ['en']): void => {
36
+ cy.apollo({
37
+ variables: {
38
+ pathOrId: path,
39
+ languages: languages,
40
+ publishSubNodes: true,
41
+ includeSubTree: true
42
+ },
43
+ mutationFile: 'graphql/jcr/mutation/publishNode.graphql'
44
+ });
45
+ waitAllJobsFinished('Publication timeout for node: ' + path, 60000);
46
+ };
47
+
35
48
  export const waitAllJobsFinished = (errorMessage?: string, timeout = 60000): void => {
36
49
  cy.waitUntil(
37
50
  () =>
@@ -58,7 +71,7 @@ export const waitAllJobsFinished = (errorMessage?: string, timeout = 60000): voi
58
71
  cy.wait(2000);
59
72
  };
60
73
 
61
- export const addNode = (variables: {parentPathOrId: string, primaryNodeType: string, name: string, properties?: any[], children?: any[]}): Cypress.Chainable => {
74
+ export const addNode = (variables: { parentPathOrId: string, primaryNodeType: string, name: string, properties?: any[], children?: any[] }): Cypress.Chainable => {
62
75
  return cy.apollo({
63
76
  variables: variables,
64
77
  mutationFile: 'graphql/jcr/mutation/addNode.graphql'
@@ -73,3 +86,37 @@ export const getNodeByPath = (path: string): Cypress.Chainable => {
73
86
  queryFile: 'graphql/jcr/query/getNodeByPath.graphql'
74
87
  });
75
88
  };
89
+
90
+ export const createSite = (siteKey: string, templateSet?: string, serverName?: string, locale?: string, languages?: string): void => {
91
+ const definedLocale = locale ? locale : 'en';
92
+ cy.executeGroovy('groovy/admin/createSite.groovy', {
93
+ SITEKEY: siteKey,
94
+ TEMPLATES_SET: templateSet ? templateSet : 'dx-base-demo-templates',
95
+ SERVERNAME: serverName ? serverName : 'localhost',
96
+ LOCALE: definedLocale,
97
+ LANGUAGES: languages ? `Arrays.asList(${languages})` : `Arrays.asList("${definedLocale}")`
98
+ });
99
+ };
100
+
101
+ export const deleteSite = (siteKey: string): void => {
102
+ cy.executeGroovy('groovy/admin/deleteSite.groovy', {
103
+ SITEKEY: siteKey
104
+ });
105
+ };
106
+
107
+ export const createUser = (userName: string, password: string, properties: { name: string, value: string }[] = []): void => {
108
+ const userProperties = properties.map(property => {
109
+ return 'properties.setProperty("' + property.name + '", "' + property.value + '")';
110
+ });
111
+ cy.executeGroovy('groovy/admin/createUser.groovy', {
112
+ USER_NAME: userName,
113
+ PASSWORD: password ? password : 'password',
114
+ USER_PROPERTIES: userProperties ? userProperties.join('\n') : ''
115
+ });
116
+ };
117
+
118
+ export const deleteUser = (userName: string): void => {
119
+ cy.executeGroovy('groovy/admin/deleteUser.groovy', {
120
+ USER_NAME: userName
121
+ });
122
+ };