Skip to content

Commit

Permalink
Merge pull request #105 from contentstack/test/cs-43284-sanity-tests-…
Browse files Browse the repository at this point in the history
…branches-aliases

cs-43284 sanity tests for branches aliases
  • Loading branch information
harshithad0703 authored Jan 5, 2024
2 parents 3c4ba30 + 941b9e9 commit f7128e7
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/organization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function Organization (http, data) {
*/
this.transferOwnership = async (email) => {
try {
const response = await http.post(`${this.urlPath}/transfer_ownership`, { transfer_to: email })
const response = await http.post(`${this.urlPath}/transfer-ownership`, { transfer_to: email })
if (response.data) {
return response.data
} else {
Expand Down
220 changes: 220 additions & 0 deletions test/sanity-check/api/branch-test.js
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)
}
85 changes: 85 additions & 0 deletions test/sanity-check/api/branchAlias-test.js
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)
}
26 changes: 13 additions & 13 deletions test/sanity-check/api/organization-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions test/sanity-check/api/taxonomy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { jsonReader } from '../utility/fileOperations/readwrite'
import { contentstackClient } from '../utility/ContentstackClient.js'

var client = {}
var stack = {}

const taxonomy = {
uid: 'taxonomy_testing',
Expand All @@ -17,7 +16,6 @@ var taxonomyUID = ''
describe('taxonomy api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
stack = jsonReader('stack.json')
client = contentstackClient(user.authtoken)
})

Expand Down Expand Up @@ -82,5 +80,5 @@ describe('taxonomy api Test', () => {
})

function makeTaxonomy (uid = null) {
return client.stack({ api_key: stack.api_key }).taxonomy(uid)
return client.stack({ api_key: process.env.API_KEY }).taxonomy(uid)
}
20 changes: 20 additions & 0 deletions test/sanity-check/mock/branch.js
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
}
Loading

0 comments on commit f7128e7

Please sign in to comment.