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 258b3a9

Browse files
committedJan 5, 2024
test: added branches and aliases test suits to sanity folder
1 parent 2e38341 commit 258b3a9

File tree

5 files changed

+328
-3
lines changed

5 files changed

+328
-3
lines changed
 

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

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
import { branch, stageBranch, devBranch } from '../mock/branch.js'
6+
7+
var client = {}
8+
var mergeJobUid = ''
9+
describe('Branch api Test', () => {
10+
setup(() => {
11+
const user = jsonReader('loggedinuser.json')
12+
client = contentstackClient(user.authtoken)
13+
})
14+
15+
it('should return master branch when query is called', done => {
16+
makeBranch()
17+
.query()
18+
.find()
19+
.then((response) => {
20+
expect(response.items.length).to.be.equal(1)
21+
var item = response.items[0]
22+
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
23+
expect(item.delete).to.not.equal(undefined)
24+
expect(item.fetch).to.not.equal(undefined)
25+
done()
26+
})
27+
.catch(done)
28+
})
29+
30+
it('should create staging branch', done => {
31+
makeBranch()
32+
.create({ branch: stageBranch })
33+
.then((response) => {
34+
expect(response.uid).to.be.equal(stageBranch.uid)
35+
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
36+
expect(response.source).to.be.equal(stageBranch.source)
37+
expect(response.alias).to.not.equal(undefined)
38+
expect(response.delete).to.not.equal(undefined)
39+
expect(response.fetch).to.not.equal(undefined)
40+
done()
41+
})
42+
.catch(done)
43+
})
44+
45+
it('should fetch stage branch from branch uid', done => {
46+
makeBranch(branch.uid)
47+
.fetch()
48+
.then((response) => {
49+
expect(response.uid).to.be.equal(branch.uid)
50+
expect(response.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`)
51+
expect(response.source).to.be.equal(branch.source)
52+
expect(response.alias).to.not.equal(undefined)
53+
expect(response.delete).to.not.equal(undefined)
54+
expect(response.fetch).to.not.equal(undefined)
55+
done()
56+
})
57+
.catch(done)
58+
})
59+
60+
it('should create Branch from staging', done => {
61+
makeBranch()
62+
.create({ branch: devBranch })
63+
.then((response) => {
64+
expect(response.uid).to.be.equal(devBranch.uid)
65+
expect(response.urlPath).to.be.equal(`/stacks/branches/${devBranch.uid}`)
66+
expect(response.source).to.be.equal(devBranch.source)
67+
expect(response.alias).to.not.equal(undefined)
68+
expect(response.delete).to.not.equal(undefined)
69+
expect(response.fetch).to.not.equal(undefined)
70+
done()
71+
})
72+
.catch(done)
73+
})
74+
75+
it('should query branch for specific condition', done => {
76+
makeBranch()
77+
.query({ query: { source: 'main' } })
78+
.find()
79+
.then((response) => {
80+
expect(response.items.length).to.be.equal(1)
81+
response.items.forEach(item => {
82+
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
83+
expect(item.source).to.be.equal(`main`)
84+
expect(item.delete).to.not.equal(undefined)
85+
expect(item.fetch).to.not.equal(undefined)
86+
})
87+
done()
88+
})
89+
.catch(done)
90+
})
91+
92+
it('should query branch to return all branches', done => {
93+
makeBranch()
94+
.query()
95+
.find()
96+
.then((response) => {
97+
expect(response.items.length).to.be.equal(3)
98+
response.items.forEach(item => {
99+
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
100+
expect(item.delete).to.not.equal(undefined)
101+
expect(item.fetch).to.not.equal(undefined)
102+
})
103+
done()
104+
})
105+
.catch(done)
106+
})
107+
108+
it('should delete branch from branch uid', done => {
109+
makeBranch(devBranch.uid)
110+
.delete()
111+
.then((response) => {
112+
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.')
113+
done()
114+
})
115+
.catch(done)
116+
})
117+
118+
it('should provide list of content types and global fields that exist in only one branch or are different between the two branches', done => {
119+
makeBranch(branch.uid)
120+
.compare(stageBranch.uid)
121+
.all()
122+
.then((response) => {
123+
expect(response.branches.base_branch).to.be.equal(branch.uid)
124+
expect(response.branches.compare_branch).to.be.equal(stageBranch.uid)
125+
done()
126+
})
127+
.catch(done)
128+
})
129+
130+
it('should list differences for a content types between two branches', done => {
131+
makeBranch(branch.uid)
132+
.compare(stageBranch.uid)
133+
.contentTypes()
134+
.then((response) => {
135+
expect(response.branches.base_branch).to.be.equal(branch.uid)
136+
expect(response.branches.compare_branch).to.be.equal(stageBranch.uid)
137+
done()
138+
})
139+
.catch(done)
140+
})
141+
142+
it('should list differences for a global fields between two branches', done => {
143+
makeBranch(branch.uid)
144+
.compare(stageBranch.uid)
145+
.globalFields()
146+
.then((response) => {
147+
expect(response.branches.base_branch).to.be.equal(branch.uid)
148+
expect(response.branches.compare_branch).to.be.equal(stageBranch.uid)
149+
done()
150+
})
151+
.catch(done)
152+
})
153+
154+
it('should merge given two branches', done => {
155+
const params = {
156+
base_branch: branch.uid,
157+
compare_branch: stageBranch.uid,
158+
default_merge_strategy: 'ignore',
159+
merge_comment: 'Merging staging into main'
160+
}
161+
const mergeObj = {
162+
item_merge_strategies: [
163+
{
164+
uid: 'global_field_uid',
165+
type: 'global_field',
166+
merge_strategy: 'merge_prefer_base'
167+
},
168+
{
169+
uid: 'ct5',
170+
type: 'content_type',
171+
merge_strategy: 'merge_prefer_compare'
172+
},
173+
{
174+
uid: 'bot_all',
175+
type: 'content_type',
176+
merge_strategy: 'merge_prefer_base'
177+
}
178+
]
179+
}
180+
makeBranch()
181+
.merge(mergeObj, params)
182+
.then((response) => {
183+
mergeJobUid = response.uid
184+
expect(response.merge_details.base_branch).to.be.equal(branch.uid)
185+
expect(response.merge_details.compare_branch).to.be.equal(stageBranch.uid)
186+
done()
187+
})
188+
.catch(done)
189+
})
190+
191+
it('should list all recent merge jobs', done => {
192+
makeBranch()
193+
.mergeQueue()
194+
.find()
195+
.then((response) => {
196+
expect(response.queue).to.not.equal(undefined)
197+
expect(response.queue[0].merge_details.base_branch).to.be.equal(branch.uid)
198+
expect(response.queue[0].merge_details.compare_branch).to.be.equal(stageBranch.uid)
199+
done()
200+
})
201+
.catch(done)
202+
})
203+
204+
it('should list details of merge job when job uid is passed', done => {
205+
makeBranch()
206+
.mergeQueue(mergeJobUid)
207+
.fetch()
208+
.then((response) => {
209+
expect(response.queue).to.not.equal(undefined)
210+
expect(response.queue[0].merge_details.base_branch).to.be.equal(branch.uid)
211+
expect(response.queue[0].merge_details.compare_branch).to.be.equal(stageBranch.uid)
212+
done()
213+
})
214+
.catch(done)
215+
})
216+
})
217+
218+
function makeBranch (uid = null) {
219+
return client.stack({ api_key: process.env.API_KEY }).branch(uid)
220+
}
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
import { stageBranch } from '../mock/branch.js'
6+
7+
var client = {}
8+
9+
describe('Branch Alias api Test', () => {
10+
setup(() => {
11+
const user = jsonReader('loggedinuser.json')
12+
client = contentstackClient(user.authtoken)
13+
})
14+
15+
it('Should create Branch Alias', done => {
16+
makeBranchAlias(`${stageBranch.uid}_alias`)
17+
.createOrUpdate(stageBranch.uid)
18+
.then((response) => {
19+
expect(response.uid).to.be.equal(stageBranch.uid)
20+
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
21+
expect(response.source).to.be.equal(stageBranch.source)
22+
expect(response.alias).to.be.equal(`${stageBranch.uid}_alias`)
23+
expect(response.delete).to.not.equal(undefined)
24+
expect(response.fetch).to.not.equal(undefined)
25+
done()
26+
})
27+
.catch(done)
28+
})
29+
30+
it('Branch query should return master branch', done => {
31+
makeBranchAlias()
32+
.fetchAll({ query: { uid: stageBranch.uid } })
33+
.then((response) => {
34+
expect(response.items.length).to.be.equal(1)
35+
var item = response.items[0]
36+
expect(item.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
37+
expect(item.delete).to.not.equal(undefined)
38+
expect(item.fetch).to.not.equal(undefined)
39+
done()
40+
})
41+
.catch(done)
42+
})
43+
44+
it('Should fetch Branch Alias', done => {
45+
makeBranchAlias(`${stageBranch.uid}_alias`)
46+
.fetch()
47+
.then((response) => {
48+
expect(response.uid).to.be.equal(stageBranch.uid)
49+
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
50+
expect(response.source).to.be.equal(stageBranch.source)
51+
expect(response.alias).to.be.equal(`${stageBranch.uid}_alias`)
52+
expect(response.delete).to.not.equal(undefined)
53+
expect(response.fetch).to.not.equal(undefined)
54+
done()
55+
})
56+
.catch(done)
57+
})
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+
})
81+
})
82+
83+
function makeBranchAlias (uid = null) {
84+
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid)
85+
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { jsonReader } from '../utility/fileOperations/readwrite'
44
import { contentstackClient } from '../utility/ContentstackClient.js'
55

66
var client = {}
7-
var stack = {}
87

98
const taxonomy = {
109
uid: 'taxonomy_testing',
@@ -17,7 +16,6 @@ var taxonomyUID = ''
1716
describe('taxonomy api Test', () => {
1817
setup(() => {
1918
const user = jsonReader('loggedinuser.json')
20-
stack = jsonReader('stack.json')
2119
client = contentstackClient(user.authtoken)
2220
})
2321

@@ -82,5 +80,5 @@ describe('taxonomy api Test', () => {
8280
})
8381

8482
function makeTaxonomy (uid = null) {
85-
return client.stack({ api_key: stack.api_key }).taxonomy(uid)
83+
return client.stack({ api_key: process.env.API_KEY }).taxonomy(uid)
8684
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const branch = {
2+
uid: 'main',
3+
source: ''
4+
}
5+
6+
const stageBranch = {
7+
uid: 'staging',
8+
source: 'main'
9+
}
10+
11+
const devBranch = {
12+
uid: 'merge_test',
13+
source: 'staging'
14+
}
15+
16+
export {
17+
branch,
18+
stageBranch,
19+
devBranch
20+
}

‎test/sanity-check/sanity.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require('./api/user-test')
22
require('./api/organization-test')
33
require('./api/stack-test')
4+
require('./api/branch-test')
5+
require('./api/branchAlias-test')
46
require('./api/contentType-test')
57
require('./api/asset-test')
68
require('./api/entry-test')

0 commit comments

Comments
 (0)
Please sign in to comment.