diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js new file mode 100644 index 00000000..b1c2a309 --- /dev/null +++ b/sanity-report-dev11.js @@ -0,0 +1,74 @@ +const dotenv = require("dotenv"); +const fs = require("fs"); + +dotenv.config(); + +const user1 = process.env.USER1; +const user2 = process.env.USER2; +const user3 = process.env.USER3; +const user4 = process.env.USER4; + +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; + +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)` + : `:x: Failure (${passedTests} / ${totalTests} Passed)`; + +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}/${pipelineCounter}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html`; + +let tagUsers = ``; +if (failedTests > 0) { + tagUsers = `<@${user1}> <@${user2}> <@${user3}> <@${user4}>`; +} + +const slackMessage = { + text: `Dev11, CMA SDK Full Sanity +*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s +*Failed Tests:* ${failedTests} +<${reportUrl}|View Report> +${tagUsers}`, +}; + +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); diff --git a/sanity-report.mjs b/sanity-report.mjs index 9735e954..2847a04d 100644 --- a/sanity-report.mjs +++ b/sanity-report.mjs @@ -1,4 +1,5 @@ -import { App } from '@slack/bolt' +import Slack from '@slack/bolt' +const { App } = Slack import dotenv from 'dotenv' import fs from 'fs' 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..4ce676a0 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) => { 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) {