@adobe/spacecat-shared-tokowaka-client 1.1.1 → 1.2.1
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/.releaserc.cjs +17 -0
- package/CHANGELOG.md +76 -1
- package/CODE_OF_CONDUCT.md +75 -0
- package/CONTRIBUTING.md +74 -0
- package/README.md +155 -15
- package/package.json +6 -6
- package/src/index.d.ts +120 -25
- package/src/index.js +481 -177
- package/src/mappers/base-mapper.js +41 -9
- package/src/mappers/content-summarization-mapper.js +38 -35
- package/src/mappers/faq-mapper.js +247 -0
- package/src/mappers/headings-mapper.js +37 -23
- package/src/mappers/mapper-registry.js +2 -0
- package/src/utils/custom-html-utils.js +195 -0
- package/src/utils/markdown-utils.js +24 -0
- package/src/utils/patch-utils.js +103 -0
- package/src/utils/s3-utils.js +117 -0
- package/src/utils/site-utils.js +25 -0
- package/src/utils/suggestion-utils.js +69 -0
- package/test/index.test.js +1268 -462
- package/test/mappers/base-mapper.test.js +250 -7
- package/test/mappers/content-mapper.test.js +26 -24
- package/test/mappers/faq-mapper.test.js +1428 -0
- package/test/mappers/headings-mapper.test.js +23 -17
- package/test/utils/html-utils.test.js +432 -0
- package/test/utils/patch-utils.test.js +409 -0
- package/test/utils/s3-utils.test.js +140 -0
- package/test/utils/site-utils.test.js +80 -0
- package/test/utils/suggestion-utils.test.js +187 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/* eslint-env mocha */
|
|
14
|
+
|
|
15
|
+
import { expect } from 'chai';
|
|
16
|
+
import { groupSuggestionsByUrlPath, filterEligibleSuggestions } from '../../src/utils/suggestion-utils.js';
|
|
17
|
+
|
|
18
|
+
describe('Suggestion Utils', () => {
|
|
19
|
+
describe('groupSuggestionsByUrlPath', () => {
|
|
20
|
+
const log = {
|
|
21
|
+
warn: () => {},
|
|
22
|
+
debug: () => {},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
it('should group suggestions by URL path', () => {
|
|
26
|
+
const suggestions = [
|
|
27
|
+
{
|
|
28
|
+
getId: () => 'sugg-1',
|
|
29
|
+
getData: () => ({ url: 'https://example.com/page1' }),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
getId: () => 'sugg-2',
|
|
33
|
+
getData: () => ({ url: 'https://example.com/page1' }),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
getId: () => 'sugg-3',
|
|
37
|
+
getData: () => ({ url: 'https://example.com/page2' }),
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const result = groupSuggestionsByUrlPath(suggestions, 'https://example.com', log);
|
|
42
|
+
|
|
43
|
+
expect(result).to.have.property('/page1');
|
|
44
|
+
expect(result).to.have.property('/page2');
|
|
45
|
+
expect(result['/page1']).to.have.lengthOf(2);
|
|
46
|
+
expect(result['/page2']).to.have.lengthOf(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should skip suggestions without URL', () => {
|
|
50
|
+
const suggestions = [
|
|
51
|
+
{
|
|
52
|
+
getId: () => 'sugg-1',
|
|
53
|
+
getData: () => ({}), // No URL
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
getId: () => 'sugg-2',
|
|
57
|
+
getData: () => ({ url: 'https://example.com/page1' }),
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const result = groupSuggestionsByUrlPath(suggestions, 'https://example.com', log);
|
|
62
|
+
|
|
63
|
+
expect(result).to.not.have.property('undefined');
|
|
64
|
+
expect(result).to.have.property('/page1');
|
|
65
|
+
expect(result['/page1']).to.have.lengthOf(1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should skip suggestions with invalid URL', () => {
|
|
69
|
+
const suggestions = [
|
|
70
|
+
{
|
|
71
|
+
getId: () => 'sugg-1',
|
|
72
|
+
getData: () => ({ url: 'not-a-valid-url' }),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
getId: () => 'sugg-2',
|
|
76
|
+
getData: () => ({ url: 'https://example.com/page1' }),
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = groupSuggestionsByUrlPath(suggestions, 'https://example.com', log);
|
|
81
|
+
|
|
82
|
+
expect(result).to.have.property('/page1');
|
|
83
|
+
expect(result['/page1']).to.have.lengthOf(1);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should skip suggestions with malformed URL that throws', () => {
|
|
87
|
+
const suggestions = [
|
|
88
|
+
{
|
|
89
|
+
getId: () => 'sugg-1',
|
|
90
|
+
getData: () => ({ url: 'http://[invalid' }), // Malformed URL that will throw
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
getId: () => 'sugg-2',
|
|
94
|
+
getData: () => ({ url: 'https://example.com/page1' }),
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const result = groupSuggestionsByUrlPath(suggestions, 'invalid-base', log);
|
|
99
|
+
|
|
100
|
+
// Should skip sugg-1 due to URL parsing error
|
|
101
|
+
expect(Object.keys(result)).to.have.lengthOf(0); // Both fail due to invalid base
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('filterEligibleSuggestions', () => {
|
|
106
|
+
const mapper = {
|
|
107
|
+
canDeploy: (suggestion) => {
|
|
108
|
+
const data = suggestion.getData();
|
|
109
|
+
if (data.shouldDeploy) {
|
|
110
|
+
return { eligible: true };
|
|
111
|
+
}
|
|
112
|
+
return { eligible: false, reason: 'Not eligible' };
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
it('should filter eligible and ineligible suggestions', () => {
|
|
117
|
+
const suggestions = [
|
|
118
|
+
{
|
|
119
|
+
getId: () => 'sugg-1',
|
|
120
|
+
getData: () => ({ shouldDeploy: true }),
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
getId: () => 'sugg-2',
|
|
124
|
+
getData: () => ({ shouldDeploy: false }),
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const result = filterEligibleSuggestions(suggestions, mapper);
|
|
129
|
+
|
|
130
|
+
expect(result.eligible).to.have.lengthOf(1);
|
|
131
|
+
expect(result.ineligible).to.have.lengthOf(1);
|
|
132
|
+
expect(result.eligible[0].getId()).to.equal('sugg-1');
|
|
133
|
+
expect(result.ineligible[0].suggestion.getId()).to.equal('sugg-2');
|
|
134
|
+
expect(result.ineligible[0].reason).to.equal('Not eligible');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should handle all eligible suggestions', () => {
|
|
138
|
+
const suggestions = [
|
|
139
|
+
{
|
|
140
|
+
getId: () => 'sugg-1',
|
|
141
|
+
getData: () => ({ shouldDeploy: true }),
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
getId: () => 'sugg-2',
|
|
145
|
+
getData: () => ({ shouldDeploy: true }),
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const result = filterEligibleSuggestions(suggestions, mapper);
|
|
150
|
+
|
|
151
|
+
expect(result.eligible).to.have.lengthOf(2);
|
|
152
|
+
expect(result.ineligible).to.have.lengthOf(0);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should handle all ineligible suggestions', () => {
|
|
156
|
+
const suggestions = [
|
|
157
|
+
{
|
|
158
|
+
getId: () => 'sugg-1',
|
|
159
|
+
getData: () => ({ shouldDeploy: false }),
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
const result = filterEligibleSuggestions(suggestions, mapper);
|
|
164
|
+
|
|
165
|
+
expect(result.eligible).to.have.lengthOf(0);
|
|
166
|
+
expect(result.ineligible).to.have.lengthOf(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should use default reason when eligibility.reason is empty', () => {
|
|
170
|
+
const mapperWithoutReason = {
|
|
171
|
+
canDeploy: () => ({ eligible: false }), // No reason provided
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const suggestions = [
|
|
175
|
+
{
|
|
176
|
+
getId: () => 'sugg-1',
|
|
177
|
+
getData: () => ({}),
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const result = filterEligibleSuggestions(suggestions, mapperWithoutReason);
|
|
182
|
+
|
|
183
|
+
expect(result.ineligible).to.have.lengthOf(1);
|
|
184
|
+
expect(result.ineligible[0].reason).to.equal('Suggestion cannot be deployed');
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|