Skip to content

sanity test for locale and environment delete #113

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 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production",
"buildweb": "webpack --config webpack/webpack.web.js --mode production",
"test": "npm run test:api && npm run test:unit",
"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",
"test:sanity-report": "node sanity-report.mjs",
"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",
"test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs",
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill",
"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",
"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",
Expand Down Expand Up @@ -92,6 +92,7 @@
"jest": "^28.1.0",
"jsdoc": "^4.0.2",
"mocha": "^9.2.2",
"mocha-html-reporter": "^0.0.1",
"mochawesome": "^7.1.3",
"multiparty": "^4.2.3",
"nock": "^10.0.6",
Expand Down
31 changes: 21 additions & 10 deletions sanity-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,53 @@ dotenv.config()

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

const totalSuites = mochawesomeReport.stats.suites
const totalTests = mochawesomeReport.stats.tests
const passedTests = mochawesomeReport.stats.passes
const failedTests = mochawesomeReport.stats.failures
const pendingTests = mochawesomeReport.stats.pending
const durationInSeconds = mochawesomeReport.stats.duration / 1000
let durationInSeconds = mochawesomeReport.stats.duration / 1000
const durationInMinutes = Math.floor(durationInSeconds / 60)
durationInSeconds %= 60

console.log(`Total Suites: ${totalSuites}`)
console.log(`Total Tests: ${totalTests}`)
console.log(`Passed Tests: ${passedTests}`)
console.log(`Failed Tests: ${failedTests}`)
console.log(`Pending Tests: ${pendingTests}`)
console.log(`Total Duration: ${durationInSeconds.toFixed(2)} seconds`)
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)

const slackMessage = `
*Test Summary*
Total Suites: ${totalSuites}
Total Tests: ${totalTests}
Passed Tests: ${passedTests}
Failed Tests: ${failedTests}
Pending Tests: ${pendingTests}
Total Duration: ${durationInSeconds.toFixed(2)} seconds
Total Suites: *${totalSuites}*
Total Tests: *${totalTests}*
Passed Tests: *${passedTests}*
Failed Tests: *${failedTests}*
Pending Tests: *${pendingTests}*
Total Duration: *${durationInMinutes}m ${durationInSeconds.toFixed(2)}s*
`

const app = new Slack.App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
})

async function publishMessage (text) {
async function publishMessage (text, report) {
await app.client.chat.postMessage({
token: process.env.SLACK_BOT_TOKEN,
channel: process.env.SLACK_CHANNEL,
text: text
})
await app.client.files.upload({
token: process.env.SLACK_BOT_TOKEN,
channels: process.env.SLACK_CHANNEL,
initial_comment: '*Here is the report generated*',
filetype: 'html',
filename: 'sanity-report.html',
file: fs.createReadStream(report)
})
}

publishMessage(slackMessage)
publishMessage(slackMessage, report)
Empty file.
68 changes: 68 additions & 0 deletions test/sanity-check/api/delete-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}

describe('Delete Environment api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should delete an environment', done => {
makeEnvironment(environmentCreate.environment.name)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Environment deleted successfully.')
done()
})
.catch(done)
})

it('should delete the prod environment', done => {
makeEnvironment(environmentProdCreate.environment.name)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Environment deleted successfully.')
done()
})
.catch(done)
})
})

describe('Delete Locale api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('should delete language: Hindi - India', done => {
makeLocale('hi-in')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})

it('should delete language: English - Austria', done => {
makeLocale('en-at')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})
})

function makeEnvironment (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
}

function makeLocale (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
}
127 changes: 127 additions & 0 deletions test/sanity-check/api/locale-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}

describe('Locale api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('should add a language English - Austria', done => {
makeLocale()
.create({ locale: { code: 'en-at' } })
.then((locale) => {
expect(locale.code).to.be.equal('en-at')
expect(locale.name).to.be.equal('English - Austria')
expect(locale.fallback_locale).to.be.equal('en-us')
expect(locale.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should add a language Hindi - India', done => {
makeLocale()
.create({ locale: { code: 'hi-in' } })
.then((locale) => {
expect(locale.code).to.be.equal('hi-in')
expect(locale.name).to.be.equal('Hindi - India')
expect(locale.fallback_locale).to.be.equal('en-us')
expect(locale.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should add a language Marathi - India with Fallback en-at', done => {
makeLocale()
.create({ locale: { code: 'mr-in', fallback_locale: 'en-at' } })
.then((locale) => {
expect(locale.code).to.be.equal('mr-in')
expect(locale.name).to.be.equal('Marathi - India')
expect(locale.fallback_locale).to.be.equal('en-at')
expect(locale.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should get a all languages', done => {
makeLocale()
.query()
.find()
.then((locales) => {
locales.items.forEach((locale) => {
expect(locale.code).to.be.not.equal(null)
expect(locale.name).to.be.not.equal(null)
expect(locale.uid).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('should query a language Hindi - India', done => {
makeLocale()
.query({ query: { name: 'Hindi - India' } })
.find()
.then((locales) => {
locales.items.forEach((locale) => {
expect(locale.code).to.be.equal('hi-in')
expect(locale.name).to.be.equal('Hindi - India')
expect(locale.fallback_locale).to.be.equal('en-us')
expect(locale.uid).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('should get a language Hindi - India', done => {
makeLocale('hi-in')
.fetch()
.then((locale) => {
expect(locale.code).to.be.equal('hi-in')
expect(locale.name).to.be.equal('Hindi - India')
expect(locale.fallback_locale).to.be.equal('en-us')
expect(locale.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should get and update a language Hindi - India', done => {
makeLocale('hi-in')
.fetch()
.then((locale) => {
locale.fallback_locale = 'en-at'
return locale.update()
})
.then((locale) => {
expect(locale.code).to.be.equal('hi-in')
expect(locale.name).to.be.equal('Hindi - India')
expect(locale.fallback_locale).to.be.equal('en-at')
expect(locale.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should delete language: Hindi - India', done => {
makeLocale('mr-in')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})
})

function makeLocale (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
}
2 changes: 2 additions & 0 deletions test/sanity-check/sanity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('./api/user-test')
require('./api/organization-test')
require('./api/stack-test')
require('./api/locale-test')
require('./api/environment-test')
require('./api/contentType-test')
require('./api/asset-test')
Expand All @@ -10,3 +11,4 @@ require('./api/branchAlias-test')
require('./api/contentType-delete-test')
require('./api/taxonomy-test')
require('./api/terms-test')
require('./api/delete-test')