Skip to content

Commit b0d9e5f

Browse files
authored
fix product schema and add fields (#3177)
1 parent 46a32c5 commit b0d9e5f

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

lib/metadata/__snapshots__/generate.spec.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ exports[`generates correct metadata for: > dynamic route with API data 1`] = `
2626
"name": "Tether",
2727
},
2828
"description": "USDT is a stablecoin",
29-
"logo": "https://example.com/usdt.png",
29+
"image": "https://example.com/usdt.png",
3030
"name": "USDT",
3131
"offers": {
3232
"@type": "Offer",
33+
"availability": "InStock",
3334
"price": "1.00",
3435
"priceCurrency": "USD",
36+
"priceValidUntil": "2024-01-02T00:00:00.000Z",
3537
},
3638
"productID": "0x12345",
3739
"url": "http://localhost:3000/token/0x12345",

lib/metadata/generate.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ApiData } from './types';
22

33
import type { Route } from 'nextjs-routes';
44

5-
import { describe, it, expect } from 'vitest';
5+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
66

77
import generate from './generate';
88

@@ -49,6 +49,16 @@ const TEST_CASES = [
4949
];
5050

5151
describe('generates correct metadata for:', () => {
52+
beforeEach(() => {
53+
// Mock date to a fixed value: 2024-01-01T00:00:00.000Z
54+
vi.useFakeTimers();
55+
vi.setSystemTime(new Date('2024-01-01T00:00:00.000Z'));
56+
});
57+
58+
afterEach(() => {
59+
vi.useRealTimers();
60+
});
61+
5262
TEST_CASES.forEach((testCase) => {
5363
it(`${ testCase.title }`, () => {
5464
const result = generate(testCase.route, testCase.apiData);

lib/metadata/generateProductSchema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function generateProductSchema<Pathname extends Route['pathname']
4141
'@type': 'Product',
4242
name: tokenData.name || tokenData.symbol || undefined,
4343
description: tokenData.description || undefined,
44-
logo: tokenData.icon_url || undefined,
44+
image: tokenData.icon_url || undefined,
4545
url: tokenUrl,
4646
productID: tokenData.address_hash,
4747
};
@@ -60,6 +60,8 @@ export default function generateProductSchema<Pathname extends Route['pathname']
6060
'@type': 'Offer',
6161
price: tokenData.exchange_rate,
6262
priceCurrency: 'USD',
63+
priceValidUntil: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(),
64+
availability: 'InStock',
6365
};
6466
}
6567

lib/metadata/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ export interface ProductSchema {
1919
'@type': 'Product';
2020
name?: string;
2121
description?: string;
22-
logo?: string;
22+
image?: string;
2323
url?: string;
2424
productID?: string;
2525
offers?: {
2626
'@type': 'Offer';
2727
price?: string;
2828
priceCurrency?: string;
29+
priceValidUntil?: string;
30+
availability?: string;
2931
};
3032
brand?: {
3133
'@type': 'Brand';

0 commit comments

Comments
 (0)