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 122b4db

Browse files
committedJan 9, 2024
test: added create branch test after stack creation test
1 parent 11c4d74 commit 122b4db

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed
 

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

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

15-
it('should return master branch when query is called', done => {
15+
it('should create Branch from staging', done => {
1616
makeBranch()
17-
.query()
18-
.find()
17+
.create({ branch: devBranch })
1918
.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)
19+
expect(response.uid).to.be.equal(devBranch.uid)
20+
expect(response.urlPath).to.be.equal(`/stacks/branches/${devBranch.uid}`)
21+
expect(response.source).to.be.equal(devBranch.source)
22+
expect(response.alias).to.not.equal(undefined)
23+
expect(response.delete).to.not.equal(undefined)
24+
expect(response.fetch).to.not.equal(undefined)
2525
done()
2626
})
2727
.catch(done)
2828
})
2929

30-
it('should create staging branch', done => {
30+
it('should return master branch when query is called', done => {
3131
makeBranch()
32-
.create({ branch: stageBranch })
32+
.query()
33+
.find()
3334
.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)
35+
var item = response.items[0]
36+
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`)
37+
expect(item.delete).to.not.equal(undefined)
38+
expect(item.fetch).to.not.equal(undefined)
4039
done()
4140
})
4241
.catch(done)
@@ -72,21 +71,6 @@ describe('Branch api Test', () => {
7271
.catch(done)
7372
})
7473

75-
it('should create Branch from staging', done => {
76-
makeBranch()
77-
.create({ branch: devBranch })
78-
.then((response) => {
79-
expect(response.uid).to.be.equal(devBranch.uid)
80-
expect(response.urlPath).to.be.equal(`/stacks/branches/${devBranch.uid}`)
81-
expect(response.source).to.be.equal(devBranch.source)
82-
expect(response.alias).to.not.equal(undefined)
83-
expect(response.delete).to.not.equal(undefined)
84-
expect(response.fetch).to.not.equal(undefined)
85-
done()
86-
})
87-
.catch(done)
88-
})
89-
9074
it('should query branch for specific condition', done => {
9175
makeBranch()
9276
.query({ query: { source: 'main' } })

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

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { expect } from 'chai'
22
import { describe, it, setup } from 'mocha'
33
import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite'
44
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
import { stageBranch } from '../mock/branch.js'
6+
57
import dotenv from 'dotenv'
68
dotenv.config()
79

@@ -156,3 +158,29 @@ describe('Stack api Test', () => {
156158
.catch(done)
157159
})
158160
})
161+
162+
describe('Branch creation api Test', () => {
163+
setup(() => {
164+
const user = jsonReader('loggedinuser.json')
165+
client = contentstackClient(user.authtoken)
166+
})
167+
168+
it('should create staging branch', done => {
169+
makeBranch()
170+
.create({ branch: stageBranch })
171+
.then((response) => {
172+
expect(response.uid).to.be.equal(stageBranch.uid)
173+
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`)
174+
expect(response.source).to.be.equal(stageBranch.source)
175+
expect(response.alias).to.not.equal(undefined)
176+
expect(response.delete).to.not.equal(undefined)
177+
expect(response.fetch).to.not.equal(undefined)
178+
done()
179+
})
180+
.catch(done)
181+
})
182+
})
183+
184+
function makeBranch (uid = null) {
185+
return client.stack({ api_key: process.env.API_KEY }).branch(uid)
186+
}

‎test/sanity-check/sanity.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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')
64
require('./api/contentType-test')
75
require('./api/asset-test')
86
require('./api/entry-test')
7+
require('./api/branch-test')
8+
require('./api/branchAlias-test')
99
require('./api/contentType-delete-test')
1010
require('./api/taxonomy-test')
1111
require('./api/terms-test')

0 commit comments

Comments
 (0)
Please sign in to comment.