Skip to content

Commit 1ce0d64

Browse files
committed
fix: ESLint in asset-test.js and unit test mock paths
- asset-test.js: fix trailing spaces, remove unused uploadedAssetUid, add no-unused-expressions disables for Chai expect() (lint check) - Add test/sanity-check/mock/customUpload.html and upload.html so unit tests (asset-test, concurrency-Queue-test) find expected files and Build & Test passes (622 passes, 0 failures)
1 parent a297264 commit 1ce0d64

File tree

3 files changed

+86
-23
lines changed

3 files changed

+86
-23
lines changed

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Asset API Tests
3-
*
3+
*
44
* Comprehensive test suite for:
55
* - Asset upload (various methods)
66
* - Asset CRUD operations
@@ -39,8 +39,6 @@ describe('Asset API Tests', () => {
3939
// ==========================================================================
4040

4141
describe('Asset Upload', () => {
42-
let uploadedAssetUid
43-
4442
after(async () => {
4543
// NOTE: Deletion removed - assets persist for entries, bulk operations
4644
})
@@ -67,7 +65,6 @@ describe('Asset API Tests', () => {
6765
expect(response.title).to.include('Test Image')
6866
expect(response.description).to.equal('Test image upload')
6967

70-
uploadedAssetUid = response.uid
7168
testData.assets.image = response
7269
})
7370

@@ -96,9 +93,9 @@ describe('Asset API Tests', () => {
9693

9794
it('should upload asset from buffer', async function () {
9895
this.timeout(30000)
99-
96+
10097
const fileBuffer = fs.readFileSync(assetPath)
101-
98+
10299
// SDK returns the asset object directly
103100
const asset = await stack.asset().create({
104101
upload: fileBuffer,
@@ -115,7 +112,7 @@ describe('Asset API Tests', () => {
115112
expect(asset.title).to.include('Buffer Upload')
116113
// Content type may vary based on server detection
117114
expect(asset.content_type).to.be.a('string')
118-
115+
119116
testData.assets.bufferUpload = asset
120117

121118
// Cleanup
@@ -131,9 +128,11 @@ describe('Asset API Tests', () => {
131128
})
132129
expect.fail('Should have thrown an error')
133130
} catch (error) {
131+
// eslint-disable-next-line no-unused-expressions
134132
expect(error).to.exist
135133
// SDK might throw client-side error without status
136134
if (error.status) {
135+
// eslint-disable-next-line no-unused-expressions
137136
expect(error.status).to.be.oneOf([400, 422])
138137
}
139138
}
@@ -147,6 +146,7 @@ describe('Asset API Tests', () => {
147146
})
148147
expect.fail('Should have thrown an error')
149148
} catch (error) {
149+
// eslint-disable-next-line no-unused-expressions
150150
expect(error).to.exist
151151
}
152152
})
@@ -286,9 +286,11 @@ describe('Asset API Tests', () => {
286286
}
287287
})
288288

289+
// eslint-disable-next-line no-unused-expressions
289290
expect(folder).to.be.an('object')
290291
expect(folder.uid).to.be.a('string')
291292
expect(folder.name).to.include('Test Folder')
293+
// eslint-disable-next-line no-unused-expressions
292294
expect(folder.is_dir).to.be.true
293295

294296
folderUid = folder.uid
@@ -303,8 +305,10 @@ describe('Asset API Tests', () => {
303305

304306
const response = await stack.asset().folder(folderUid).fetch()
305307

308+
// eslint-disable-next-line no-unused-expressions
306309
expect(response).to.be.an('object')
307310
expect(response.uid).to.equal(folderUid)
311+
// eslint-disable-next-line no-unused-expressions
308312
expect(response.is_dir).to.be.true
309313
})
310314

@@ -386,7 +390,7 @@ describe('Asset API Tests', () => {
386390

387391
before(async function () {
388392
this.timeout(60000)
389-
393+
390394
// Get environment name from testData (created by environment-test.js)
391395
if (testData.environments && testData.environments.development) {
392396
publishEnvironment = testData.environments.development.name
@@ -402,7 +406,7 @@ describe('Asset API Tests', () => {
402406
console.log('Could not fetch environments:', e.message)
403407
}
404408
}
405-
409+
406410
// If no environment exists, create a temporary one for publishing
407411
if (!publishEnvironment) {
408412
try {
@@ -420,12 +424,12 @@ describe('Asset API Tests', () => {
420424
console.log('Could not create environment for publishing:', e.message)
421425
}
422426
}
423-
427+
424428
if (!publishEnvironment) {
425429
console.log('No environment available for publish tests - will skip')
426430
return
427431
}
428-
432+
429433
// SDK returns the asset object directly
430434
const asset = await stack.asset().create({
431435
upload: assetPath,
@@ -444,7 +448,7 @@ describe('Asset API Tests', () => {
444448
this.skip()
445449
return
446450
}
447-
451+
448452
try {
449453
const asset = await stack.asset(publishableAssetUid).fetch()
450454

@@ -471,7 +475,7 @@ describe('Asset API Tests', () => {
471475
this.skip()
472476
return
473477
}
474-
478+
475479
try {
476480
const asset = await stack.asset(publishableAssetUid).fetch()
477481

@@ -528,7 +532,7 @@ describe('Asset API Tests', () => {
528532
// SDK doesn't have a separate versions() method
529533
// Version info is available via _version property on fetched asset
530534
const asset = await stack.asset(versionedAssetUid).fetch()
531-
535+
532536
expect(asset).to.be.an('object')
533537
expect(asset._version).to.be.a('number')
534538
expect(asset._version).to.be.at.least(1)
@@ -608,15 +612,17 @@ describe('Asset API Tests', () => {
608612

609613
it('should download asset from URL', async function () {
610614
this.timeout(30000)
611-
615+
612616
try {
613-
const response = await stack.asset().download({
614-
url: assetUrl,
615-
responseType: 'stream'
617+
const response = await stack.asset().download({
618+
url: assetUrl,
619+
responseType: 'stream'
616620
})
617-
621+
622+
// eslint-disable-next-line no-unused-expressions
618623
expect(response).to.be.an('object')
619624
// Stream response should have data
625+
// eslint-disable-next-line no-unused-expressions
620626
expect(response.data || response).to.exist
621627
} catch (error) {
622628
// Download might not be available in all environments
@@ -626,13 +632,15 @@ describe('Asset API Tests', () => {
626632

627633
it('should download asset after fetch', async function () {
628634
this.timeout(30000)
629-
635+
630636
try {
631637
const asset = await stack.asset(downloadAssetUid).fetch()
632638
const response = await asset.download({ responseType: 'stream' })
633-
639+
640+
// eslint-disable-next-line no-unused-expressions
634641
expect(response).to.be.an('object')
635642
// Stream response should have data
643+
// eslint-disable-next-line no-unused-expressions
636644
expect(response.data || response).to.exist
637645
} catch (error) {
638646
// Download might not be available in all environments
@@ -685,7 +693,6 @@ describe('Asset API Tests', () => {
685693
// ==========================================================================
686694

687695
describe('Error Handling', () => {
688-
689696
it('should fail to fetch non-existent asset', async () => {
690697
try {
691698
await stack.asset('nonexistent_asset_12345').fetch()
@@ -709,6 +716,7 @@ describe('Asset API Tests', () => {
709716
await stack.asset('invalid_uid').fetch()
710717
expect.fail('Should have thrown an error')
711718
} catch (error) {
719+
// eslint-disable-next-line no-unused-expressions
712720
expect(error).to.exist
713721
expect(error.status).to.be.a('number')
714722
expect(error.errorMessage).to.be.a('string')
@@ -721,7 +729,6 @@ describe('Asset API Tests', () => {
721729
// ==========================================================================
722730

723731
describe('Asset Query Operations', () => {
724-
725732
it('should query assets by content type', async () => {
726733
const response = await stack.asset().query({
727734
query: { content_type: { $regex: 'image' } }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<head>
3+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
4+
<script src="https://unpkg.com/@contentstack/ui-extensions-sdk@2.1.1/dist/ui-extension-sdk.js"></script>
5+
<link rel="stylesheet" type="text/css" href="https://unpkg.com/@contentstack/ui-extensions-sdk@2.1.1/dist/ui-extension-sdk.css">
6+
</head>
7+
<body>
8+
<input type="color" id="html5colorpicker" onchange="colorChange()">
9+
<script>
10+
// initialise Field Extension
11+
window.extensionField = {};
12+
// find color input element
13+
var colorPickerElement = document.getElementById("html5colorpicker");
14+
ContentstackUIExtension.init().then(function(extension) {
15+
// make extension object globally available
16+
extensionField = extension;
17+
// Get current color field value from Contentstack and update the color picker input element
18+
colorPickerElement.value = extensionField.field.getData();
19+
}).catch(function(error) {
20+
console.log(error);
21+
});
22+
// On color change event, pass new value to Contentstack
23+
function colorChange(){
24+
extensionField.field.setData(colorPickerElement.value);
25+
}
26+
</script>
27+
</body>
28+
</html>

test/sanity-check/mock/upload.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<head>
3+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
4+
<script src="https://unpkg.com/@contentstack/ui-extensions-sdk@2.1.1/dist/ui-extension-sdk.js"></script>
5+
<link rel="stylesheet" type="text/css" href="https://unpkg.com/@contentstack/ui-extensions-sdk@2.1.1/dist/ui-extension-sdk.css">
6+
</head>
7+
<body>
8+
<input type="color" id="html5colorpicker" onchange="colorChange()">
9+
<script>
10+
// initialise Field Extension
11+
window.extensionField = {};
12+
// find color input element
13+
var colorPickerElement = document.getElementById("html5colorpicker");
14+
ContentstackUIExtension.init().then(function(extension) {
15+
// make extension object globally available
16+
extensionField = extension;
17+
// Get current color field value from Contentstack and update the color picker input element
18+
colorPickerElement.value = extensionField.field.getData();
19+
}).catch(function(error) {
20+
console.log(error);
21+
});
22+
// On color change event, pass new value to Contentstack
23+
function colorChange(){
24+
extensionField.field.setData(colorPickerElement.value);
25+
}
26+
</script>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)