From 9847d8799add9b0ab812b02b1211d6ac043a655d Mon Sep 17 00:00:00 2001 From: Francois G Date: Thu, 13 Jun 2024 17:17:09 +0200 Subject: [PATCH] TECH-1844: Added a method to wait until SAM returns green (#74) --- fixtures/graphql/sam/healthStatus.graphql | 12 ++++++++++++ package.json | 2 +- src/utils/SAMHelper.ts | 22 ++++++++++++++++++++++ src/utils/index.ts | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 fixtures/graphql/sam/healthStatus.graphql create mode 100644 src/utils/SAMHelper.ts diff --git a/fixtures/graphql/sam/healthStatus.graphql b/fixtures/graphql/sam/healthStatus.graphql new file mode 100644 index 0000000..c1983c2 --- /dev/null +++ b/fixtures/graphql/sam/healthStatus.graphql @@ -0,0 +1,12 @@ +query($severity: GqlProbeSeverity) { + admin { + jahia { + healthCheck(severity: $severity) { + status { + health + message + } + } + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index d7c4427..c7532ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jahia/cypress", - "version": "3.19.4", + "version": "3.20.0", "scripts": { "build": "tsc", "lint": "eslint src -c .eslintrc.json --ext .ts" diff --git a/src/utils/SAMHelper.ts b/src/utils/SAMHelper.ts new file mode 100644 index 0000000..c067d20 --- /dev/null +++ b/src/utils/SAMHelper.ts @@ -0,0 +1,22 @@ +export const waitUntilSAMStatusGreen = (severity = 'MEDIUM', timeout = 60000, interval = 1000) : void => { + cy.waitUntil(() => + cy.apollo({ + fetchPolicy: 'no-cache', + queryFile: 'graphql/sam/healthStatus.graphql', + variables: { + severity: severity + } + }).then(result => { + const healthStatus = result?.data?.admin?.jahia?.healthCheck?.status; + if (healthStatus) { + return healthStatus.health === 'GREEN'; + } + }), + { + errorMsg: `Timeout waiting for SAM to be green for severity: ${severity}`, + timeout: timeout, + verbose: true, + interval: interval + }); +}; + diff --git a/src/utils/index.ts b/src/utils/index.ts index ed5758f..3634570 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -6,3 +6,4 @@ export * from './VanityUrlHelper'; export * from './ClusterHelper'; export * from './JahiaPlatformHelper'; export * from './GraphQLHelper'; +export * from './SAMHelper';