Skip to content

Commit f9d9d30

Browse files
authored
feat: add scraped at time to faq suggestions (#1592)
Please ensure your pull request adheres to the following guidelines: - [ ] make sure to link the related issues in this description - [ ] when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes - [ ] If data sources for any opportunity has been updated/added, please update the [wiki](https://wiki.corp.adobe.com/display/AEMSites/Data+Sources+for+Opportunities) for same opportunity. ## Related Issues Thanks for contributing!
1 parent b2b97a8 commit f9d9d30

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/faqs/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function getJsonFaqSuggestion(faqs) {
100100
sources: normalizeSources(suggestion.sources),
101101
questionRelevanceReason: suggestion.questionRelevanceReason,
102102
answerSuitabilityReason: suggestion.answerSuitabilityReason,
103+
scrapedAt: suggestion.scrapedAt || new Date().toISOString(),
103104
},
104105
});
105106
});

test/audits/faqs/utils.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,59 @@ describe('FAQ Utils', () => {
372372
]);
373373
});
374374

375+
it('should use provided scrapedAt timestamp when available', () => {
376+
const testTimestamp = '2025-11-17T18:53:21.143931';
377+
const faqs = [
378+
{
379+
url: 'https://www.adobe.com/products/test',
380+
topic: 'test',
381+
suggestions: [
382+
{
383+
isAnswerSuitable: true,
384+
isQuestionRelevant: true,
385+
question: 'Question?',
386+
answer: 'Answer.',
387+
sources: [],
388+
scrapedAt: testTimestamp,
389+
},
390+
],
391+
},
392+
];
393+
394+
const suggestions = getJsonFaqSuggestion(faqs);
395+
396+
expect(suggestions[0].item.scrapedAt).to.equal(testTimestamp);
397+
});
398+
399+
it('should generate current timestamp when scrapedAt is missing', () => {
400+
const faqs = [
401+
{
402+
url: 'https://www.adobe.com/products/test',
403+
topic: 'test',
404+
suggestions: [
405+
{
406+
isAnswerSuitable: true,
407+
isQuestionRelevant: true,
408+
question: 'Question?',
409+
answer: 'Answer.',
410+
sources: [],
411+
// No scrapedAt property
412+
},
413+
],
414+
},
415+
];
416+
417+
const beforeTime = new Date().toISOString();
418+
const suggestions = getJsonFaqSuggestion(faqs);
419+
const afterTime = new Date().toISOString();
420+
421+
expect(suggestions[0].item.scrapedAt).to.be.a('string');
422+
expect(suggestions[0].item.scrapedAt).to.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/);
423+
// Timestamp should be between before and after
424+
expect(suggestions[0].item.scrapedAt >= beforeTime).to.be.true;
425+
expect(suggestions[0].item.scrapedAt <= afterTime).to.be.true;
426+
});
427+
375428
});
376429
});
377430

0 commit comments

Comments
 (0)