From 2f32924413da13c1b16f15d32e92ced944d34e93 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 5 Jan 2024 11:10:08 +0530 Subject: [PATCH 1/5] fix: changed the url in transferOwnership --- lib/organization/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/organization/index.js b/lib/organization/index.js index 725bd65a..98ce0f5a 100644 --- a/lib/organization/index.js +++ b/lib/organization/index.js @@ -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 { From 2e383413bf9214ae530be28be0a7368b5023d0f7 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 5 Jan 2024 11:52:59 +0530 Subject: [PATCH 2/5] test: removed the skipped test case from organization test suit --- test/sanity-check/api/organization-test.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/sanity-check/api/organization-test.js b/test/sanity-check/api/organization-test.js index 96ce9852..4399384c 100644 --- a/test/sanity-check/api/organization-test.js +++ b/test/sanity-check/api/organization-test.js @@ -61,19 +61,6 @@ describe('Organization api test', () => { }) .catch(done) }) - // need to test with transfer ownership - it.skip('should transfer Organization Ownership', done => { - organization.transferOwnership('em@em.com') - .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() From 258b3a9128c322a63c3c6e2460b8798474f755e9 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 5 Jan 2024 11:54:27 +0530 Subject: [PATCH 3/5] test: added branches and aliases test suits to sanity folder --- test/sanity-check/api/branch-test.js | 220 ++++++++++++++++++++++ test/sanity-check/api/branchAlias-test.js | 85 +++++++++ test/sanity-check/api/taxonomy-test.js | 4 +- test/sanity-check/mock/branch.js | 20 ++ test/sanity-check/sanity.js | 2 + 5 files changed, 328 insertions(+), 3 deletions(-) create mode 100644 test/sanity-check/api/branch-test.js create mode 100644 test/sanity-check/api/branchAlias-test.js create mode 100644 test/sanity-check/mock/branch.js diff --git a/test/sanity-check/api/branch-test.js b/test/sanity-check/api/branch-test.js new file mode 100644 index 00000000..3f3759a3 --- /dev/null +++ b/test/sanity-check/api/branch-test.js @@ -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) +} diff --git a/test/sanity-check/api/branchAlias-test.js b/test/sanity-check/api/branchAlias-test.js new file mode 100644 index 00000000..41aa4b78 --- /dev/null +++ b/test/sanity-check/api/branchAlias-test.js @@ -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) +} diff --git a/test/sanity-check/api/taxonomy-test.js b/test/sanity-check/api/taxonomy-test.js index 3deb99aa..fcff1f47 100644 --- a/test/sanity-check/api/taxonomy-test.js +++ b/test/sanity-check/api/taxonomy-test.js @@ -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', @@ -17,7 +16,6 @@ var taxonomyUID = '' describe('taxonomy api Test', () => { setup(() => { const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') client = contentstackClient(user.authtoken) }) @@ -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) } diff --git a/test/sanity-check/mock/branch.js b/test/sanity-check/mock/branch.js new file mode 100644 index 00000000..3016c0a3 --- /dev/null +++ b/test/sanity-check/mock/branch.js @@ -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 +} diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index 7e3581a6..e3a67116 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -1,6 +1,8 @@ require('./api/user-test') require('./api/organization-test') require('./api/stack-test') +require('./api/branch-test') +require('./api/branchAlias-test') require('./api/contentType-test') require('./api/asset-test') require('./api/entry-test') From ca58beb3a81b7bff51bd34944c9fc42ad7f03efb Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 5 Jan 2024 12:00:13 +0530 Subject: [PATCH 4/5] test: commented out the test case instead or removing --- test/sanity-check/api/organization-test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/sanity-check/api/organization-test.js b/test/sanity-check/api/organization-test.js index 4399384c..7e1f2b8f 100644 --- a/test/sanity-check/api/organization-test.js +++ b/test/sanity-check/api/organization-test.js @@ -62,6 +62,19 @@ describe('Organization api test', () => { .catch(done) }) + // it('should transfer Organization Ownership', done => { + // organization.transferOwnership('em@em.com') + // .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() .then((roles) => { From 941b9e9d1324c491129cb5f20818ffec41861274 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 5 Jan 2024 12:06:31 +0530 Subject: [PATCH 5/5] test: updated url path in unit test case --- test/unit/organization-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/organization-test.js b/test/unit/organization-test.js index be278013..f2340ffd 100644 --- a/test/unit/organization-test.js +++ b/test/unit/organization-test.js @@ -176,7 +176,7 @@ describe('Organization Test', () => { it('Organization Transfer Ownership', done => { const mock = new MockAdapter(Axios) - mock.onPost(`/organizations/${systemUidMock.uid}/transfer_ownership`).reply(200, { ...noticeMock }) + mock.onPost(`/organizations/${systemUidMock.uid}/transfer-ownership`).reply(200, { ...noticeMock }) makeOrganization({ organization: { ...systemUidMock,