Skip to content

Commit 474976f

Browse files
committed
fix(sanity): asset/bulk AM 2.0, branch merge, testHelpers
- asset-test: allow am/blt UID format; stop deleting HTML/bufferUpload per test so bulk has valid assets - branch-test: use stack.branch().mergeQueue()/merge() correctly; 10s wait; store branches in testData; handle 409 on create - bulkOperation-test: require assets via assetsWithValidUids(), fail when none (no skip) - testHelpers: validateAssetResponse accepts (blt|am) UID prefix - .talismanrc: update bulkOperation-test.js checksum
1 parent 4bfc6af commit 474976f

File tree

5 files changed

+78
-96
lines changed

5 files changed

+78
-96
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fileignoreconfig:
9494
- filename: test/sanity-check/api/contentType-test.js
9595
checksum: 4d5178998f9f3c27550c5bd21540e254e08f79616e8615e7256ba2175cb4c8e1
9696
- filename: test/sanity-check/api/bulkOperation-test.js
97-
checksum: 1721c0e0f5b79a46fba21bfbedc3a87db4715bc97cd064f2361d35ab453b890c
97+
checksum: 8dd642da1152d84eeb949022c6b25bbd8b0e43b4399a37f06af786aa3139cd88
9898
- filename: test/sanity-check/api/entry-test.js
9999
checksum: 9dc16b404a98ff9fa2c164fad0182b291b9c338dd58558dc5ef8dd75cf18bc1f
100100
- filename: test/sanity-check/api/entryVariants-test.js

test/sanity-check/api/asset-test.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ describe('Asset API Tests', () => {
8484
expect(asset.content_type).to.include('html')
8585

8686
testData.assets.html = asset
87-
88-
// Cleanup
89-
try {
90-
await stack.asset(asset.uid).delete()
91-
} catch (e) { }
87+
// Do not delete: bulk operation tests depend on this asset (Phase 21)
9288
})
9389

9490
it('should upload asset from buffer', async function () {
@@ -114,11 +110,7 @@ describe('Asset API Tests', () => {
114110
expect(asset.content_type).to.be.a('string')
115111

116112
testData.assets.bufferUpload = asset
117-
118-
// Cleanup
119-
try {
120-
await stack.asset(asset.uid).delete()
121-
} catch (e) { }
113+
// Do not delete: bulk operation tests depend on this asset (Phase 21)
122114
})
123115

124116
it('should fail to upload without file', async () => {
@@ -187,7 +179,7 @@ describe('Asset API Tests', () => {
187179
const asset = await stack.asset(assetUid).fetch()
188180

189181
// Required fields
190-
expect(asset.uid).to.be.a('string').and.match(/^blt[a-f0-9]+$/)
182+
expect(asset.uid).to.be.a('string').and.match(/^(blt|am)[a-f0-9]+$/)
191183
expect(asset.filename).to.be.a('string')
192184
expect(asset.url).to.be.a('string')
193185
expect(asset.content_type).to.be.a('string')

test/sanity-check/api/branch-test.js

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { expect } from 'chai'
1313
import { describe, it, before, after } from 'mocha'
1414
import { contentstackClient } from '../utility/ContentstackClient.js'
15-
import { validateBranchResponse, testData, wait, shortId, trackedExpect } from '../utility/testHelpers.js'
15+
import { validateBranchResponse, testData, wait, shortId, trackedExpect, LONG_DELAY } from '../utility/testHelpers.js'
1616

1717
describe('Branch API Tests', () => {
1818
let client
@@ -76,8 +76,8 @@ describe('Branch API Tests', () => {
7676
branchCreated = true
7777
testData.branches.development = branch
7878

79-
// Wait for branch to be fully ready
80-
await wait(3000)
79+
// Wait for branch to be fully ready (can take 10+ seconds to reflect)
80+
await wait(LONG_DELAY)
8181
} catch (error) {
8282
// If branch already exists (409), try to fetch it
8383
if (error.status === 409 || (error.errorMessage && error.errorMessage.includes('already exists'))) {
@@ -135,20 +135,26 @@ describe('Branch API Tests', () => {
135135

136136
before(async function () {
137137
this.timeout(60000)
138-
// Create a branch for comparison
138+
// Create a branch for comparison (uid stored for dependent tests)
139139
compareBranchUid = `cmp${shortId()}`
140140

141141
try {
142-
await stack.branch().create({
142+
const branch = await stack.branch().create({
143143
branch: {
144144
uid: compareBranchUid,
145145
source: 'main'
146146
}
147147
})
148-
// Wait for branch to be fully ready before compare operations
149-
await wait(2000)
148+
testData.branches.compare = branch
149+
// Wait for branch to be fully ready (can take 10+ seconds to reflect)
150+
await wait(LONG_DELAY)
150151
} catch (error) {
151-
console.log('Branch creation failed:', error.errorMessage)
152+
if (error.status === 409 || (error.errorMessage && error.errorMessage.includes('already exists'))) {
153+
const existing = await stack.branch(compareBranchUid).fetch()
154+
testData.branches.compare = existing
155+
} else {
156+
console.log('Branch creation failed:', error.message || error.errorMessage)
157+
}
152158
}
153159
})
154160

@@ -206,20 +212,26 @@ describe('Branch API Tests', () => {
206212

207213
before(async function () {
208214
this.timeout(60000)
209-
// Create a branch for merging
215+
// Create a branch for merging (uid stored in testData.branches.merge for dependent tests)
210216
mergeBranchUid = `mrg${shortId()}`
211217

212218
try {
213-
await stack.branch().create({
219+
const branch = await stack.branch().create({
214220
branch: {
215221
uid: mergeBranchUid,
216222
source: 'main'
217223
}
218224
})
219-
// Wait for branch to be fully ready before merge operations
220-
await wait(2000)
225+
testData.branches.merge = branch
226+
// Wait for branch to be fully ready (can take 10+ seconds to reflect)
227+
await wait(LONG_DELAY)
221228
} catch (error) {
222-
console.log('Branch creation failed:', error.errorMessage)
229+
if (error.status === 409 || (error.errorMessage && error.errorMessage.includes('already exists'))) {
230+
const existing = await stack.branch(mergeBranchUid).fetch()
231+
testData.branches.merge = existing
232+
} else {
233+
console.log('Branch creation failed:', error.message || error.errorMessage)
234+
}
223235
}
224236
})
225237

@@ -228,30 +240,31 @@ describe('Branch API Tests', () => {
228240
})
229241

230242
it('should get merge queue', async () => {
231-
try {
232-
const response = await stack.branch(mergeBranchUid).mergeQueue()
233-
234-
expect(response).to.be.an('object')
235-
} catch (error) {
236-
console.log('Merge queue failed:', error.errorMessage)
243+
// mergeQueue() is on the branch collection, not on a branch instance
244+
const response = await stack.branch().mergeQueue().find()
245+
expect(response).to.be.an('object')
246+
if (response.queue) {
247+
expect(response.queue).to.be.an('array')
237248
}
238249
})
239250

240-
it('should merge branch into main (dry run conceptual)', async () => {
241-
// Note: Actual merge requires changes in the branch
242-
// This tests the merge API availability
243-
try {
244-
const response = await stack.branch(mergeBranchUid).merge({
245-
base_branch: 'main',
246-
compare_branch: mergeBranchUid,
247-
default_merge_strategy: 'merge_prefer_base',
248-
merge_comment: 'Test merge'
249-
})
250-
251-
expect(response).to.be.an('object')
252-
} catch (error) {
253-
// Merge might fail if no changes or conflicts
254-
console.log('Merge result:', error.errorMessage)
251+
it('should merge branch into main', async () => {
252+
// merge() is on the branch collection: merge(mergeObj, params)
253+
// mergeObj = request body (e.g. item_merge_strategies), params = query (base_branch, compare_branch, etc.)
254+
const params = {
255+
base_branch: 'main',
256+
compare_branch: mergeBranchUid,
257+
default_merge_strategy: 'merge_prefer_base',
258+
merge_comment: 'Test merge'
259+
}
260+
const response = await stack.branch().merge({}, params)
261+
expect(response).to.be.an('object')
262+
// API may return merge_details, errors, or notice depending on whether there were changes to merge
263+
if (response.merge_details !== undefined) {
264+
expect(response.merge_details).to.be.an('object')
265+
}
266+
if (response.notice) {
267+
expect(response.notice).to.be.a('string')
255268
}
256269
})
257270
})

test/sanity-check/api/bulkOperation-test.js

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function delay (ms) {
3434
return new Promise(resolve => setTimeout(resolve, ms))
3535
}
3636

37+
// Build assets array with only non-empty UIDs (never send "uid": "" — API returns 412).
38+
// Asset-test must not delete image/html/bufferUpload so bulk tests have valid assets (Phase 6 before Phase 21).
39+
function assetsWithValidUids () {
40+
return [assetUid1, assetUid2].filter(uid => uid && String(uid).trim()).map(uid => ({ uid }))
41+
}
42+
3743
async function waitForJobReady (jobId, maxAttempts = 10) {
3844
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
3945
try {
@@ -110,16 +116,12 @@ describe('BulkOperation api test', () => {
110116
.catch(done)
111117
})
112118

113-
it('should publish one asset when publishDetails of an asset is passed', done => {
119+
it('should publish one asset when publishDetails of an asset is passed', function (done) {
120+
const assets = assetsWithValidUids()
121+
expect(assets.length, 'At least one asset required from asset-test (Phase 6)').to.be.at.least(1)
114122
const publishDetails = {
115-
assets: [
116-
{
117-
uid: assetUid1
118-
}
119-
],
120-
locales: [
121-
'en-us'
122-
],
123+
assets,
124+
locales: ['en-us'],
123125
environments: [envName]
124126
}
125127
doBulkOperation()
@@ -136,28 +138,11 @@ describe('BulkOperation api test', () => {
136138
it('should publish multiple entries assets when publishDetails of entries and assets are passed', done => {
137139
const publishDetails = {
138140
entries: [
139-
{
140-
uid: entryUid1,
141-
content_type: bulkCtUid1,
142-
locale: 'en-us'
143-
},
144-
{
145-
uid: entryUid2,
146-
content_type: bulkCtUid2,
147-
locale: 'en-us'
148-
}
149-
],
150-
assets: [
151-
{
152-
uid: assetUid1
153-
},
154-
{
155-
uid: assetUid2
156-
}
157-
],
158-
locales: [
159-
'en-us'
141+
{ uid: entryUid1, content_type: bulkCtUid1, locale: 'en-us' },
142+
{ uid: entryUid2, content_type: bulkCtUid2, locale: 'en-us' }
160143
],
144+
assets: assetsWithValidUids(),
145+
locales: ['en-us'],
161146
environments: [envName]
162147
}
163148
doBulkOperation()
@@ -231,16 +216,12 @@ describe('BulkOperation api test', () => {
231216
.catch(done)
232217
})
233218

234-
it('should publish assets with publishAllLocalized parameter', done => {
219+
it('should publish assets with publishAllLocalized parameter', function (done) {
220+
const assets = assetsWithValidUids()
221+
expect(assets.length, 'At least one asset required from asset-test (Phase 6)').to.be.at.least(1)
235222
const publishDetails = {
236-
assets: [
237-
{
238-
uid: assetUid1
239-
}
240-
],
241-
locales: [
242-
'en-us'
243-
],
223+
assets,
224+
locales: ['en-us'],
244225
environments: [envName]
245226
}
246227
doBulkOperation()
@@ -319,16 +300,12 @@ describe('BulkOperation api test', () => {
319300
.catch(done)
320301
})
321302

322-
it('should unpublish assets with unpublishAllLocalized parameter', done => {
303+
it('should unpublish assets with unpublishAllLocalized parameter', function (done) {
304+
const assets = assetsWithValidUids()
305+
expect(assets.length, 'At least one asset required from asset-test (Phase 6)').to.be.at.least(1)
323306
const unpublishDetails = {
324-
assets: [
325-
{
326-
uid: assetUid1
327-
}
328-
],
329-
locales: [
330-
'en-us'
331-
],
307+
assets,
308+
locales: ['en-us'],
332309
environments: [envName]
333310
}
334311
doBulkOperation()

test/sanity-check/utility/testHelpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export function validateAssetResponse (response) {
131131
expect(response.content_type).to.be.a('string')
132132
expect(response.file_size).to.be.a('string')
133133

134-
// Validate UID format
135-
expect(response.uid).to.match(/^blt[a-f0-9]+$/, 'Asset UID should have blt prefix')
134+
// Validate UID format (CMA: blt prefix; AM 2.0: am prefix)
135+
expect(response.uid).to.match(/^(blt|am)[a-f0-9]+$/, 'Asset UID should have blt or am prefix')
136136

137137
// Validate timestamps
138138
expect(response.created_at).to.be.a('string')

0 commit comments

Comments
 (0)