Skip to content

update sanity with delay for branch creation #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions sanity-report-dev11.js
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 2 additions & 1 deletion sanity-report.mjs
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
24 changes: 11 additions & 13 deletions test/sanity-check/api/branch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ describe('Branch api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
console.log("🚀 ~ setup ~ user.authtoken:", 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()
Expand Down Expand Up @@ -90,6 +87,7 @@ describe('Branch api Test', () => {
.query()
.find()
.then((response) => {
console.log("🚀 ~ .then ~ response:", response)
response.items.forEach(item => {
expect(item.uid).to.not.equal(undefined)
expect(item.delete).to.not.equal(undefined)
Expand Down
2 changes: 1 addition & 1 deletion test/sanity-check/api/taxonomy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
57 changes: 22 additions & 35 deletions test/sanity-check/api/terms-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down
Loading