Skip to content

Commit 651ddbf

Browse files
Merge pull request #116 from contentstack/test/cs-43491-sanity-test-delivery-token
sanity test for delivery token
2 parents 22ef564 + e75befb commit 651ddbf

File tree

6 files changed

+293
-27
lines changed

6 files changed

+293
-27
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +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 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",
33+
"test:sanity-test": "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": "npm run test:sanity-test || true",
3435
"test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs",
3536
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill",
3637
"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/sanity-check/api/branchAlias-test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,6 @@ describe('Branch Alias api Test', () => {
5555
})
5656
.catch(done)
5757
})
58-
59-
it('Should delete Branch Alias', done => {
60-
try {
61-
makeBranchAlias(`${stageBranch.uid}_alias`)
62-
.delete()
63-
.then((response) => {
64-
expect(response.notice).to.be.equal('Branch alias deleted successfully.')
65-
done()
66-
})
67-
.catch(done)
68-
} catch (e) {
69-
done()
70-
}
71-
})
72-
it('Should delete stage branch from uid', done => {
73-
client.stack({ api_key: process.env.API_KEY }).branch(stageBranch.uid)
74-
.delete()
75-
.then((response) => {
76-
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.')
77-
done()
78-
})
79-
.catch(done)
80-
})
8158
})
8259

8360
function makeBranchAlias (uid = null) {

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { expect } from 'chai'
22
import { describe, it, setup } from 'mocha'
33
import { jsonReader } from '../utility/fileOperations/readwrite'
4-
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
54
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
6+
import { stageBranch } from '../mock/branch.js'
7+
import { createDeliveryToken } from '../mock/deliveryToken.js'
8+
import dotenv from 'dotenv'
69

10+
dotenv.config()
711
let client = {}
812

913
describe('Delete Environment api Test', () => {
@@ -59,10 +63,76 @@ describe('Delete Locale api Test', () => {
5963
})
6064
})
6165

66+
describe('Delivery Token delete api Test', () => {
67+
let tokenUID = ''
68+
setup(() => {
69+
const user = jsonReader('loggedinuser.json')
70+
client = contentstackClient(user.authtoken)
71+
})
72+
73+
it('should get token uid by name for deleting that token', done => {
74+
makeDeliveryToken()
75+
.query({ query: { name: createDeliveryToken.token.name } })
76+
.find()
77+
.then((tokens) => {
78+
tokens.items.forEach((token) => {
79+
tokenUID = token.uid
80+
})
81+
done()
82+
})
83+
.catch(done)
84+
})
85+
it('should delete Delivery token from uid', done => {
86+
makeDeliveryToken(tokenUID)
87+
.delete()
88+
.then((data) => {
89+
expect(data.notice).to.be.equal('Delivery Token deleted successfully.')
90+
done()
91+
})
92+
.catch(done)
93+
})
94+
})
95+
96+
describe('Branch Alias delete api Test', () => {
97+
setup(() => {
98+
const user = jsonReader('loggedinuser.json')
99+
client = contentstackClient(user.authtoken)
100+
})
101+
it('Should delete Branch Alias', done => {
102+
try {
103+
makeBranchAlias(`${stageBranch.uid}_alias`)
104+
.delete()
105+
.then((response) => {
106+
expect(response.notice).to.be.equal('Branch alias deleted successfully.')
107+
done()
108+
})
109+
.catch(done)
110+
} catch (e) {
111+
done()
112+
}
113+
})
114+
it('Should delete stage branch from uid', done => {
115+
client.stack({ api_key: process.env.API_KEY }).branch(stageBranch.uid)
116+
.delete()
117+
.then((response) => {
118+
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.')
119+
done()
120+
})
121+
.catch(done)
122+
})
123+
})
62124
function makeEnvironment (uid = null) {
63125
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
64126
}
65127

66128
function makeLocale (uid = null) {
67129
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
68130
}
131+
132+
function makeDeliveryToken (uid = null) {
133+
return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid)
134+
}
135+
136+
function makeBranchAlias (uid = null) {
137+
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid)
138+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { createDeliveryToken, createDeliveryToken2 } from '../mock/deliveryToken.js'
5+
import { contentstackClient } from '../utility/ContentstackClient.js'
6+
import dotenv from 'dotenv'
7+
8+
dotenv.config()
9+
let client = {}
10+
11+
let tokenUID = ''
12+
describe('Delivery Token api Test', () => {
13+
setup(() => {
14+
const user = jsonReader('loggedinuser.json')
15+
client = contentstackClient(user.authtoken)
16+
})
17+
18+
it('should add a Delivery Token for development', done => {
19+
makeDeliveryToken()
20+
.create(createDeliveryToken)
21+
.then((token) => {
22+
expect(token.name).to.be.equal(createDeliveryToken.token.name)
23+
expect(token.description).to.be.equal(createDeliveryToken.token.description)
24+
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0])
25+
expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module)
26+
expect(token.uid).to.be.not.equal(null)
27+
done()
28+
})
29+
.catch(done)
30+
})
31+
32+
it('should add a Delivery Token for production', done => {
33+
makeDeliveryToken()
34+
.create(createDeliveryToken2)
35+
.then((token) => {
36+
tokenUID = token.uid
37+
expect(token.name).to.be.equal(createDeliveryToken2.token.name)
38+
expect(token.description).to.be.equal(createDeliveryToken2.token.description)
39+
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
40+
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
41+
expect(token.uid).to.be.not.equal(null)
42+
done()
43+
})
44+
.catch(done)
45+
})
46+
47+
it('should get a Delivery Token from uid', done => {
48+
makeDeliveryToken(tokenUID)
49+
.fetch()
50+
.then((token) => {
51+
expect(token.name).to.be.equal(createDeliveryToken2.token.name)
52+
expect(token.description).to.be.equal(createDeliveryToken2.token.description)
53+
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
54+
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
55+
expect(token.uid).to.be.not.equal(null)
56+
done()
57+
})
58+
.catch(done)
59+
})
60+
61+
it('should query to get all Delivery Token', done => {
62+
makeDeliveryToken()
63+
.query()
64+
.find()
65+
.then((tokens) => {
66+
tokens.items.forEach((token) => {
67+
expect(token.name).to.be.not.equal(null)
68+
expect(token.description).to.be.not.equal(null)
69+
expect(token.scope[0].environments[0].name).to.be.not.equal(null)
70+
expect(token.scope[0].module).to.be.not.equal(null)
71+
expect(token.uid).to.be.not.equal(null)
72+
})
73+
done()
74+
})
75+
.catch(done)
76+
})
77+
78+
it('should query to get a Delivery Token from name', done => {
79+
makeDeliveryToken()
80+
.query({ query: { name: createDeliveryToken.token.name } })
81+
.find()
82+
.then((tokens) => {
83+
tokens.items.forEach((token) => {
84+
expect(token.name).to.be.equal(createDeliveryToken.token.name)
85+
expect(token.description).to.be.equal(createDeliveryToken.token.description)
86+
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0])
87+
expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module)
88+
expect(token.uid).to.be.not.equal(null)
89+
})
90+
done()
91+
})
92+
.catch(done)
93+
})
94+
95+
it('should fetch and update a Delivery Token from uid', done => {
96+
makeDeliveryToken(tokenUID)
97+
.fetch()
98+
.then((token) => {
99+
token.name = 'Update Production Name'
100+
token.description = 'Update Production description'
101+
token.scope = createDeliveryToken2.token.scope
102+
return token.update()
103+
})
104+
.then((token) => {
105+
expect(token.name).to.be.equal('Update Production Name')
106+
expect(token.description).to.be.equal('Update Production description')
107+
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
108+
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
109+
expect(token.uid).to.be.not.equal(null)
110+
done()
111+
})
112+
.catch(done)
113+
})
114+
115+
it('should update a Delivery Token from uid', done => {
116+
const token = makeDeliveryToken(tokenUID)
117+
Object.assign(token, createDeliveryToken2.token)
118+
token.update()
119+
.then((token) => {
120+
expect(token.name).to.be.equal(createDeliveryToken2.token.name)
121+
expect(token.description).to.be.equal(createDeliveryToken2.token.description)
122+
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
123+
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
124+
expect(token.uid).to.be.not.equal(null)
125+
done()
126+
})
127+
.catch(done)
128+
})
129+
130+
it('should delete a Delivery Token from uid', done => {
131+
makeDeliveryToken(tokenUID)
132+
.delete()
133+
.then((data) => {
134+
expect(data.notice).to.be.equal('Delivery Token deleted successfully.')
135+
done()
136+
})
137+
.catch(done)
138+
})
139+
})
140+
141+
function makeDeliveryToken (uid = null) {
142+
return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid)
143+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const createDeliveryToken = {
2+
token: {
3+
name: 'development test',
4+
description: 'This is a demo token.',
5+
scope: [
6+
{
7+
module: 'environment',
8+
environments: [
9+
'development'
10+
],
11+
acl: {
12+
read: true
13+
}
14+
},
15+
{
16+
module: 'branch',
17+
branches: [
18+
'main',
19+
'staging'
20+
],
21+
acl: {
22+
read: true
23+
}
24+
},
25+
{
26+
module: 'branch_alias',
27+
branch_aliases: [
28+
'staging_alias'
29+
],
30+
acl: {
31+
read: true
32+
}
33+
}
34+
]
35+
}
36+
}
37+
const createDeliveryToken2 = {
38+
token: {
39+
name: 'production test',
40+
description: 'This is a demo token.',
41+
scope: [
42+
{
43+
module: 'environment',
44+
environments: [
45+
'production'
46+
],
47+
acl: {
48+
read: true
49+
}
50+
},
51+
{
52+
module: 'branch',
53+
branches: [
54+
'main',
55+
'staging'
56+
],
57+
acl: {
58+
read: true
59+
}
60+
},
61+
{
62+
module: 'branch_alias',
63+
branch_aliases: [
64+
'staging_alias'
65+
],
66+
acl: {
67+
read: true
68+
}
69+
}
70+
]
71+
}
72+
}
73+
74+
export { createDeliveryToken, createDeliveryToken2 }

test/sanity-check/sanity.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ require('./api/organization-test')
33
require('./api/stack-test')
44
require('./api/locale-test')
55
require('./api/environment-test')
6+
require('./api/branch-test')
7+
require('./api/branchAlias-test')
8+
require('./api/deliveryToken-test')
69
require('./api/contentType-test')
710
require('./api/asset-test')
811
require('./api/entry-test')
9-
require('./api/branch-test')
10-
require('./api/branchAlias-test')
1112
require('./api/contentType-delete-test')
1213
require('./api/taxonomy-test')
1314
require('./api/terms-test')

0 commit comments

Comments
 (0)