@adobe/spacecat-shared-tokowaka-client 1.17.3 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/index.js +450 -236
- package/src/utils/metaconfig-utils.js +52 -0
- package/src/utils/pattern-utils.js +43 -0
- package/src/utils/suggestion-utils.js +174 -0
- package/test/index.test.js +1575 -229
- package/test/utils/suggestion-utils.test.js +43 -1
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { expect } from 'chai';
|
|
14
|
-
import
|
|
14
|
+
import sinon from 'sinon';
|
|
15
|
+
import { groupSuggestionsByUrlPath, filterEligibleSuggestions, saveSuggestions } from '../../src/utils/suggestion-utils.js';
|
|
15
16
|
|
|
16
17
|
describe('Suggestion Utils', () => {
|
|
17
18
|
describe('groupSuggestionsByUrlPath', () => {
|
|
@@ -182,4 +183,45 @@ describe('Suggestion Utils', () => {
|
|
|
182
183
|
expect(result.ineligible[0].reason).to.equal('Suggestion cannot be deployed');
|
|
183
184
|
});
|
|
184
185
|
});
|
|
186
|
+
|
|
187
|
+
describe('saveSuggestions', () => {
|
|
188
|
+
it('should no-op for empty array', async () => {
|
|
189
|
+
const dataAccess = { Suggestion: { saveMany: sinon.stub() } };
|
|
190
|
+
await saveSuggestions(dataAccess, []);
|
|
191
|
+
expect(dataAccess.Suggestion.saveMany.called).to.be.false;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should use saveMany for <= 1700 suggestions', async () => {
|
|
195
|
+
const dataAccess = { Suggestion: { saveMany: sinon.stub().resolves() } };
|
|
196
|
+
const items = [{ save: sinon.stub().resolves() }];
|
|
197
|
+
await saveSuggestions(dataAccess, items);
|
|
198
|
+
expect(dataAccess.Suggestion.saveMany.calledOnce).to.be.true;
|
|
199
|
+
expect(items[0].save.called).to.be.false;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should use Promise.allSettled for > 1700 suggestions', async () => {
|
|
203
|
+
const dataAccess = { Suggestion: { saveMany: sinon.stub() } };
|
|
204
|
+
const items = Array.from({ length: 1701 }, () => ({ save: sinon.stub().resolves() }));
|
|
205
|
+
await saveSuggestions(dataAccess, items);
|
|
206
|
+
expect(dataAccess.Suggestion.saveMany.called).to.be.false;
|
|
207
|
+
expect(items[0].save.calledOnce).to.be.true;
|
|
208
|
+
expect(items[1700].save.calledOnce).to.be.true;
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should throw when Promise.allSettled has failures', async () => {
|
|
212
|
+
const dataAccess = { Suggestion: { saveMany: sinon.stub() } };
|
|
213
|
+
const items = Array.from({ length: 1701 }, (_, i) => ({
|
|
214
|
+
save: i === 0
|
|
215
|
+
? sinon.stub().rejects(new Error('DB error'))
|
|
216
|
+
: sinon.stub().resolves(),
|
|
217
|
+
}));
|
|
218
|
+
try {
|
|
219
|
+
await saveSuggestions(dataAccess, items);
|
|
220
|
+
expect.fail('should have thrown');
|
|
221
|
+
} catch (error) {
|
|
222
|
+
expect(error.message).to.include('1 of 1701 suggestions failed');
|
|
223
|
+
expect(error.message).to.include('DB error');
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
185
227
|
});
|