Skip to content

Commit c13a012

Browse files
authored
Merge pull request #568 from contentstack/development
DX | 06-07-2026 | Release
2 parents 2b54069 + 7a93dc0 commit c13a012

4 files changed

Lines changed: 170 additions & 3 deletions

File tree

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,4 +981,84 @@ describe('Asset API Tests', () => {
981981
}
982982
})
983983
})
984+
985+
// ==========================================================================
986+
// ASSET SCAN STATUS
987+
// ==========================================================================
988+
989+
describe('Asset Scan Status', () => {
990+
let assetUid
991+
992+
before(async function () {
993+
this.timeout(30000)
994+
// Reuse an asset created by the Asset Upload block to avoid an extra upload.
995+
// Fall back to creating a fresh one only if that block didn't succeed.
996+
if (testData.assets.image && testData.assets.image.uid) {
997+
assetUid = testData.assets.image.uid
998+
return
999+
}
1000+
try {
1001+
const asset = await stack.asset().create({
1002+
upload: assetPath,
1003+
title: `Scan Status Test Asset ${Date.now()}`,
1004+
description: 'Asset for scan status testing'
1005+
})
1006+
assetUid = asset.uid
1007+
} catch (err) {
1008+
// Asset creation failed — individual tests will skip themselves.
1009+
}
1010+
})
1011+
1012+
it('should accept include_asset_scan_status param on single asset fetch', async function () {
1013+
if (!assetUid) return this.skip()
1014+
const asset = await stack.asset(assetUid).fetch({ include_asset_scan_status: true })
1015+
1016+
expect(asset).to.be.an('object')
1017+
expect(asset.uid).to.equal(assetUid)
1018+
// _asset_scan_status is opt-in. When scanning is enabled: pending | clean | quarantined.
1019+
// When scanning is not enabled for the stack, the API returns 'not_scanned'.
1020+
if ('_asset_scan_status' in asset) {
1021+
expect(asset._asset_scan_status).to.be.a('string')
1022+
expect(['pending', 'clean', 'quarantined', 'not_scanned']).to.include(asset._asset_scan_status)
1023+
}
1024+
})
1025+
1026+
it('should accept include_asset_scan_status param on asset list query', async function () {
1027+
const response = await stack.asset().query({ include_asset_scan_status: true }).find()
1028+
1029+
expect(response).to.be.an('object')
1030+
expect(response.items).to.be.an('array')
1031+
// pending | clean | quarantined when scanning is enabled; not_scanned otherwise.
1032+
if (response.items.length > 0 && '_asset_scan_status' in response.items[0]) {
1033+
expect(response.items[0]._asset_scan_status).to.be.a('string')
1034+
expect(['pending', 'clean', 'quarantined', 'not_scanned']).to.include(response.items[0]._asset_scan_status)
1035+
}
1036+
})
1037+
1038+
it('should not return _asset_scan_status when param is omitted', async function () {
1039+
if (!assetUid) return this.skip()
1040+
const asset = await stack.asset(assetUid).fetch()
1041+
1042+
expect(asset).to.be.an('object')
1043+
expect(asset).to.not.have.property('_asset_scan_status')
1044+
})
1045+
1046+
it('should accept include_asset_scan_status param on asset upload', async function () {
1047+
this.timeout(30000)
1048+
const asset = await stack.asset().create(
1049+
{
1050+
upload: assetPath,
1051+
title: `Scan Status Upload Test ${Date.now()}`
1052+
},
1053+
{ include_asset_scan_status: true }
1054+
)
1055+
1056+
expect(asset).to.be.an('object')
1057+
expect(asset.uid).to.be.a('string')
1058+
// pending when scanning is enabled; not_scanned when scanning is not enabled for the stack.
1059+
if ('_asset_scan_status' in asset) {
1060+
expect(['pending', 'not_scanned']).to.include(asset._asset_scan_status)
1061+
}
1062+
})
1063+
})
9841064
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ describe('Taxonomy API Tests', () => {
308308
await stack.taxonomy().publish({ locales: ['en-us'], environments: ['development'], items: [] })
309309
// Some environments may accept empty arrays, just check it returns something
310310
} catch (e) {
311-
expect(e.status).to.be.oneOf([400, 422])
311+
expect(e.status).to.be.oneOf([400, 412, 422])
312312
}
313313
})
314314

@@ -367,7 +367,7 @@ describe('Taxonomy API Tests', () => {
367367
try {
368368
await stack.taxonomy().unpublish({ locales: ['en-us'], environments: ['development'], items: [] })
369369
} catch (e) {
370-
expect(e.status).to.be.oneOf([400, 422])
370+
expect(e.status).to.be.oneOf([400, 412, 422])
371371
}
372372
})
373373
})

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ describe('Teams API Tests', () => {
8787
trackedExpect(response.uid, 'Team UID').toExist()
8888
trackedExpect(response.uid, 'Team UID type').toBeA('string')
8989
trackedExpect(response.name, 'Team name').toEqual(teamData.name)
90-
trackedExpect(response.organizationRole, 'Team organizationRole').toExist()
90+
const orgRole = response.organizationRole || response.organizationRoles
91+
trackedExpect(orgRole, 'Team organizationRole/organizationRoles').toExist()
9192

9293
// Wait for team to be fully created
9394
await wait(2000)

test/unit/asset-test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,92 @@ describe('Contentstack Asset test', () => {
463463
})
464464
.catch(done)
465465
})
466+
467+
// Asset Scanning tests
468+
it('Asset fetch sends include_asset_scan_status as query param and returns _asset_scan_status', done => {
469+
var mock = new MockAdapter(Axios)
470+
mock.onGet('/assets/UID').reply((config) => {
471+
expect(config.params.include_asset_scan_status).to.equal(true)
472+
return [200, {
473+
asset: {
474+
...assetMock,
475+
_asset_scan_status: 'clean'
476+
}
477+
}]
478+
})
479+
makeAsset({
480+
asset: { ...systemUidMock },
481+
stackHeaders: stackHeadersMock
482+
})
483+
.fetch({ include_asset_scan_status: true })
484+
.then((asset) => {
485+
checkAsset(asset)
486+
expect(asset._asset_scan_status).to.equal('clean')
487+
done()
488+
})
489+
.catch(done)
490+
})
491+
492+
it('Asset query sends include_asset_scan_status as query param and returns _asset_scan_status', done => {
493+
var mock = new MockAdapter(Axios)
494+
mock.onGet('/assets').reply((config) => {
495+
expect(config.params.include_asset_scan_status).to.equal(true)
496+
return [200, {
497+
assets: [{
498+
...assetMock,
499+
_asset_scan_status: 'clean'
500+
}]
501+
}]
502+
})
503+
makeAsset()
504+
.query({ include_asset_scan_status: true })
505+
.find()
506+
.then((collection) => {
507+
expect(collection.items[0]._asset_scan_status).to.equal('clean')
508+
done()
509+
})
510+
.catch(done)
511+
})
512+
513+
it('Asset create sends include_asset_scan_status as query param and returns pending scan status', done => {
514+
var mock = new MockAdapter(Axios)
515+
mock.onPost('/assets').reply((config) => {
516+
expect(config.params.include_asset_scan_status).to.equal(true)
517+
return [200, {
518+
asset: {
519+
...assetMock,
520+
_asset_scan_status: 'pending'
521+
}
522+
}]
523+
})
524+
makeAsset()
525+
.create(
526+
{ upload: path.join(__dirname, '../sanity-check/mock/customUpload.html') },
527+
{ include_asset_scan_status: true }
528+
)
529+
.then((asset) => {
530+
expect(asset._asset_scan_status).to.equal('pending')
531+
done()
532+
})
533+
.catch(done)
534+
})
535+
536+
it('Asset fetch without include_asset_scan_status does not return _asset_scan_status', done => {
537+
var mock = new MockAdapter(Axios)
538+
mock.onGet('/assets/UID').reply(200, {
539+
asset: { ...assetMock }
540+
})
541+
makeAsset({
542+
asset: { ...systemUidMock },
543+
stackHeaders: stackHeadersMock
544+
})
545+
.fetch()
546+
.then((asset) => {
547+
expect(asset._asset_scan_status).to.equal(undefined)
548+
done()
549+
})
550+
.catch(done)
551+
})
466552
})
467553

468554
function makeAsset (data) {

0 commit comments

Comments
 (0)