Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a0ed39d

Browse files
committedJan 11, 2024
test: added environment test to sanity and changes done in branch test
1 parent a9398ad commit a0ed39d

File tree

4 files changed

+184
-19
lines changed

4 files changed

+184
-19
lines changed
 

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

+15-19
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ describe('Branch api Test', () => {
1212
client = contentstackClient(user.authtoken)
1313
})
1414

15-
it('should create Branch from staging', done => {
15+
it('should create a dev branch from stage branch', done => {
1616
makeBranch()
1717
.create({ branch: devBranch })
1818
.then((response) => {
1919
expect(response.uid).to.be.equal(devBranch.uid)
20-
expect(response.urlPath).to.be.equal(`/stacks/branches/${devBranch.uid}`)
2120
expect(response.source).to.be.equal(devBranch.source)
2221
expect(response.alias).to.not.equal(undefined)
2322
expect(response.delete).to.not.equal(undefined)
@@ -27,13 +26,13 @@ describe('Branch api Test', () => {
2726
.catch(done)
2827
})
2928

30-
it('should return master branch when query is called', done => {
29+
it('should return main branch when query is called', done => {
3130
makeBranch()
3231
.query()
3332
.find()
3433
.then((response) => {
3534
var item = response.items[0]
36-
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
35+
expect(item.uid).to.not.equal(undefined)
3736
expect(item.delete).to.not.equal(undefined)
3837
expect(item.fetch).to.not.equal(undefined)
3938
done()
@@ -46,7 +45,6 @@ describe('Branch api Test', () => {
4645
.fetch()
4746
.then((response) => {
4847
expect(response.uid).to.be.equal(branch.uid)
49-
expect(response.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`)
5048
expect(response.source).to.be.equal(branch.source)
5149
expect(response.alias).to.not.equal(undefined)
5250
expect(response.delete).to.not.equal(undefined)
@@ -61,7 +59,6 @@ describe('Branch api Test', () => {
6159
.fetch()
6260
.then((response) => {
6361
expect(response.uid).to.be.equal(stageBranch.uid)
64-
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
6562
expect(response.source).to.be.equal(stageBranch.source)
6663
expect(response.alias).to.not.equal(undefined)
6764
expect(response.delete).to.not.equal(undefined)
@@ -78,7 +75,7 @@ describe('Branch api Test', () => {
7875
.then((response) => {
7976
expect(response.items.length).to.be.equal(1)
8077
response.items.forEach(item => {
81-
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
78+
expect(item.uid).to.not.equal(undefined)
8279
expect(item.source).to.be.equal(`main`)
8380
expect(item.delete).to.not.equal(undefined)
8481
expect(item.fetch).to.not.equal(undefined)
@@ -93,9 +90,8 @@ describe('Branch api Test', () => {
9390
.query()
9491
.find()
9592
.then((response) => {
96-
expect(response.items.length).to.be.equal(3)
9793
response.items.forEach(item => {
98-
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
94+
expect(item.uid).to.not.equal(undefined)
9995
expect(item.delete).to.not.equal(undefined)
10096
expect(item.fetch).to.not.equal(undefined)
10197
})
@@ -104,16 +100,6 @@ describe('Branch api Test', () => {
104100
.catch(done)
105101
})
106102

107-
it('should delete branch from branch uid', done => {
108-
makeBranch(devBranch.uid)
109-
.delete()
110-
.then((response) => {
111-
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.')
112-
done()
113-
})
114-
.catch(done)
115-
})
116-
117103
it('should provide list of content types and global fields that exist in only one branch or are different between the two branches', done => {
118104
makeBranch(branch.uid)
119105
.compare(stageBranch.uid)
@@ -212,6 +198,16 @@ describe('Branch api Test', () => {
212198
})
213199
.catch(done)
214200
})
201+
202+
it('should delete dev branch from branch uid', done => {
203+
makeBranch(devBranch.uid)
204+
.delete()
205+
.then((response) => {
206+
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.')
207+
done()
208+
})
209+
.catch(done)
210+
})
215211
})
216212

217213
function makeBranch (uid = null) {
+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite'
4+
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
5+
import { cloneDeep } from 'lodash'
6+
import { contentstackClient } from '../utility/ContentstackClient.js'
7+
8+
var client = {}
9+
10+
describe('Environment api Test', () => {
11+
setup(() => {
12+
const user = jsonReader('loggedinuser.json')
13+
client = contentstackClient(user.authtoken)
14+
})
15+
16+
it('Add a Environment development', done => {
17+
makeEnvironment()
18+
.create(environmentCreate)
19+
.then((environment) => {
20+
expect(environment.name).to.be.equal(environmentCreate.environment.name)
21+
expect(environment.uid).to.be.not.equal(null)
22+
done()
23+
})
24+
.catch(done)
25+
})
26+
27+
it('Add a Environment production', done => {
28+
makeEnvironment()
29+
.create(environmentProdCreate)
30+
.then((environment) => {
31+
expect(environment.name).to.be.equal(environmentProdCreate.environment.name)
32+
expect(environment.uid).to.be.not.equal(null)
33+
expect(environment.urls).to.be.not.equal(null)
34+
done()
35+
})
36+
.catch(done)
37+
})
38+
39+
it('Get a Environment development', done => {
40+
makeEnvironment(environmentCreate.environment.name)
41+
.fetch()
42+
.then((environment) => {
43+
expect(environment.name).to.be.equal(environmentCreate.environment.name)
44+
expect(environment.uid).to.be.not.equal(null)
45+
expect(environment.urls).to.be.not.equal(null)
46+
done()
47+
})
48+
.catch(done)
49+
})
50+
51+
it('Query a Environment development', done => {
52+
makeEnvironment()
53+
.query({ query: { name: environmentCreate.environment.name } })
54+
.find()
55+
.then((environments) => {
56+
environments.items.forEach((environment) => {
57+
expect(environment.name).to.be.equal(environmentCreate.environment.name)
58+
expect(environment.uid).to.be.not.equal(null)
59+
expect(environment.urls).to.be.not.equal(null)
60+
})
61+
done()
62+
})
63+
.catch(done)
64+
})
65+
66+
it('Fetch and Update a Environment', done => {
67+
makeEnvironment(environmentCreate.environment.name)
68+
.fetch()
69+
.then((environment) => {
70+
environment.name = 'dev'
71+
return environment.update()
72+
})
73+
.then((environment) => {
74+
expect(environment.name).to.be.equal('dev')
75+
expect(environment.urls).to.be.not.equal(null)
76+
expect(environment.uid).to.be.not.equal(null)
77+
done()
78+
})
79+
.catch(done)
80+
})
81+
82+
it('Update a Environment', done => {
83+
var environment = makeEnvironment('dev')
84+
Object.assign(environment, cloneDeep(environmentCreate.environment))
85+
environment.update()
86+
.then((environment) => {
87+
expect(environment.name).to.be.equal(environmentCreate.environment.name)
88+
expect(environment.urls).to.be.not.equal(null)
89+
expect(environment.uid).to.be.not.equal(null)
90+
done()
91+
})
92+
.catch(done)
93+
})
94+
95+
it('delete a Environment', done => {
96+
makeEnvironment(environmentProdCreate.environment.name)
97+
.delete()
98+
.then((data) => {
99+
expect(data.notice).to.be.equal('Environment deleted successfully.')
100+
done()
101+
})
102+
.catch(done)
103+
})
104+
105+
it('Add a Environment production', done => {
106+
makeEnvironment()
107+
.create(environmentProdCreate)
108+
.then((environment) => {
109+
expect(environment.name).to.be.equal(environmentProdCreate.environment.name)
110+
expect(environment.uid).to.be.not.equal(null)
111+
expect(environment.urls).to.be.not.equal(null)
112+
done()
113+
})
114+
.catch(done)
115+
})
116+
117+
it('Query all Environments', done => {
118+
makeEnvironment()
119+
.query()
120+
.find()
121+
.then((environments) => {
122+
jsonWrite(environments.items, 'environments.json')
123+
environments.items.forEach((environment) => {
124+
expect(environment.name).to.be.not.equal(null)
125+
expect(environment.uid).to.be.not.equal(null)
126+
expect(environment.urls).to.be.not.equal(null)
127+
})
128+
done()
129+
})
130+
.catch(done)
131+
})
132+
})
133+
134+
function makeEnvironment (uid = null) {
135+
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
136+
}

‎test/sanity-check/mock/environment.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const environmentCreate = {
2+
environment: {
3+
name: 'development',
4+
servers: [
5+
{
6+
name: 'default'
7+
}
8+
],
9+
urls: [
10+
{
11+
locale: 'en-us',
12+
url: 'http://example.com/'
13+
}
14+
],
15+
deploy_content: true
16+
}
17+
}
18+
const environmentProdCreate = {
19+
environment: {
20+
name: 'production',
21+
servers: [],
22+
urls: [
23+
{
24+
locale: 'en-us',
25+
url: 'http://example.com/'
26+
}
27+
],
28+
deploy_content: true
29+
}
30+
}
31+
32+
export { environmentCreate, environmentProdCreate }

‎test/sanity-check/sanity.js

+1
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/environment-test')
45
require('./api/contentType-test')
56
require('./api/asset-test')
67
require('./api/entry-test')

0 commit comments

Comments
 (0)
Please sign in to comment.