|
| 1 | +import { expect } from 'chai' |
| 2 | +import { describe, it, setup } from 'mocha' |
| 3 | +import { jsonReader } from '../utility/fileOperations/readwrite' |
| 4 | +import { contentstackClient } from '../utility/ContentstackClient.js' |
| 5 | +import { branch, stageBranch, devBranch } from '../mock/branch.js' |
| 6 | + |
| 7 | +var client = {} |
| 8 | +var mergeJobUid = '' |
| 9 | +describe('Branch api Test', () => { |
| 10 | + setup(() => { |
| 11 | + const user = jsonReader('loggedinuser.json') |
| 12 | + client = contentstackClient(user.authtoken) |
| 13 | + }) |
| 14 | + |
| 15 | + it('should return master branch when query is called', done => { |
| 16 | + makeBranch() |
| 17 | + .query() |
| 18 | + .find() |
| 19 | + .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) |
| 25 | + done() |
| 26 | + }) |
| 27 | + .catch(done) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should create staging branch', done => { |
| 31 | + makeBranch() |
| 32 | + .create({ branch: stageBranch }) |
| 33 | + .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) |
| 40 | + done() |
| 41 | + }) |
| 42 | + .catch(done) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should fetch stage branch from branch uid', done => { |
| 46 | + makeBranch(branch.uid) |
| 47 | + .fetch() |
| 48 | + .then((response) => { |
| 49 | + expect(response.uid).to.be.equal(branch.uid) |
| 50 | + expect(response.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`) |
| 51 | + expect(response.source).to.be.equal(branch.source) |
| 52 | + expect(response.alias).to.not.equal(undefined) |
| 53 | + expect(response.delete).to.not.equal(undefined) |
| 54 | + expect(response.fetch).to.not.equal(undefined) |
| 55 | + done() |
| 56 | + }) |
| 57 | + .catch(done) |
| 58 | + }) |
| 59 | + |
| 60 | + it('should create Branch from staging', done => { |
| 61 | + makeBranch() |
| 62 | + .create({ branch: devBranch }) |
| 63 | + .then((response) => { |
| 64 | + expect(response.uid).to.be.equal(devBranch.uid) |
| 65 | + expect(response.urlPath).to.be.equal(`/stacks/branches/${devBranch.uid}`) |
| 66 | + expect(response.source).to.be.equal(devBranch.source) |
| 67 | + expect(response.alias).to.not.equal(undefined) |
| 68 | + expect(response.delete).to.not.equal(undefined) |
| 69 | + expect(response.fetch).to.not.equal(undefined) |
| 70 | + done() |
| 71 | + }) |
| 72 | + .catch(done) |
| 73 | + }) |
| 74 | + |
| 75 | + it('should query branch for specific condition', done => { |
| 76 | + makeBranch() |
| 77 | + .query({ query: { source: 'main' } }) |
| 78 | + .find() |
| 79 | + .then((response) => { |
| 80 | + expect(response.items.length).to.be.equal(1) |
| 81 | + response.items.forEach(item => { |
| 82 | + expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) |
| 83 | + expect(item.source).to.be.equal(`main`) |
| 84 | + expect(item.delete).to.not.equal(undefined) |
| 85 | + expect(item.fetch).to.not.equal(undefined) |
| 86 | + }) |
| 87 | + done() |
| 88 | + }) |
| 89 | + .catch(done) |
| 90 | + }) |
| 91 | + |
| 92 | + it('should query branch to return all branches', done => { |
| 93 | + makeBranch() |
| 94 | + .query() |
| 95 | + .find() |
| 96 | + .then((response) => { |
| 97 | + expect(response.items.length).to.be.equal(3) |
| 98 | + response.items.forEach(item => { |
| 99 | + expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) |
| 100 | + expect(item.delete).to.not.equal(undefined) |
| 101 | + expect(item.fetch).to.not.equal(undefined) |
| 102 | + }) |
| 103 | + done() |
| 104 | + }) |
| 105 | + .catch(done) |
| 106 | + }) |
| 107 | + |
| 108 | + it('should delete branch from branch uid', done => { |
| 109 | + makeBranch(devBranch.uid) |
| 110 | + .delete() |
| 111 | + .then((response) => { |
| 112 | + expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.') |
| 113 | + done() |
| 114 | + }) |
| 115 | + .catch(done) |
| 116 | + }) |
| 117 | + |
| 118 | + it('should provide list of content types and global fields that exist in only one branch or are different between the two branches', done => { |
| 119 | + makeBranch(branch.uid) |
| 120 | + .compare(stageBranch.uid) |
| 121 | + .all() |
| 122 | + .then((response) => { |
| 123 | + expect(response.branches.base_branch).to.be.equal(branch.uid) |
| 124 | + expect(response.branches.compare_branch).to.be.equal(stageBranch.uid) |
| 125 | + done() |
| 126 | + }) |
| 127 | + .catch(done) |
| 128 | + }) |
| 129 | + |
| 130 | + it('should list differences for a content types between two branches', done => { |
| 131 | + makeBranch(branch.uid) |
| 132 | + .compare(stageBranch.uid) |
| 133 | + .contentTypes() |
| 134 | + .then((response) => { |
| 135 | + expect(response.branches.base_branch).to.be.equal(branch.uid) |
| 136 | + expect(response.branches.compare_branch).to.be.equal(stageBranch.uid) |
| 137 | + done() |
| 138 | + }) |
| 139 | + .catch(done) |
| 140 | + }) |
| 141 | + |
| 142 | + it('should list differences for a global fields between two branches', done => { |
| 143 | + makeBranch(branch.uid) |
| 144 | + .compare(stageBranch.uid) |
| 145 | + .globalFields() |
| 146 | + .then((response) => { |
| 147 | + expect(response.branches.base_branch).to.be.equal(branch.uid) |
| 148 | + expect(response.branches.compare_branch).to.be.equal(stageBranch.uid) |
| 149 | + done() |
| 150 | + }) |
| 151 | + .catch(done) |
| 152 | + }) |
| 153 | + |
| 154 | + it('should merge given two branches', done => { |
| 155 | + const params = { |
| 156 | + base_branch: branch.uid, |
| 157 | + compare_branch: stageBranch.uid, |
| 158 | + default_merge_strategy: 'ignore', |
| 159 | + merge_comment: 'Merging staging into main' |
| 160 | + } |
| 161 | + const mergeObj = { |
| 162 | + item_merge_strategies: [ |
| 163 | + { |
| 164 | + uid: 'global_field_uid', |
| 165 | + type: 'global_field', |
| 166 | + merge_strategy: 'merge_prefer_base' |
| 167 | + }, |
| 168 | + { |
| 169 | + uid: 'ct5', |
| 170 | + type: 'content_type', |
| 171 | + merge_strategy: 'merge_prefer_compare' |
| 172 | + }, |
| 173 | + { |
| 174 | + uid: 'bot_all', |
| 175 | + type: 'content_type', |
| 176 | + merge_strategy: 'merge_prefer_base' |
| 177 | + } |
| 178 | + ] |
| 179 | + } |
| 180 | + makeBranch() |
| 181 | + .merge(mergeObj, params) |
| 182 | + .then((response) => { |
| 183 | + mergeJobUid = response.uid |
| 184 | + expect(response.merge_details.base_branch).to.be.equal(branch.uid) |
| 185 | + expect(response.merge_details.compare_branch).to.be.equal(stageBranch.uid) |
| 186 | + done() |
| 187 | + }) |
| 188 | + .catch(done) |
| 189 | + }) |
| 190 | + |
| 191 | + it('should list all recent merge jobs', done => { |
| 192 | + makeBranch() |
| 193 | + .mergeQueue() |
| 194 | + .find() |
| 195 | + .then((response) => { |
| 196 | + expect(response.queue).to.not.equal(undefined) |
| 197 | + expect(response.queue[0].merge_details.base_branch).to.be.equal(branch.uid) |
| 198 | + expect(response.queue[0].merge_details.compare_branch).to.be.equal(stageBranch.uid) |
| 199 | + done() |
| 200 | + }) |
| 201 | + .catch(done) |
| 202 | + }) |
| 203 | + |
| 204 | + it('should list details of merge job when job uid is passed', done => { |
| 205 | + makeBranch() |
| 206 | + .mergeQueue(mergeJobUid) |
| 207 | + .fetch() |
| 208 | + .then((response) => { |
| 209 | + expect(response.queue).to.not.equal(undefined) |
| 210 | + expect(response.queue[0].merge_details.base_branch).to.be.equal(branch.uid) |
| 211 | + expect(response.queue[0].merge_details.compare_branch).to.be.equal(stageBranch.uid) |
| 212 | + done() |
| 213 | + }) |
| 214 | + .catch(done) |
| 215 | + }) |
| 216 | +}) |
| 217 | + |
| 218 | +function makeBranch (uid = null) { |
| 219 | + return client.stack({ api_key: process.env.API_KEY }).branch(uid) |
| 220 | +} |
0 commit comments