Skip to content

Commit 0de28b9

Browse files
Merge pull request #249 from contentstack/fix/dx-2069-sanity-update
update sanity with delay for branch creation
2 parents 0094fdd + 3ebc1b8 commit 0de28b9

File tree

5 files changed

+108
-50
lines changed

5 files changed

+108
-50
lines changed

sanity-report-dev11.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const dotenv = require("dotenv");
2+
const fs = require("fs");
3+
4+
dotenv.config();
5+
6+
const user1 = process.env.USER1;
7+
const user2 = process.env.USER2;
8+
const user3 = process.env.USER3;
9+
const user4 = process.env.USER4;
10+
11+
const mochawesomeJsonOutput = fs.readFileSync(
12+
"./mochawesome-report/mochawesome.json",
13+
"utf-8"
14+
);
15+
const mochawesomeReport = JSON.parse(mochawesomeJsonOutput);
16+
17+
const totalTests = mochawesomeReport.stats.tests;
18+
const passedTests = mochawesomeReport.stats.passes;
19+
const failedTests = mochawesomeReport.stats.failures;
20+
21+
let durationInSeconds = Math.floor(mochawesomeReport.stats.duration / 1000);
22+
const durationInMinutes = Math.floor(durationInSeconds / 60);
23+
durationInSeconds %= 60;
24+
25+
const resultMessage =
26+
passedTests === totalTests
27+
? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)`
28+
: `:x: Failure (${passedTests} / ${totalTests} Passed)`;
29+
30+
const pipelineName = process.env.GO_PIPELINE_NAME;
31+
const pipelineCounter = process.env.GO_PIPELINE_COUNTER;
32+
const goCdServer = process.env.GOCD_SERVER;
33+
34+
const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCounter}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html`;
35+
36+
let tagUsers = ``;
37+
if (failedTests > 0) {
38+
tagUsers = `<@${user1}> <@${user2}> <@${user3}> <@${user4}>`;
39+
}
40+
41+
const slackMessage = {
42+
text: `Dev11, CMA SDK Full Sanity
43+
*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s
44+
*Failed Tests:* ${failedTests}
45+
<${reportUrl}|View Report>
46+
${tagUsers}`,
47+
};
48+
49+
const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL;
50+
51+
const sendSlackMessage = async (message) => {
52+
const payload = {
53+
text: message,
54+
};
55+
56+
try {
57+
const response = await fetch(slackWebhookUrl, {
58+
method: "POST",
59+
headers: {
60+
"Content-Type": "application/json",
61+
},
62+
body: JSON.stringify(payload),
63+
});
64+
65+
if (!response.ok) {
66+
throw new Error(`Error sending message to Slack: ${response.statusText}`);
67+
}
68+
69+
console.log("Message sent to Slack successfully");
70+
} catch (error) {
71+
console.error("Error:", error);
72+
}
73+
};
74+
sendSlackMessage(slackMessage.text);

sanity-report.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { App } from '@slack/bolt'
1+
import Slack from '@slack/bolt'
2+
const { App } = Slack
23
import dotenv from 'dotenv'
34
import fs from 'fs'
45

test/sanity-check/api/branch-test.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ describe('Branch api Test', () => {
1212
client = contentstackClient(user.authtoken)
1313
})
1414

15-
it('should create a dev branch from stage branch', done => {
16-
makeBranch()
17-
.create({ branch: devBranch })
18-
.then((response) => {
19-
expect(response.uid).to.be.equal(devBranch.uid)
20-
expect(response.source).to.be.equal(devBranch.source)
21-
expect(response.alias).to.not.equal(undefined)
22-
expect(response.delete).to.not.equal(undefined)
23-
expect(response.fetch).to.not.equal(undefined)
24-
done()
25-
})
26-
.catch(done)
27-
})
15+
it('should create a dev branch from stage branch',async () => {
16+
const response = await makeBranch().create({ branch: devBranch });
17+
expect(response.uid).to.be.equal(devBranch.uid);
18+
expect(response.source).to.be.equal(devBranch.source);
19+
expect(response.alias).to.not.equal(undefined);
20+
expect(response.delete).to.not.equal(undefined);
21+
expect(response.fetch).to.not.equal(undefined);
22+
await new Promise(resolve => setTimeout(resolve, 15000));
23+
});
2824

2925
it('should return main branch when query is called', done => {
3026
makeBranch()

test/sanity-check/api/taxonomy-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('taxonomy api Test', () => {
3232
.catch(done)
3333
})
3434

35-
it('should fetch taxonomy of the uid passe', done => {
35+
it('should fetch taxonomy of the uid passed', done => {
3636
makeTaxonomy(taxonomyUID)
3737
.fetch()
3838
.then((taxonomyResponse) => {

test/sanity-check/api/terms-test.js

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,22 @@ describe('Terms API Test', () => {
4444
await client.stack({ api_key: process.env.API_KEY }).taxonomy().create({ taxonomy })
4545
}, 10000)
4646

47-
it('should create term', done => {
48-
makeTerms(taxonomy.uid).create(term)
49-
.then((response) => {
50-
expect(response.uid).to.be.equal(term.term.uid)
51-
done()
52-
})
53-
.catch(done)
47+
it('should create term', async () => {
48+
const response = await makeTerms(taxonomy.uid).create(term)
49+
expect(response.uid).to.be.equal(term.term.uid)
50+
await new Promise(resolve => setTimeout(resolve, 15000));
5451
})
5552

56-
it('should create child term 1', done => {
57-
makeTerms(taxonomy.uid).create(childTerm1)
58-
.then((response) => {
59-
expect(response.uid).to.be.equal(childTerm1.term.uid)
60-
done()
61-
})
62-
.catch(done)
53+
it('should create child term 1', async () => {
54+
const response = await makeTerms(taxonomy.uid).create(childTerm1)
55+
expect(response.uid).to.be.equal(childTerm1.term.uid)
56+
await new Promise(resolve => setTimeout(resolve, 15000));
6357
})
6458

65-
it('should create child term 2', done => {
66-
makeTerms(taxonomy.uid).create(childTerm2)
67-
.then((response) => {
68-
expect(response.uid).to.be.equal(childTerm2.term.uid)
69-
done()
70-
})
71-
.catch(done)
59+
it('should create child term 2', async () => {
60+
const response = await makeTerms(taxonomy.uid).create(childTerm2)
61+
expect(response.uid).to.be.equal(childTerm2.term.uid)
62+
await new Promise(resolve => setTimeout(resolve, 15000));
7263
})
7364

7465
it('should query and get all terms', done => {
@@ -180,20 +171,16 @@ describe('Branch creation api Test', () => {
180171
client = contentstackClient(user.authtoken)
181172
})
182173

183-
it('should create staging branch', done => {
184-
makeBranch()
185-
.create({ branch: stageBranch })
186-
.then((response) => {
187-
expect(response.uid).to.be.equal(stageBranch.uid)
188-
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
189-
expect(response.source).to.be.equal(stageBranch.source)
190-
expect(response.alias).to.not.equal(undefined)
191-
expect(response.delete).to.not.equal(undefined)
192-
expect(response.fetch).to.not.equal(undefined)
193-
done()
194-
})
195-
.catch(done)
196-
})
174+
it('should create staging branch', async () => {
175+
const response = await makeBranch().create({ branch: stageBranch });
176+
expect(response.uid).to.be.equal(stageBranch.uid);
177+
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`);
178+
expect(response.source).to.be.equal(stageBranch.source);
179+
expect(response.alias).to.not.equal(undefined);
180+
expect(response.fetch).to.not.equal(undefined);
181+
expect(response.delete).to.not.equal(undefined);
182+
await new Promise(resolve => setTimeout(resolve, 15000));
183+
});
197184
})
198185

199186
function makeBranch (uid = null) {

0 commit comments

Comments
 (0)