@jahia/cypress 3.20.1 → 3.21.1

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,19 +1,21 @@
1
1
  /// <reference types="cypress" />
2
2
  import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core';
3
- interface AuthMethod {
3
+ interface HostConfig {
4
4
  token?: string;
5
5
  username?: string;
6
6
  password?: string;
7
+ url?: string;
7
8
  }
8
9
  declare global {
9
10
  namespace Cypress {
10
11
  interface Chainable<Subject> {
11
- apolloClient(authMethod?: AuthMethod): Chainable<ApolloClient<NormalizedCacheObject>>;
12
+ apolloClient(config?: HostConfig): Chainable<ApolloClient<NormalizedCacheObject>>;
12
13
  }
13
14
  }
14
15
  }
15
16
  export declare type ApolloClientOptions = Cypress.Loggable & {
16
17
  setCurrentApolloClient: boolean;
17
18
  };
18
- export declare const apolloClient: (authMethod?: AuthMethod, options?: ApolloClientOptions) => void;
19
+ export declare const switchApolloClient: (config?: HostConfig, options?: ApolloClientOptions) => void;
20
+ export declare const apolloClient: (config?: HostConfig, options?: ApolloClientOptions) => void;
19
21
  export {};
@@ -1,24 +1,36 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.apolloClient = void 0;
3
+ exports.apolloClient = exports.switchApolloClient = void 0;
4
4
  var core_1 = require("@apollo/client/core");
5
5
  var links_1 = require("./links");
6
- var apolloClient = function (authMethod, options) {
6
+ var switchApolloClient = function (config, options) {
7
+ if (config === void 0) { config = { url: Cypress.config().baseUrl }; }
8
+ if (options === void 0) { options = {
9
+ log: true,
10
+ setCurrentApolloClient: true
11
+ }; }
12
+ // Switch context to apollo client
13
+ cy.visit(config.url, { failOnStatusCode: false });
14
+ return exports.apolloClient(config, options);
15
+ };
16
+ exports.switchApolloClient = switchApolloClient;
17
+ var apolloClient = function (config, options) {
18
+ if (config === void 0) { config = { url: Cypress.config().baseUrl }; }
7
19
  if (options === void 0) { options = {
8
20
  log: true,
9
21
  setCurrentApolloClient: true
10
22
  }; }
11
23
  var headers = {};
12
- if (authMethod === undefined) {
13
- headers.authorization = "Basic " + btoa('root:' + Cypress.env('SUPER_USER_PASSWORD'));
24
+ if (config.token !== undefined) {
25
+ headers.authorization = "APIToken " + config.token;
14
26
  }
15
- else if (authMethod.token !== undefined) {
16
- headers.authorization = "APIToken " + authMethod.token;
27
+ else if (config.username !== undefined && config.password !== undefined) {
28
+ headers.authorization = "Basic " + btoa(config.username + ':' + config.password);
17
29
  }
18
- else if (authMethod.username !== undefined && authMethod.password !== undefined) {
19
- headers.authorization = "Basic " + btoa(authMethod.username + ':' + authMethod.password);
30
+ else {
31
+ headers.authorization = "Basic " + btoa('root:' + Cypress.env('SUPER_USER_PASSWORD'));
20
32
  }
21
- var links = [links_1.uploadLink, links_1.formDataHttpLink(Cypress.config().baseUrl, headers)];
33
+ var links = [links_1.uploadLink, links_1.formDataHttpLink(config.url, headers)];
22
34
  var client = new core_1.ApolloClient({
23
35
  link: core_1.from(links),
24
36
  cache: new core_1.InMemoryCache(),
@@ -35,7 +47,7 @@ var apolloClient = function (authMethod, options) {
35
47
  message: 'Create new apollo client',
36
48
  consoleProps: function () {
37
49
  return {
38
- Auth: authMethod,
50
+ Config: config,
39
51
  Yielded: client
40
52
  };
41
53
  }
@@ -2,10 +2,10 @@
2
2
  declare global {
3
3
  namespace Cypress {
4
4
  interface Chainable<Subject> {
5
- login(username?: string, password?: string): Chainable<Cypress.Response<any>>;
6
- loginAndStoreSession(username?: string, password?: string): Chainable<Cypress.Response<any>>;
5
+ login(username?: string, password?: string, url?: string): Chainable<Cypress.Response<any>>;
6
+ loginAndStoreSession(username?: string, password?: string, url?: string): Chainable<Cypress.Response<any>>;
7
7
  }
8
8
  }
9
9
  }
10
- export declare const login: (username?: string, password?: string) => void;
11
- export declare const loginAndStoreSession: (username?: string, password?: string) => void;
10
+ export declare const login: (username?: string, password?: string, url?: string) => void;
11
+ export declare const loginAndStoreSession: (username?: string, password?: string, url?: string) => void;
@@ -3,9 +3,10 @@
3
3
  exports.__esModule = true;
4
4
  exports.loginAndStoreSession = exports.login = void 0;
5
5
  /// <reference types="cypress" />
6
- var login = function (username, password) {
6
+ var login = function (username, password, url) {
7
7
  if (username === void 0) { username = 'root'; }
8
8
  if (password === void 0) { password = Cypress.env('SUPER_USER_PASSWORD'); }
9
+ if (url === void 0) { url = '/cms/login'; }
9
10
  Cypress.log({
10
11
  name: 'login',
11
12
  message: "Login with " + username,
@@ -17,24 +18,25 @@ var login = function (username, password) {
17
18
  });
18
19
  cy.request({
19
20
  method: 'POST',
20
- url: '/cms/login',
21
21
  form: true,
22
22
  body: { username: username, password: password },
23
23
  followRedirect: false,
24
- log: false
24
+ log: false,
25
+ url: url
25
26
  }).then(function (res) {
26
27
  expect(res.status, 'Login result').to.eq(302);
27
28
  });
28
29
  };
29
30
  exports.login = login;
30
- var loginAndStoreSession = function (username, password) {
31
+ var loginAndStoreSession = function (username, password, url) {
31
32
  if (username === void 0) { username = 'root'; }
32
33
  if (password === void 0) { password = Cypress.env('SUPER_USER_PASSWORD'); }
34
+ if (url === void 0) { url = '/start'; }
33
35
  cy.session('session-' + username, function () {
34
36
  cy.login(username, password); // Edit in chief
35
37
  }, {
36
38
  validate: function () {
37
- cy.request('/start').its('status').should('eq', 200);
39
+ cy.request(url).its('status').should('eq', 200);
38
40
  }
39
41
  });
40
42
  };
@@ -1,12 +1,13 @@
1
+ import { JahiaServer } from '../support';
1
2
  export declare const createSite: (siteKey: string, config?: {
2
3
  languages?: string;
3
4
  templateSet: string;
4
5
  serverName: string;
5
6
  locale: string;
6
- }) => void;
7
- export declare const deleteSite: (siteKey: string) => void;
8
- export declare const enableModule: (moduleName: string, siteKey: string) => void;
7
+ }, jahiaServer?: JahiaServer) => void;
8
+ export declare const deleteSite: (siteKey: string, jahiaServer?: JahiaServer) => void;
9
+ export declare const enableModule: (moduleName: string, siteKey: string, jahiaServer?: JahiaServer) => void;
9
10
  export declare const disableModule: (moduleName: string, siteKey: string) => void;
10
11
  export declare const editSite: (siteKey: string, config?: {
11
12
  serverName: string;
12
- }) => void;
13
+ }, jahiaServer?: JahiaServer) => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
3
  exports.editSite = exports.disableModule = exports.enableModule = exports.deleteSite = exports.createSite = void 0;
4
- var createSite = function (siteKey, config) {
4
+ // eslint-disable-next-line default-param-last
5
+ var createSite = function (siteKey, config, jahiaServer) {
5
6
  if (config === void 0) { config = { templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en' }; }
6
7
  cy.executeGroovy('groovy/admin/createSite.groovy', {
7
8
  SITEKEY: siteKey,
@@ -9,20 +10,20 @@ var createSite = function (siteKey, config) {
9
10
  SERVERNAME: config.serverName,
10
11
  LOCALE: config.locale,
11
12
  LANGUAGES: config.languages || config.locale
12
- });
13
+ }, jahiaServer);
13
14
  };
14
15
  exports.createSite = createSite;
15
- var deleteSite = function (siteKey) {
16
+ var deleteSite = function (siteKey, jahiaServer) {
16
17
  cy.executeGroovy('groovy/admin/deleteSite.groovy', {
17
18
  SITEKEY: siteKey
18
- });
19
+ }, jahiaServer);
19
20
  };
20
21
  exports.deleteSite = deleteSite;
21
- var enableModule = function (moduleName, siteKey) {
22
+ var enableModule = function (moduleName, siteKey, jahiaServer) {
22
23
  cy.runProvisioningScript({
23
24
  fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
24
25
  type: 'application/yaml'
25
- });
26
+ }, undefined, jahiaServer);
26
27
  };
27
28
  exports.enableModule = enableModule;
28
29
  var disableModule = function (moduleName, siteKey) {
@@ -32,11 +33,12 @@ var disableModule = function (moduleName, siteKey) {
32
33
  });
33
34
  };
34
35
  exports.disableModule = disableModule;
35
- var editSite = function (siteKey, config) {
36
+ // eslint-disable-next-line default-param-last
37
+ var editSite = function (siteKey, config, jahiaServer) {
36
38
  if (config === void 0) { config = { serverName: 'localhost' }; }
37
39
  cy.executeGroovy('groovy/admin/editSite.groovy', {
38
40
  SITEKEY: siteKey,
39
41
  SERVERNAME: config.serverName
40
- });
42
+ }, jahiaServer);
41
43
  };
42
44
  exports.editSite = editSite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "3.20.1",
3
+ "version": "3.21.1",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts"
@@ -13,13 +13,14 @@ cy.apolloClient()
13
13
 
14
14
  ### Arguments
15
15
 
16
- #### &gt; auth (`AuthMethod`)
16
+ #### &gt; config (`HostConfig`)
17
17
 
18
- If no authorization is passed, will use root credentials. Otherwise :
18
+ If no authorization is passed, will use root credentials and cypress base url. Otherwise :
19
19
 
20
20
  - token: An API token
21
21
  - username
22
22
  - password
23
+ - url
23
24
 
24
25
  #### &gt; options (`ApolloClientOptions`)
25
26
 
@@ -1,10 +1,11 @@
1
1
  import {ApolloClient, from, InMemoryCache, NormalizedCacheObject} from '@apollo/client/core';
2
2
  import {formDataHttpLink, uploadLink} from './links';
3
3
 
4
- interface AuthMethod {
4
+ interface HostConfig {
5
5
  token?: string
6
6
  username?: string
7
- password?: string
7
+ password?: string,
8
+ url?: string
8
9
  }
9
10
 
10
11
  declare global {
@@ -12,7 +13,7 @@ declare global {
12
13
  namespace Cypress {
13
14
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
15
  interface Chainable<Subject> {
15
- apolloClient(authMethod?: AuthMethod): Chainable<ApolloClient<NormalizedCacheObject>>
16
+ apolloClient(config?: HostConfig): Chainable<ApolloClient<NormalizedCacheObject>>
16
17
  }
17
18
  }
18
19
  }
@@ -21,20 +22,29 @@ export type ApolloClientOptions = Cypress.Loggable & {
21
22
  setCurrentApolloClient: boolean
22
23
  }
23
24
 
24
- export const apolloClient = function (authMethod?: AuthMethod, options: ApolloClientOptions = {
25
+ export const switchApolloClient = function (config: HostConfig = {url: Cypress.config().baseUrl}, options: ApolloClientOptions = {
26
+ log: true,
27
+ setCurrentApolloClient: true
28
+ }): void {
29
+ // Switch context to apollo client
30
+ cy.visit(config.url, {failOnStatusCode: false});
31
+ return apolloClient(config, options);
32
+ };
33
+
34
+ export const apolloClient = function (config: HostConfig = {url: Cypress.config().baseUrl}, options: ApolloClientOptions = {
25
35
  log: true,
26
36
  setCurrentApolloClient: true
27
37
  }): void {
28
38
  const headers: { authorization?: string } = {};
29
- if (authMethod === undefined) {
39
+ if (config.token !== undefined) {
40
+ headers.authorization = `APIToken ${config.token}`;
41
+ } else if (config.username !== undefined && config.password !== undefined) {
42
+ headers.authorization = `Basic ${btoa(config.username + ':' + config.password)}`;
43
+ } else {
30
44
  headers.authorization = `Basic ${btoa('root:' + Cypress.env('SUPER_USER_PASSWORD'))}`;
31
- } else if (authMethod.token !== undefined) {
32
- headers.authorization = `APIToken ${authMethod.token}`;
33
- } else if (authMethod.username !== undefined && authMethod.password !== undefined) {
34
- headers.authorization = `Basic ${btoa(authMethod.username + ':' + authMethod.password)}`;
35
45
  }
36
46
 
37
- const links = [uploadLink, formDataHttpLink(Cypress.config().baseUrl, headers)];
47
+ const links = [uploadLink, formDataHttpLink(config.url, headers)];
38
48
 
39
49
  const client = new ApolloClient({
40
50
  link: from(links),
@@ -53,7 +63,7 @@ export const apolloClient = function (authMethod?: AuthMethod, options: ApolloCl
53
63
  message: 'Create new apollo client',
54
64
  consoleProps: () => {
55
65
  return {
56
- Auth: authMethod,
66
+ Config: config,
57
67
  Yielded: client
58
68
  };
59
69
  }
@@ -7,13 +7,13 @@ declare global {
7
7
  namespace Cypress {
8
8
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
9
  interface Chainable<Subject> {
10
- login(username?: string, password?: string): Chainable<Cypress.Response<any>>
11
- loginAndStoreSession(username?: string, password?: string): Chainable<Cypress.Response<any>>
10
+ login(username?: string, password?: string, url?: string): Chainable<Cypress.Response<any>>
11
+ loginAndStoreSession(username?: string, password?: string, url?: string): Chainable<Cypress.Response<any>>
12
12
  }
13
13
  }
14
14
  }
15
15
 
16
- export const login = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD')): void => {
16
+ export const login = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD'), url = '/cms/login'): void => {
17
17
  Cypress.log({
18
18
  name: 'login',
19
19
  message: `Login with ${username}`,
@@ -26,22 +26,22 @@ export const login = (username = 'root', password: string = Cypress.env('SUPER_U
26
26
 
27
27
  cy.request({
28
28
  method: 'POST',
29
- url: '/cms/login',
30
29
  form: true,
31
30
  body: {username, password},
32
31
  followRedirect: false,
33
- log: false
32
+ log: false,
33
+ url
34
34
  }).then(res => {
35
35
  expect(res.status, 'Login result').to.eq(302);
36
36
  });
37
37
  };
38
38
 
39
- export const loginAndStoreSession = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD')): void => {
39
+ export const loginAndStoreSession = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD'), url = '/start'): void => {
40
40
  cy.session('session-' + username, () => {
41
41
  cy.login(username, password); // Edit in chief
42
42
  }, {
43
43
  validate() {
44
- cy.request('/start').its('status').should('eq', 200);
44
+ cy.request(url).its('status').should('eq', 200);
45
45
  }
46
46
  });
47
47
  };
@@ -1,25 +1,27 @@
1
+ import {JahiaServer} from '../support';
1
2
 
2
- export const createSite = (siteKey: string, config: {languages?: string, templateSet: string, serverName: string, locale: string} = {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en'}): void => {
3
+ // eslint-disable-next-line default-param-last
4
+ export const createSite = (siteKey: string, config: {languages?: string, templateSet: string, serverName: string, locale: string} = {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en'}, jahiaServer?: JahiaServer): void => {
3
5
  cy.executeGroovy('groovy/admin/createSite.groovy', {
4
6
  SITEKEY: siteKey,
5
7
  TEMPLATES_SET: config.templateSet,
6
8
  SERVERNAME: config.serverName,
7
9
  LOCALE: config.locale,
8
10
  LANGUAGES: config.languages || config.locale
9
- });
11
+ }, jahiaServer);
10
12
  };
11
13
 
12
- export const deleteSite = (siteKey: string): void => {
14
+ export const deleteSite = (siteKey: string, jahiaServer?: JahiaServer): void => {
13
15
  cy.executeGroovy('groovy/admin/deleteSite.groovy', {
14
16
  SITEKEY: siteKey
15
- });
17
+ }, jahiaServer);
16
18
  };
17
19
 
18
- export const enableModule = (moduleName: string, siteKey: string): void => {
20
+ export const enableModule = (moduleName: string, siteKey: string, jahiaServer?: JahiaServer): void => {
19
21
  cy.runProvisioningScript({
20
22
  fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
21
23
  type: 'application/yaml'
22
- });
24
+ }, undefined, jahiaServer);
23
25
  };
24
26
 
25
27
  export const disableModule = (moduleName: string, siteKey: string): void => {
@@ -29,9 +31,10 @@ export const disableModule = (moduleName: string, siteKey: string): void => {
29
31
  });
30
32
  };
31
33
 
32
- export const editSite = (siteKey: string, config: {serverName: string} = {serverName: 'localhost'}): void => {
34
+ // eslint-disable-next-line default-param-last
35
+ export const editSite = (siteKey: string, config: {serverName: string} = {serverName: 'localhost'}, jahiaServer?: JahiaServer): void => {
33
36
  cy.executeGroovy('groovy/admin/editSite.groovy', {
34
37
  SITEKEY: siteKey,
35
38
  SERVERNAME: config.serverName
36
- });
39
+ }, jahiaServer);
37
40
  };