-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from contentstack/test/cs-43284-sanity-tests-…
…branches-aliases cs-43284 sanity tests for branches aliases
- Loading branch information
Showing
8 changed files
with
343 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
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 return master branch when query is called', done => { | ||
makeBranch() | ||
.query() | ||
.find() | ||
.then((response) => { | ||
expect(response.items.length).to.be.equal(1) | ||
var item = response.items[0] | ||
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) | ||
expect(item.delete).to.not.equal(undefined) | ||
expect(item.fetch).to.not.equal(undefined) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should create staging branch', done => { | ||
makeBranch() | ||
.create({ branch: stageBranch }) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(stageBranch.uid) | ||
expect(response.urlPath).to.be.equal(`/stacks/branches/${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 fetch stage branch from branch uid', done => { | ||
makeBranch(branch.uid) | ||
.fetch() | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(branch.uid) | ||
expect(response.urlPath).to.be.equal(`/stacks/branches/${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 create Branch from staging', done => { | ||
makeBranch() | ||
.create({ branch: devBranch }) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(devBranch.uid) | ||
expect(response.urlPath).to.be.equal(`/stacks/branches/${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) | ||
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.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) | ||
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) => { | ||
expect(response.items.length).to.be.equal(3) | ||
response.items.forEach(item => { | ||
expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) | ||
expect(item.delete).to.not.equal(undefined) | ||
expect(item.fetch).to.not.equal(undefined) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should delete branch from branch uid', done => { | ||
makeBranch(devBranch.uid) | ||
.delete() | ||
.then((response) => { | ||
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.') | ||
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', done => { | ||
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' | ||
} | ||
] | ||
} | ||
makeBranch() | ||
.merge(mergeObj, params) | ||
.then((response) => { | ||
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) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
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) | ||
}) | ||
}) | ||
|
||
function makeBranch (uid = null) { | ||
return client.stack({ api_key: process.env.API_KEY }).branch(uid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { expect } from 'chai' | ||
import { describe, it, setup } from 'mocha' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
import { stageBranch } from '../mock/branch.js' | ||
|
||
var client = {} | ||
|
||
describe('Branch Alias api Test', () => { | ||
setup(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
|
||
it('Should create Branch Alias', done => { | ||
makeBranchAlias(`${stageBranch.uid}_alias`) | ||
.createOrUpdate(stageBranch.uid) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(stageBranch.uid) | ||
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`) | ||
expect(response.source).to.be.equal(stageBranch.source) | ||
expect(response.alias).to.be.equal(`${stageBranch.uid}_alias`) | ||
expect(response.delete).to.not.equal(undefined) | ||
expect(response.fetch).to.not.equal(undefined) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Branch query should return master branch', done => { | ||
makeBranchAlias() | ||
.fetchAll({ query: { uid: stageBranch.uid } }) | ||
.then((response) => { | ||
expect(response.items.length).to.be.equal(1) | ||
var item = response.items[0] | ||
expect(item.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`) | ||
expect(item.delete).to.not.equal(undefined) | ||
expect(item.fetch).to.not.equal(undefined) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Should fetch Branch Alias', done => { | ||
makeBranchAlias(`${stageBranch.uid}_alias`) | ||
.fetch() | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(stageBranch.uid) | ||
expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`) | ||
expect(response.source).to.be.equal(stageBranch.source) | ||
expect(response.alias).to.be.equal(`${stageBranch.uid}_alias`) | ||
expect(response.delete).to.not.equal(undefined) | ||
expect(response.fetch).to.not.equal(undefined) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Should delete Branch Alias', done => { | ||
try { | ||
makeBranchAlias(`${stageBranch.uid}_alias`) | ||
.delete() | ||
.then((response) => { | ||
expect(response.notice).to.be.equal('Branch alias deleted successfully.') | ||
done() | ||
}) | ||
.catch(done) | ||
} catch (e) { | ||
done() | ||
} | ||
}) | ||
it('Should delete stage branch from uid', done => { | ||
client.stack({ api_key: process.env.API_KEY }).branch(stageBranch.uid) | ||
.delete() | ||
.then((response) => { | ||
expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeBranchAlias (uid = null) { | ||
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,19 +61,19 @@ describe('Organization api test', () => { | |
}) | ||
.catch(done) | ||
}) | ||
// need to test with transfer ownership | ||
it.skip('should transfer Organization Ownership', done => { | ||
organization.transferOwnership('[email protected]') | ||
.then((data) => { | ||
expect(data.notice).to.be.equal('Email has been successfully sent to the user.', 'Message does not match') | ||
done() | ||
}) | ||
.catch((error) => { | ||
console.log(error) | ||
expect(error).to.be.equal(null, 'Failed Transfer Organization Ownership') | ||
done() | ||
}) | ||
}) | ||
|
||
// it('should transfer Organization Ownership', done => { | ||
// organization.transferOwnership('[email protected]') | ||
// .then((data) => { | ||
// expect(data.notice).to.be.equal('Email has been successfully sent to the user.', 'Message does not match') | ||
// done() | ||
// }) | ||
// .catch((error) => { | ||
// console.log(error) | ||
// expect(error).to.be.equal(null, 'Failed Transfer Organization Ownership') | ||
// done() | ||
// }) | ||
// }) | ||
|
||
it('should get all roles in an organization', done => { | ||
organization.roles() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const branch = { | ||
uid: 'main', | ||
source: '' | ||
} | ||
|
||
const stageBranch = { | ||
uid: 'staging', | ||
source: 'main' | ||
} | ||
|
||
const devBranch = { | ||
uid: 'merge_test', | ||
source: 'staging' | ||
} | ||
|
||
export { | ||
branch, | ||
stageBranch, | ||
devBranch | ||
} |
Oops, something went wrong.