Skip to content

Commit 51663ff

Browse files
dicagnodylandepass
andauthored
feat: product:lastModifiedAt from Catalog Service (#68)
* feat: product:lastModifiedAt from Catalog Service * chore: better meta name * fix: verify last modified exists but don't check value in post-deploy tests * fix: post-deploy tests * fix: tests --------- Co-authored-by: Dylan Depass <[email protected]>
1 parent 0595cf9 commit 51663ff

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

src/content/queries/cs-product.js

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const adapter = (config, productData) => {
3737
const product = {
3838
sku: productData.sku,
3939
name: productData.name,
40+
lastModifiedAt: productData.lastModifiedAt,
4041
metaTitle: productData.metaTitle,
4142
metaDescription: productData.metaDescription,
4243
metaKeyword: productData.metaKeyword,
@@ -153,6 +154,7 @@ export default ({ sku, imageRoles = [], linkTypes = [] }) => gql`{
153154
) {
154155
id
155156
sku
157+
lastModifiedAt
156158
name
157159
metaTitle
158160
metaDescription

src/templates/html/HTMLTemplate.js

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ ${HTMLTemplate.metaName('urlKey', product.urlKey)}
129129
${HTMLTemplate.metaName('externalId', product.externalId)}
130130
${HTMLTemplate.metaName('addToCartAllowed', product.addToCartAllowed)}
131131
${HTMLTemplate.metaName('inStock', product.inStock ? 'true' : 'false')}
132+
${HTMLTemplate.metaName('lastModifiedAtCS', product.lastModifiedAt)}
132133
${HTMLTemplate.metaProperty('product:availability', product.inStock ? 'In stock' : 'Out of stock')}
133134
${HTMLTemplate.metaProperty('product:price.amount', product.prices?.final?.amount)}
134135
${HTMLTemplate.metaProperty('product:price.currency', product.prices?.final?.currency)}`;

src/types.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ declare global {
199199
rating?: Rating;
200200
links?: Link[];
201201

202+
// Coming only from Catalog Service at the time of writing:
203+
lastModifiedAt?: string;
204+
202205
// not handled currently:
203206
externalParentId?: string;
204207
variantSku?: string;

test/post-deploy.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ describe('Post-Deploy Tests', () => {
6565
const expected = await getHTMLFixture('bella-tank');
6666

6767
assert.strictEqual(res.status, 200);
68-
const actual = await res.text();
68+
let actual = await res.text();
6969
const differ = new HtmlDiffer();
7070

71+
const regex = /<meta\s+name="lastModifiedAtCS"\s+content="[^"]*"\s*>/;
72+
const match = actual.match(regex);
73+
assert(match, 'lastModifiedAtCS should be present');
74+
75+
actual = actual.replace(regex, '');
76+
7177
// @ts-ignore
7278
assert.ok(differ.isEqual(actual, expected));
7379
});

test/templates/html/index.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,16 @@ describe('Render Product HTML', () => {
466466
const ogImage = document.querySelector('meta[name="image"]');
467467
assert.strictEqual(ogImage.getAttribute('content'), '/media/catalog/product/t/s/test-sku.png');
468468
});
469+
470+
it('lastModifiedAtCS is not present if lastModifiedAt is undefined', () => {
471+
product.lastModifiedAt = undefined;
472+
473+
const html = htmlTemplateFromContext(DEFAULT_CONTEXT({ config }), product, variations).render();
474+
475+
dom = new JSDOM(html);
476+
document = dom.window.document;
477+
478+
const metaProductLastModified = document.querySelector('meta[name="lastModifiedAtCS"]');
479+
assert(!metaProductLastModified, 'meta[name="lastModifiedAtCS"] should not be in the document');
480+
});
469481
});

0 commit comments

Comments
 (0)