-
Notifications
You must be signed in to change notification settings - Fork 9
cs-43284 sanity tests for branches aliases #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harshithad0703
merged 5 commits into
next
from
test/cs-43284-sanity-tests-branches-aliases
Jan 5, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2f32924
fix: changed the url in transferOwnership
harshithad0703 2e38341
test: removed the skipped test case from organization test suit
harshithad0703 258b3a9
test: added branches and aliases test suits to sanity folder
harshithad0703 ca58beb
test: commented out the test case instead or removing
harshithad0703 941b9e9
test: updated url path in unit test case
harshithad0703 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.