Skip to content

Commit c3caac0

Browse files
committed
feat: SITES-29655 Remove import assistant related code from the helper
1 parent 7f262e1 commit c3caac0

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
"esbuild": "^0.23.0",
4343
"express": "^4.21.0",
4444
"find-up": "^7.0.0",
45+
"form-data": "4.0.1",
46+
"inquirer": "12.2.0",
4547
"jsdom": "^25.0.1",
4648
"node-fetch": "^3.3.2",
4749
"ora": "^8.1.0",
4850
"puppeteer": "^23.1.0",
4951
"unzipper": "^0.12.3",
50-
"yargs": "^17.7.2",
51-
"form-data": "4.0.1",
52-
"inquirer": "12.2.0"
52+
"yargs": "^17.7.2"
5353
},
5454
"devDependencies": {
5555
"@eslint/js": "^9.13.0",

test/aem/downloadImages.test.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
import fs from 'fs';
1414
import { expect, use } from 'chai';
1515
import sinon from 'sinon';
16+
import sinonChai from 'sinon-chai';
1617
import chaiAsPromised from 'chai-as-promised';
1718
import * as downloadImagesModule from '../../src/aem/downloadImages.js';
1819
import { downloadImagesInMarkdown } from '../../src/aem/downloadImages.js';
1920
import { Readable, Writable } from 'stream';
2021
import path from 'path';
2122
import { expectLogContains } from '../utils.js';
2223

24+
use(sinonChai); // chai.use
2325
use(chaiAsPromised);
2426

2527
describe('downloadImages.js', function () {
@@ -119,14 +121,14 @@ describe('downloadImages.js', function () {
119121
mkdirSyncStub.returns();
120122

121123
downloadImagesModule.ensureDirSync('path/to/directory');
122-
expect(mkdirSyncStub.calledWith('path/to/directory', { recursive: true })).to.equal(true);
124+
expect(mkdirSyncStub).to.have.been.calledWith('path/to/directory', { recursive: true });
123125
});
124126

125127
it('should log error if directory creation fails', () => {
126128
mkdirSyncStub.throws(new Error('Error creating directory'));
127129

128130
downloadImagesModule.ensureDirSync('path/to/directory');
129-
expect(consoleErrorStub.calledWith(sinon.match.string)).to.equal(true);
131+
expect(consoleErrorStub).to.have.been.calledWith(sinon.match.string);
130132
});
131133
});
132134

@@ -138,10 +140,10 @@ describe('downloadImages.js', function () {
138140
'/content/dam/image.jpg',
139141
);
140142

141-
expect(fetchStub.calledWith('http://example.com/image.jpg')).to.equal(true);
143+
expect(fetchStub).to.have.been.calledWith('http://example.com/image.jpg');
142144

143145
const finalPath = path.join(process.cwd(), 'image.jpg');
144-
expect(createWriteStreamStub.calledWith(finalPath)).to.equal(true);
146+
expect(createWriteStreamStub).to.have.been.calledWith(finalPath);
145147

146148
// Ensure the image data was correctly written to the mock stream
147149
expect(imageData).to.equal('image data');
@@ -165,7 +167,7 @@ describe('downloadImages.js', function () {
165167
.to.be.rejectedWith('Failed to fetch http://example.com/image.jpg. Status: 404.');
166168

167169
// there should be 5 retry attempts
168-
expect(fetchStub.callCount).to.equal(5);
170+
expect(fetchStub).to.have.callCount(5);
169171

170172
// because the image fails to download, the error message should be logged
171173
expectLogContains(consoleErrorStub, 'Failed to download')
@@ -183,9 +185,9 @@ describe('downloadImages.js', function () {
183185

184186
// test downloadImagesInMarkdown method
185187
await downloadImagesInMarkdown({ maxRetries: 3, downloadLocation: 'path/to/download' }, 'path/to/markdown.md');
186-
expect(fetchStub.calledWith('http://example.com/image1.jpg')).to.equal(true);
187-
expect(createWriteStreamStub.callCount).to.equal(3);
188-
expect(createWriteStreamStub.called).to.equal(true);
188+
expect(fetchStub).to.have.been.calledWith('http://example.com/image1.jpg');
189+
expect(createWriteStreamStub).to.have.been.called;
190+
expect(createWriteStreamStub).to.have.callCount(3);
189191
});
190192
});
191193
});

test/aem/uploadImages.test.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212

1313
import fs from 'fs';
1414
import path from 'path';
15-
import { expect } from 'chai';
15+
import { expect, use } from 'chai';
1616
import sinon from 'sinon';
17+
import sinonChai from 'sinon-chai';
1718
import { FileSystemUpload, FileSystemUploadOptions } from '@adobe/aem-upload';
1819
import uploadImagesToAEM from '../../src/aem/uploadImages.js';
1920

21+
use(sinonChai); // chai.use
22+
2023
describe('uploadImages.js', function() {
2124
this.timeout(30000); // Increase timeout to 30 seconds
2225

@@ -53,8 +56,8 @@ describe('uploadImages.js', function() {
5356

5457
const result = await uploadImagesToAEM(opts);
5558

56-
expect(fileUploadStub.calledWith(sinon.match.instanceOf(FileSystemUploadOptions), [path.join(process.cwd(), 'test')])).to.equal(true);
57-
expect(rmStub.calledWith(path.join(process.cwd(), 'test'), { recursive: true, force: true })).to.equal(true);
59+
expect(fileUploadStub).to.have.been.calledWith(sinon.match.instanceOf(FileSystemUploadOptions), [path.join(process.cwd(), 'test')]);
60+
expect(rmStub).to.have.been.calledWith(path.join(process.cwd(), 'test'), { recursive: true, force: true });
5861
expect(result).to.deep.equal({});
5962
});
6063

@@ -84,7 +87,7 @@ describe('uploadImages.js', function() {
8487
};
8588

8689
await expect(uploadImagesToAEM(opts)).to.be.rejectedWith('Upload error');
87-
expect(consoleErrorStub.calledWith(sinon.match.string)).to.equal(true);
90+
expect(consoleErrorStub).to.have.been.calledWith(sinon.match.string);
8891
});
8992
});
9093
});

0 commit comments

Comments
 (0)