@@ -77,10 +77,9 @@ describe('Render Product HTML', () => {
77
77
assert . strictEqual ( twitterDescription . getAttribute ( 'content' ) , expectedDescription , 'Twitter description does not match expected value' ) ;
78
78
} ) ;
79
79
80
- it ( 'should have the correct JSON-LD schema' , ( ) => {
80
+ it ( 'should have the correct JSON-LD schema with variants ' , ( ) => {
81
81
const jsonLdScript = document . querySelector ( 'script[type="application/ld+json"]' ) ;
82
82
assert . ok ( jsonLdScript , 'JSON-LD script tag should exist' ) ;
83
-
84
83
// @ts -ignore
85
84
const productTemplate = new JSONTemplate ( DEFAULT_CONTEXT ( { config } ) , product , variations ) ;
86
85
@@ -108,6 +107,44 @@ describe('Render Product HTML', () => {
108
107
} ) ;
109
108
} ) ;
110
109
110
+ it ( 'should have the correct JSON-LD schema without variants (simple product)' , ( ) => {
111
+ variations = undefined ;
112
+ const html = htmlTemplateFromContext ( DEFAULT_CONTEXT ( { config } ) , product , variations ) . render ( ) ;
113
+ dom = new JSDOM ( html ) ;
114
+ document = dom . window . document ;
115
+
116
+ const jsonLdScript = document . querySelector ( 'script[type="application/ld+json"]' ) ;
117
+
118
+ product . attributes . push ( {
119
+ name : 'special_to_date' ,
120
+ value : '2024-12-31' ,
121
+ } ) ;
122
+ // @ts -ignore
123
+ const productTemplate = new JSONTemplate ( DEFAULT_CONTEXT ( { config } ) , product , undefined ) ;
124
+
125
+ const jsonLd = JSON . parse ( jsonLdScript . textContent ) ;
126
+ assert . strictEqual ( jsonLd [ '@type' ] , 'Product' , 'JSON-LD @type should be Product' ) ;
127
+ assert . strictEqual ( jsonLd [ '@id' ] , productTemplate . constructProductURL ( ) , 'JSON-LD @id does not match product URL' ) ;
128
+ assert . strictEqual ( jsonLd . name , product . name , 'JSON-LD name does not match product name' ) ;
129
+ assert . strictEqual ( jsonLd . sku , product . sku , 'JSON-LD SKU does not match product SKU' ) ;
130
+ assert . strictEqual ( jsonLd . description , product . metaDescription , 'JSON-LD description does not match product description' ) ;
131
+ assert . strictEqual ( jsonLd . image , product . images [ 0 ] ?. url || '' , 'JSON-LD image does not match product image' ) ;
132
+ assert . strictEqual ( jsonLd . productID , product . sku , 'JSON-LD productID does not match product SKU' ) ;
133
+ assert . ok ( Array . isArray ( jsonLd . offers ) , 'JSON-LD offers should be an array' ) ;
134
+ assert . strictEqual ( jsonLd . offers . length , 1 , 'JSON-LD offers length does not match number of variants' ) ;
135
+ jsonLd . offers . forEach ( ( offer ) => {
136
+ assert . strictEqual ( offer [ '@type' ] , 'Offer' , `Offer type for variant ${ product . sku } should be Offer` ) ;
137
+ assert . strictEqual ( offer . sku , product . sku , `Offer SKU for variant ${ product . sku } does not match` ) ;
138
+ assert . strictEqual ( offer . url , productTemplate . constructProductURL ( ) , 'JSON-LD offer URL does not match' ) ;
139
+ assert . strictEqual ( offer . price , product . prices . final . amount , `Offer price for variant ${ product . sku } does not match` ) ;
140
+ assert . strictEqual ( offer . priceCurrency , product . prices . final . currency , `Offer priceCurrency for variant ${ product . sku } does not match` ) ;
141
+ assert . strictEqual ( offer . availability , product . inStock ? 'InStock' : 'OutOfStock' , `Offer availability for variant ${ product . sku } does not match` ) ;
142
+ assert . strictEqual ( offer . image , product . images [ 0 ] . url || '' , `Offer image for variant ${ product . sku } does not match` ) ;
143
+ assert . strictEqual ( offer . priceSpecification , undefined , 'Offer contains priceSpecification for variant when it should not' ) ;
144
+ assert . strictEqual ( offer . priceValidUntil , product . specialToDate , 'Offer does not contain priceValidUntil for variant' ) ;
145
+ } ) ;
146
+ } ) ;
147
+
111
148
it ( 'should have the correct JSON-LD schema with attribute overrides' , ( ) => {
112
149
variations = [
113
150
createProductVariationFixture ( { gtin : '123' } ) ,
0 commit comments