11/**
22 * Branch API Tests
3- *
3+ *
44 * Comprehensive test suite for:
55 * - Branch CRUD operations
66 * - Branch compare
1212import { expect } from 'chai'
1313import { describe , it , before , after } from 'mocha'
1414import { contentstackClient } from '../utility/ContentstackClient.js'
15- import {
16- developmentBranch ,
17- featureBranch ,
18- branchCompare ,
19- branchMerge ,
20- branchAlias ,
21- branchAliasUpdate
22- } from '../mock/configurations.js'
2315import { validateBranchResponse , testData , wait , shortId , trackedExpect } from '../utility/testHelpers.js'
2416
2517describe ( 'Branch API Tests' , ( ) => {
@@ -37,8 +29,7 @@ describe('Branch API Tests', () => {
3729
3830 describe ( 'Branch CRUD Operations' , ( ) => {
3931 // Branch UID must be max 15 chars, only lowercase and numbers
40- let devBranchUid = `dev${ shortId ( ) } `
41- let createdBranch
32+ const devBranchUid = `dev${ shortId ( ) } `
4233 let branchCreated = false
4334
4435 after ( async ( ) => {
@@ -63,7 +54,7 @@ describe('Branch API Tests', () => {
6354
6455 it ( 'should create a development branch from main' , async function ( ) {
6556 this . timeout ( 30000 )
66-
57+
6758 const branchData = {
6859 branch : {
6960 uid : devBranchUid ,
@@ -82,18 +73,16 @@ describe('Branch API Tests', () => {
8273 trackedExpect ( branch . uid , 'Branch UID' ) . toEqual ( devBranchUid )
8374 expect ( branch . source ) . to . equal ( 'main' )
8475
85- createdBranch = branch
8676 branchCreated = true
8777 testData . branches . development = branch
88-
78+
8979 // Wait for branch to be fully ready
9080 await wait ( 3000 )
9181 } catch ( error ) {
9282 // If branch already exists (409), try to fetch it
9383 if ( error . status === 409 || ( error . errorMessage && error . errorMessage . includes ( 'already exists' ) ) ) {
9484 console . log ( ` Branch ${ devBranchUid } already exists, fetching it` )
9585 const existing = await stack . branch ( devBranchUid ) . fetch ( )
96- createdBranch = existing
9786 branchCreated = true
9887 testData . branches . development = existing
9988 } else {
@@ -105,13 +94,13 @@ describe('Branch API Tests', () => {
10594
10695 it ( 'should fetch the created branch' , async function ( ) {
10796 this . timeout ( 15000 )
108-
97+
10998 if ( ! branchCreated ) {
11099 console . log ( ' Skipping - branch was not created' )
111100 this . skip ( )
112101 return
113102 }
114-
103+
115104 const response = await stack . branch ( devBranchUid ) . fetch ( )
116105
117106 expect ( response ) . to . be . an ( 'object' )
@@ -124,7 +113,7 @@ describe('Branch API Tests', () => {
124113 this . skip ( )
125114 return
126115 }
127-
116+
128117 const branch = await stack . branch ( devBranchUid ) . fetch ( )
129118
130119 expect ( branch . uid ) . to . be . a ( 'string' )
@@ -274,7 +263,6 @@ describe('Branch API Tests', () => {
274263 // ==========================================================================
275264
276265 describe ( 'Error Handling' , ( ) => {
277-
278266 it ( 'should fail to create branch with duplicate UID' , async ( ) => {
279267 // Main branch always exists
280268 try {
@@ -329,9 +317,8 @@ describe('Branch API Tests', () => {
329317 // ==========================================================================
330318
331319 describe ( 'Delete Branch' , ( ) => {
332-
333320 // Helper to wait for branch to be ready (with polling)
334- async function waitForBranchReady ( branchUid , maxAttempts = 10 ) {
321+ async function waitForBranchReady ( branchUid , maxAttempts = 10 ) {
335322 for ( let i = 0 ; i < maxAttempts ; i ++ ) {
336323 try {
337324 const branch = await stack . branch ( branchUid ) . fetch ( )
@@ -357,7 +344,7 @@ describe('Branch API Tests', () => {
357344 source : 'main'
358345 }
359346 } )
360-
347+
361348 // Wait for branch to be fully created (15 seconds like old tests)
362349 await wait ( 15000 )
363350
@@ -380,14 +367,14 @@ describe('Branch API Tests', () => {
380367 source : 'main'
381368 }
382369 } )
383-
370+
384371 // Wait for branch to be fully created (15 seconds like old tests)
385372 await wait ( 15000 )
386373
387374 // Poll until branch is ready
388375 const branch = await waitForBranchReady ( tempBranchUid , 5 )
389376 await branch . delete ( )
390-
377+
391378 // Wait for deletion to propagate
392379 await wait ( 5000 )
393380
0 commit comments