From 7c3645d099000263fe17d784e465178964805059 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 22 Oct 2024 19:26:51 +0530 Subject: [PATCH 1/8] add delay for branch and term creation --- test/sanity-check/api/branch-test.js | 22 ++++------ test/sanity-check/api/taxonomy-test.js | 3 +- test/sanity-check/api/terms-test.js | 57 ++++++++++---------------- 3 files changed, 33 insertions(+), 49 deletions(-) diff --git a/test/sanity-check/api/branch-test.js b/test/sanity-check/api/branch-test.js index 57491802..147fcd0d 100644 --- a/test/sanity-check/api/branch-test.js +++ b/test/sanity-check/api/branch-test.js @@ -12,19 +12,15 @@ describe('Branch api Test', () => { client = contentstackClient(user.authtoken) }) - it('should create a dev branch from stage branch', done => { - makeBranch() - .create({ branch: devBranch }) - .then((response) => { - expect(response.uid).to.be.equal(devBranch.uid) - expect(response.source).to.be.equal(devBranch.source) - expect(response.alias).to.not.equal(undefined) - expect(response.delete).to.not.equal(undefined) - expect(response.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) + it('should create a dev branch from stage branch',async () => { + const response = await makeBranch().create({ branch: devBranch }); + expect(response.uid).to.be.equal(devBranch.uid); + expect(response.source).to.be.equal(devBranch.source); + expect(response.alias).to.not.equal(undefined); + expect(response.delete).to.not.equal(undefined); + expect(response.fetch).to.not.equal(undefined); + await new Promise(resolve => setTimeout(resolve, 15000)); + }); it('should return main branch when query is called', done => { makeBranch() diff --git a/test/sanity-check/api/taxonomy-test.js b/test/sanity-check/api/taxonomy-test.js index 7493c27f..cce95eb4 100644 --- a/test/sanity-check/api/taxonomy-test.js +++ b/test/sanity-check/api/taxonomy-test.js @@ -32,7 +32,7 @@ describe('taxonomy api Test', () => { .catch(done) }) - it('should fetch taxonomy of the uid passe', done => { + it('should fetch taxonomy of the uid passed', done => { makeTaxonomy(taxonomyUID) .fetch() .then((taxonomyResponse) => { @@ -51,6 +51,7 @@ describe('taxonomy api Test', () => { return taxonomyResponse.update() }) .then((taxonomyResponse) => { + console.log("🚀 ~ .then ~ taxonomyResponse:", taxonomyResponse) expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) expect(taxonomyResponse.name).to.be.equal('Updated Name') done() diff --git a/test/sanity-check/api/terms-test.js b/test/sanity-check/api/terms-test.js index 16e782e7..097ab370 100644 --- a/test/sanity-check/api/terms-test.js +++ b/test/sanity-check/api/terms-test.js @@ -44,31 +44,22 @@ describe('Terms API Test', () => { await client.stack({ api_key: process.env.API_KEY }).taxonomy().create({ taxonomy }) }, 10000) - it('should create term', done => { - makeTerms(taxonomy.uid).create(term) - .then((response) => { - expect(response.uid).to.be.equal(term.term.uid) - done() - }) - .catch(done) + it('should create term', async () => { + const response = await makeTerms(taxonomy.uid).create(term) + expect(response.uid).to.be.equal(term.term.uid) + await new Promise(resolve => setTimeout(resolve, 15000)); }) - it('should create child term 1', done => { - makeTerms(taxonomy.uid).create(childTerm1) - .then((response) => { - expect(response.uid).to.be.equal(childTerm1.term.uid) - done() - }) - .catch(done) + it('should create child term 1', async () => { + const response = await makeTerms(taxonomy.uid).create(childTerm1) + expect(response.uid).to.be.equal(childTerm1.term.uid) + await new Promise(resolve => setTimeout(resolve, 15000)); }) - it('should create child term 2', done => { - makeTerms(taxonomy.uid).create(childTerm2) - .then((response) => { - expect(response.uid).to.be.equal(childTerm2.term.uid) - done() - }) - .catch(done) + it('should create child term 2', async () => { + const response = await makeTerms(taxonomy.uid).create(childTerm2) + expect(response.uid).to.be.equal(childTerm2.term.uid) + await new Promise(resolve => setTimeout(resolve, 15000)); }) it('should query and get all terms', done => { @@ -180,20 +171,16 @@ describe('Branch creation api Test', () => { client = contentstackClient(user.authtoken) }) - it('should create staging branch', done => { - makeBranch() - .create({ branch: stageBranch }) - .then((response) => { - expect(response.uid).to.be.equal(stageBranch.uid) - expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`) - expect(response.source).to.be.equal(stageBranch.source) - expect(response.alias).to.not.equal(undefined) - expect(response.delete).to.not.equal(undefined) - expect(response.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) + it('should create staging branch', async () => { + const response = await makeBranch().create({ branch: stageBranch }); + expect(response.uid).to.be.equal(stageBranch.uid); + expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`); + expect(response.source).to.be.equal(stageBranch.source); + expect(response.alias).to.not.equal(undefined); + expect(response.fetch).to.not.equal(undefined); + expect(response.delete).to.not.equal(undefined); + await new Promise(resolve => setTimeout(resolve, 15000)); + }); }) function makeBranch (uid = null) { From dd28851a1f4ca2945bac530e788e4584b1f91873 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Wed, 23 Oct 2024 10:29:23 +0530 Subject: [PATCH 2/8] removed console.log --- test/sanity-check/api/taxonomy-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/sanity-check/api/taxonomy-test.js b/test/sanity-check/api/taxonomy-test.js index cce95eb4..4ce676a0 100644 --- a/test/sanity-check/api/taxonomy-test.js +++ b/test/sanity-check/api/taxonomy-test.js @@ -51,7 +51,6 @@ describe('taxonomy api Test', () => { return taxonomyResponse.update() }) .then((taxonomyResponse) => { - console.log("🚀 ~ .then ~ taxonomyResponse:", taxonomyResponse) expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) expect(taxonomyResponse.name).to.be.equal('Updated Name') done() From ec355a9212cf0682e1e578043f81706f772f9532 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 18 Nov 2024 14:55:38 +0530 Subject: [PATCH 3/8] updated with new format of slack notification --- sanity-report-dev11.js | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sanity-report-dev11.js diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js new file mode 100644 index 00000000..d50bcb59 --- /dev/null +++ b/sanity-report-dev11.js @@ -0,0 +1,55 @@ +import dotenv from "dotenv"; +import fs from "fs"; + +dotenv.config(); + +const mochawesomeJsonOutput = fs.readFileSync( + "./mochawesome-report/mochawesome.json", + "utf-8" +); +const mochawesomeReport = JSON.parse(mochawesomeJsonOutput); + +const totalTests = mochawesomeReport.stats.tests; +const passedTests = mochawesomeReport.stats.passes; +const failedTests = mochawesomeReport.stats.failures; + +const resultMessage = + passedTests === totalTests + ? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)` + : `:x: Failure (${passedTests} / ${totalTests} Passed)`; + +const slackMessage = { + text: ` + *Dev11, CMA SDK Full Sanity* + Result: ${resultMessage} + Failed Tests: ${failedTests} + View Report: + `, +}; + +const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; + +const sendSlackMessage = async (message) => { + const payload = { + text: message, + }; + + try { + const response = await fetch(slackWebhookUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), + }); + + if (!response.ok) { + throw new Error(`Error sending message to Slack: ${response.statusText}`); + } + + console.log("Message sent to Slack successfully"); + } catch (error) { + console.error("Error:", error); + } +}; +sendSlackMessage(slackMessage.text); From f232876de61a4b56f1c05dcf888ed722e9d71ce6 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 18 Nov 2024 19:36:58 +0530 Subject: [PATCH 4/8] updated to provide report link and indentation --- sanity-report-dev11.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js index d50bcb59..eaef6c41 100644 --- a/sanity-report-dev11.js +++ b/sanity-report-dev11.js @@ -18,13 +18,17 @@ const resultMessage = ? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)` : `:x: Failure (${passedTests} / ${totalTests} Passed)`; +const pipelineName = process.env.GOCD_PIPELINE_NAME; +const buildNumber = process.env.GOCD_PIPELINE_LABEL; +const goCdServer = process.env.GOCD_SERVER; + +const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${buildNumber}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html`; + const slackMessage = { - text: ` - *Dev11, CMA SDK Full Sanity* - Result: ${resultMessage} - Failed Tests: ${failedTests} - View Report: - `, + text: `Dev11, CMA SDK Full Sanity +*Result:* ${resultMessage} +*Failed Tests:* ${failedTests} +<${reportUrl}|View Report>`, }; const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; From 39ddce039582d32e0ed209debfc021830c19513f Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 19 Nov 2024 10:53:50 +0530 Subject: [PATCH 5/8] change envs for slack notification --- sanity-report-dev11.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js index eaef6c41..acae2237 100644 --- a/sanity-report-dev11.js +++ b/sanity-report-dev11.js @@ -18,11 +18,11 @@ const resultMessage = ? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)` : `:x: Failure (${passedTests} / ${totalTests} Passed)`; -const pipelineName = process.env.GOCD_PIPELINE_NAME; -const buildNumber = process.env.GOCD_PIPELINE_LABEL; +const pipelineName = process.env.GO_PIPELINE_NAME; +const pipelineCounter = process.env.GO_PIPELINE_COUNTER; const goCdServer = process.env.GOCD_SERVER; -const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${buildNumber}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html`; +const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCounter}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html`; const slackMessage = { text: `Dev11, CMA SDK Full Sanity From 2c7010302af48cc52d9b3efba9c7b21466651592 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 19 Nov 2024 11:18:28 +0530 Subject: [PATCH 6/8] import update --- sanity-report-dev11.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js index acae2237..4fae04cd 100644 --- a/sanity-report-dev11.js +++ b/sanity-report-dev11.js @@ -1,5 +1,5 @@ -import dotenv from "dotenv"; -import fs from "fs"; +const dotenv = require("dotenv"); +const fs = require("fs"); dotenv.config(); From f5f7543928175889b33007ada832cabfdbb6bd4a Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 19 Nov 2024 17:20:12 +0530 Subject: [PATCH 7/8] update notification with time stamp --- sanity-report-dev11.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js index 4fae04cd..5a2c1753 100644 --- a/sanity-report-dev11.js +++ b/sanity-report-dev11.js @@ -13,6 +13,10 @@ const totalTests = mochawesomeReport.stats.tests; const passedTests = mochawesomeReport.stats.passes; const failedTests = mochawesomeReport.stats.failures; +let durationInSeconds = Math.floor(mochawesomeReport.stats.duration / 1000) +const durationInMinutes = Math.floor(durationInSeconds / 60) +durationInSeconds %= 60 + const resultMessage = passedTests === totalTests ? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)` @@ -26,7 +30,7 @@ const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCount const slackMessage = { text: `Dev11, CMA SDK Full Sanity -*Result:* ${resultMessage} +*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s *Failed Tests:* ${failedTests} <${reportUrl}|View Report>`, }; From 7e7c15ee5ff4c03219fb1b402a831bb8e544ff6e Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Wed, 11 Dec 2024 12:08:50 +0530 Subject: [PATCH 8/8] updated management token expiry value --- test/sanity-check/mock/managementToken.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sanity-check/mock/managementToken.js b/test/sanity-check/mock/managementToken.js index f229b16e..5511d079 100644 --- a/test/sanity-check/mock/managementToken.js +++ b/test/sanity-check/mock/managementToken.js @@ -29,7 +29,7 @@ const createManagementToken = { } } ], - expires_on: '2024-12-10', + expires_on: '2025-12-10', is_email_notification_enabled: true } } @@ -64,7 +64,7 @@ const createManagementToken2 = { } } ], - expires_on: '2024-12-10', + expires_on: '2025-12-10', is_email_notification_enabled: true } }