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