Skip to content

Commit 02e15a8

Browse files
test: Added locale test suit and delete test suit to sanity folder
1 parent b2bbd28 commit 02e15a8

File tree

6 files changed

+221
-12
lines changed

6 files changed

+221
-12
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production",
3131
"buildweb": "webpack --config webpack/webpack.web.js --mode production",
3232
"test": "npm run test:api && npm run test:unit",
33-
"test:sanity": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill",
34-
"test:sanity-report": "node sanity-report.mjs",
33+
"test:sanity": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json && marge mochawesome-report/mochawesome.json -f sanity-report.html --inline",
34+
"test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs",
3535
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill",
3636
"test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill",
3737
"test:unit:report:json": "BABEL_ENV=test nyc --reporter=clover --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter json --reporter-options output=report.json --require babel-polyfill",
@@ -92,6 +92,7 @@
9292
"jest": "^28.1.0",
9393
"jsdoc": "^4.0.2",
9494
"mocha": "^9.2.2",
95+
"mocha-html-reporter": "^0.0.1",
9596
"mochawesome": "^7.1.3",
9697
"multiparty": "^4.2.3",
9798
"nock": "^10.0.6",

sanity-report.mjs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,53 @@ dotenv.config()
66

77
const mochawesomeJsonOutput = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf-8')
88
const mochawesomeReport = JSON.parse(mochawesomeJsonOutput)
9+
const report = `./mochawesome-report/sanity-report.html`
910

1011
const totalSuites = mochawesomeReport.stats.suites
1112
const totalTests = mochawesomeReport.stats.tests
1213
const passedTests = mochawesomeReport.stats.passes
1314
const failedTests = mochawesomeReport.stats.failures
1415
const pendingTests = mochawesomeReport.stats.pending
15-
const durationInSeconds = mochawesomeReport.stats.duration / 1000
16+
let durationInSeconds = mochawesomeReport.stats.duration / 1000
17+
const durationInMinutes = Math.floor(durationInSeconds / 60)
18+
durationInSeconds %= 60
1619

1720
console.log(`Total Suites: ${totalSuites}`)
1821
console.log(`Total Tests: ${totalTests}`)
1922
console.log(`Passed Tests: ${passedTests}`)
2023
console.log(`Failed Tests: ${failedTests}`)
2124
console.log(`Pending Tests: ${pendingTests}`)
22-
console.log(`Total Duration: ${durationInSeconds.toFixed(2)} seconds`)
25+
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)
2326

2427
const slackMessage = `
2528
*Test Summary*
26-
Total Suites: ${totalSuites}
27-
Total Tests: ${totalTests}
28-
Passed Tests: ${passedTests}
29-
Failed Tests: ${failedTests}
30-
Pending Tests: ${pendingTests}
31-
Total Duration: ${durationInSeconds.toFixed(2)} seconds
29+
Total Suites: *${totalSuites}*
30+
Total Tests: *${totalTests}*
31+
Passed Tests: *${passedTests}*
32+
Failed Tests: *${failedTests}*
33+
Pending Tests: *${pendingTests}*
34+
Total Duration: *${durationInMinutes}m ${durationInSeconds.toFixed(2)}s*
3235
`
3336

3437
const app = new Slack.App({
3538
token: process.env.SLACK_BOT_TOKEN,
3639
signingSecret: process.env.SLACK_SIGNING_SECRET
3740
})
3841

39-
async function publishMessage (text) {
42+
async function publishMessage (text, report) {
4043
await app.client.chat.postMessage({
4144
token: process.env.SLACK_BOT_TOKEN,
4245
channel: process.env.SLACK_CHANNEL,
4346
text: text
4447
})
48+
await app.client.files.upload({
49+
token: process.env.SLACK_BOT_TOKEN,
50+
channels: process.env.SLACK_CHANNEL,
51+
initial_comment: '*Here is the report generated*',
52+
filetype: 'html',
53+
filename: 'sanity-report.html',
54+
file: fs.createReadStream(report)
55+
})
4556
}
4657

47-
publishMessage(slackMessage)
58+
publishMessage(slackMessage, report)

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

Whitespace-only changes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
5+
import { contentstackClient } from '../utility/ContentstackClient.js'
6+
7+
let client = {}
8+
9+
describe('Delete Environment api Test', () => {
10+
setup(() => {
11+
const user = jsonReader('loggedinuser.json')
12+
client = contentstackClient(user.authtoken)
13+
})
14+
it('should delete an environment', done => {
15+
makeEnvironment(environmentCreate.environment.name)
16+
.delete()
17+
.then((data) => {
18+
expect(data.notice).to.be.equal('Environment deleted successfully.')
19+
done()
20+
})
21+
.catch(done)
22+
})
23+
24+
it('should delete the prod environment', done => {
25+
makeEnvironment(environmentProdCreate.environment.name)
26+
.delete()
27+
.then((data) => {
28+
expect(data.notice).to.be.equal('Environment deleted successfully.')
29+
done()
30+
})
31+
.catch(done)
32+
})
33+
})
34+
35+
describe('Delete Locale api Test', () => {
36+
setup(() => {
37+
const user = jsonReader('loggedinuser.json')
38+
client = contentstackClient(user.authtoken)
39+
})
40+
41+
it('should delete language: Hindi - India', done => {
42+
makeLocale('hi-in')
43+
.delete()
44+
.then((data) => {
45+
expect(data.notice).to.be.equal('Language removed successfully.')
46+
done()
47+
})
48+
.catch(done)
49+
})
50+
51+
it('should delete language: English - Austria', done => {
52+
makeLocale('en-at')
53+
.delete()
54+
.then((data) => {
55+
expect(data.notice).to.be.equal('Language removed successfully.')
56+
done()
57+
})
58+
.catch(done)
59+
})
60+
})
61+
62+
function makeEnvironment (uid = null) {
63+
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
64+
}
65+
66+
function makeLocale (uid = null) {
67+
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
68+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
6+
let client = {}
7+
8+
describe('Locale api Test', () => {
9+
setup(() => {
10+
const user = jsonReader('loggedinuser.json')
11+
client = contentstackClient(user.authtoken)
12+
})
13+
14+
it('should add a language English - Austria', done => {
15+
makeLocale()
16+
.create({ locale: { code: 'en-at' } })
17+
.then((locale) => {
18+
expect(locale.code).to.be.equal('en-at')
19+
expect(locale.name).to.be.equal('English - Austria')
20+
expect(locale.fallback_locale).to.be.equal('en-us')
21+
expect(locale.uid).to.be.not.equal(null)
22+
done()
23+
})
24+
.catch(done)
25+
})
26+
27+
it('should add a language Hindi - India', done => {
28+
makeLocale()
29+
.create({ locale: { code: 'hi-in' } })
30+
.then((locale) => {
31+
expect(locale.code).to.be.equal('hi-in')
32+
expect(locale.name).to.be.equal('Hindi - India')
33+
expect(locale.fallback_locale).to.be.equal('en-us')
34+
expect(locale.uid).to.be.not.equal(null)
35+
done()
36+
})
37+
.catch(done)
38+
})
39+
40+
it('should add a language Marathi - India with Fallback en-at', done => {
41+
makeLocale()
42+
.create({ locale: { code: 'mr-in', fallback_locale: 'en-at' } })
43+
.then((locale) => {
44+
expect(locale.code).to.be.equal('mr-in')
45+
expect(locale.name).to.be.equal('Marathi - India')
46+
expect(locale.fallback_locale).to.be.equal('en-at')
47+
expect(locale.uid).to.be.not.equal(null)
48+
done()
49+
})
50+
.catch(done)
51+
})
52+
53+
it('should get a all languages', done => {
54+
makeLocale()
55+
.query()
56+
.find()
57+
.then((locales) => {
58+
locales.items.forEach((locale) => {
59+
expect(locale.code).to.be.not.equal(null)
60+
expect(locale.name).to.be.not.equal(null)
61+
expect(locale.uid).to.be.not.equal(null)
62+
})
63+
done()
64+
})
65+
.catch(done)
66+
})
67+
68+
it('should query a language Hindi - India', done => {
69+
makeLocale()
70+
.query({ query: { name: 'Hindi - India' } })
71+
.find()
72+
.then((locales) => {
73+
locales.items.forEach((locale) => {
74+
expect(locale.code).to.be.equal('hi-in')
75+
expect(locale.name).to.be.equal('Hindi - India')
76+
expect(locale.fallback_locale).to.be.equal('en-us')
77+
expect(locale.uid).to.be.not.equal(null)
78+
})
79+
done()
80+
})
81+
.catch(done)
82+
})
83+
84+
it('should get a language Hindi - India', done => {
85+
makeLocale('hi-in')
86+
.fetch()
87+
.then((locale) => {
88+
expect(locale.code).to.be.equal('hi-in')
89+
expect(locale.name).to.be.equal('Hindi - India')
90+
expect(locale.fallback_locale).to.be.equal('en-us')
91+
expect(locale.uid).to.be.not.equal(null)
92+
done()
93+
})
94+
.catch(done)
95+
})
96+
97+
it('should get and update a language Hindi - India', done => {
98+
makeLocale('hi-in')
99+
.fetch()
100+
.then((locale) => {
101+
locale.fallback_locale = 'en-at'
102+
return locale.update()
103+
})
104+
.then((locale) => {
105+
expect(locale.code).to.be.equal('hi-in')
106+
expect(locale.name).to.be.equal('Hindi - India')
107+
expect(locale.fallback_locale).to.be.equal('en-at')
108+
expect(locale.uid).to.be.not.equal(null)
109+
done()
110+
})
111+
.catch(done)
112+
})
113+
114+
it('should delete language: Hindi - India', done => {
115+
makeLocale('mr-in')
116+
.delete()
117+
.then((data) => {
118+
expect(data.notice).to.be.equal('Language removed successfully.')
119+
done()
120+
})
121+
.catch(done)
122+
})
123+
})
124+
125+
function makeLocale (uid = null) {
126+
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
127+
}

test/sanity-check/sanity.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require('./api/user-test')
22
require('./api/organization-test')
33
require('./api/stack-test')
4+
require('./api/locale-test')
45
require('./api/environment-test')
56
require('./api/contentType-test')
67
require('./api/asset-test')
@@ -10,3 +11,4 @@ require('./api/branchAlias-test')
1011
require('./api/contentType-delete-test')
1112
require('./api/taxonomy-test')
1213
require('./api/terms-test')
14+
require('./api/delete-test')

0 commit comments

Comments
 (0)