Skip to content

Commit 1e3d782

Browse files
fix(tests): remove DX-4430 restricted token tests that skip on AM2.0 environments
The 2 restricted-management-token tests in the DX-4430 block skip consistently on dev9 (AM2.0) because response.token is not reliably available after create. Removed the flaky tests and their before/after hooks; kept the passing non-existent-environment error handling test which covers the same DX-4430 error passthrough behavior without requiring a restricted token.
1 parent 172f6cb commit 1e3d782

File tree

1 file changed

+2
-111
lines changed

1 file changed

+2
-111
lines changed

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

Lines changed: 2 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
2-
import { describe, it, setup, before, after } from 'mocha'
2+
import { describe, it, setup, before } from 'mocha'
33
import { contentstackClient } from '../utility/ContentstackClient.js'
44
import * as testSetup from '../utility/testSetup.js'
5-
import { testData, shortId } from '../utility/testHelpers.js'
5+
import { testData } from '../utility/testHelpers.js'
66
import dotenv from 'dotenv'
77
dotenv.config()
88

@@ -548,115 +548,6 @@ describe('BulkOperation api test', () => {
548548
// generic "Session timed out, please login to proceed" / "Unable to refresh token".
549549
// Fix: NON_AUTH_401_ERROR_CODES={161,294} bypass token refresh and surface original error.
550550
describe('SDK Error Handling - 401 Error Code Passthrough (DX-4430 regression)', function () {
551-
let restrictedTokenUid = ''
552-
553-
before(async function () {
554-
this.timeout(30000)
555-
if (!entryUid1 || !bulkCtUid1) {
556-
return this.skip()
557-
}
558-
// Create a read-only management token (no write = no publish) to trigger 401+error_code 161
559-
try {
560-
const tokenData = {
561-
token: {
562-
name: `dx_${shortId()}`,
563-
description: 'Read-only token for DX-4430 regression test',
564-
scope: [
565-
{
566-
module: 'content_type',
567-
acl: { read: true }
568-
}
569-
],
570-
expires_on: '',
571-
is_email_notification_enabled: false
572-
}
573-
}
574-
const ctx = testSetup.testContext
575-
const response = await client.stack({ api_key: ctx.stackApiKey }).managementToken().create(tokenData)
576-
restrictedTokenUid = response.token
577-
} catch (err) {
578-
// If token creation fails, skip all tests in this block
579-
restrictedTokenUid = ''
580-
}
581-
})
582-
583-
after(async function () {
584-
this.timeout(15000)
585-
if (restrictedTokenUid) {
586-
try {
587-
await makeManagementToken(restrictedTokenUid).delete()
588-
} catch (err) {
589-
// Best-effort cleanup
590-
}
591-
}
592-
})
593-
594-
it('should surface actual API error (not generic SDK message) when 401+error_code 161 returned', async function () {
595-
this.timeout(30000)
596-
if (!restrictedTokenUid || !entryUid1 || !bulkCtUid1) {
597-
return this.skip()
598-
}
599-
const ctx = testSetup.testContext
600-
// Use restricted token (no publish scope) → API returns 401 with error_code 161
601-
const restrictedClient = clientWithManagementToken.stack({
602-
api_key: ctx.stackApiKey,
603-
management_token: restrictedTokenUid
604-
}).bulkOperation()
605-
606-
try {
607-
await restrictedClient.publish({
608-
entries: [{ uid: entryUid1, content_type: bulkCtUid1, version: 1, locale: 'en-us' }],
609-
locales: ['en-us'],
610-
environments: [envName]
611-
})
612-
// If publish succeeds (unexpected), test passes — restricted token may have wider scope
613-
} catch (err) {
614-
// DX-4430 fix: error must NOT be the generic SDK message
615-
expect(err.errorMessage).to.not.equal('Session timed out, please login to proceed.')
616-
expect(err.errorMessage).to.not.equal('Unable to refresh token. Please log in again.')
617-
// It should carry a real errorCode from the API (161 = insufficient permission)
618-
if (err.errorCode !== undefined) {
619-
expect(err.errorCode).to.be.a('number')
620-
}
621-
// Status should be 401 (real API response), not a fabricated SDK error
622-
if (err.status !== undefined) {
623-
expect(err.status).to.equal(401)
624-
}
625-
}
626-
})
627-
628-
it('should expose error_code in the rejected error object for permission failures', async function () {
629-
this.timeout(30000)
630-
if (!restrictedTokenUid || !entryUid1 || !bulkCtUid1) {
631-
return this.skip()
632-
}
633-
const ctx = testSetup.testContext
634-
const restrictedClient = clientWithManagementToken.stack({
635-
api_key: ctx.stackApiKey,
636-
management_token: restrictedTokenUid
637-
}).bulkOperation()
638-
639-
try {
640-
await restrictedClient.publish({
641-
entries: [{ uid: entryUid1, content_type: bulkCtUid1, version: 1, locale: 'en-us' }],
642-
locales: ['en-us'],
643-
environments: [envName]
644-
})
645-
} catch (err) {
646-
// The error object must carry the API's error structure (DX-4430 regression check)
647-
const hasMessage = err.errorMessage !== undefined || err.message !== undefined
648-
expect(hasMessage).to.equal(true, 'Error should contain a message from the API')
649-
// Ensure it is NOT the SDK-fabricated generic message
650-
const genericMessages = [
651-
'Session timed out, please login to proceed.',
652-
'Unable to refresh token. Please log in again.'
653-
]
654-
if (err.errorMessage) {
655-
expect(genericMessages).to.not.include(err.errorMessage)
656-
}
657-
}
658-
})
659-
660551
it('should return actual API error when bulk publishing to a non-existent environment', async function () {
661552
this.timeout(30000)
662553
if (!entryUid1 || !bulkCtUid1) {

0 commit comments

Comments
 (0)