@@ -16,7 +16,7 @@ const baseProductData = {
1616 name : "Test Product" ,
1717 description : null ,
1818 recurringInterval : null ,
19- price : baseProductPriceData ,
19+ prices : [ baseProductPriceData ] ,
2020} ;
2121
2222describe ( "Product Schemas" , ( ) => {
@@ -148,12 +148,14 @@ describe("Product Schemas", () => {
148148 test ( "should validate product with a custom price" , ( ) => {
149149 const productWithCustomPrice = {
150150 ...baseProductData ,
151- price : {
152- ...baseProductPriceData ,
153- id : "price_2" ,
154- amountType : "CUSTOM" as const ,
155- priceAmount : null ,
156- } ,
151+ prices : [
152+ {
153+ ...baseProductPriceData ,
154+ id : "price_2" ,
155+ amountType : "CUSTOM" as const ,
156+ priceAmount : null ,
157+ } ,
158+ ] ,
157159 } ;
158160
159161 const result = CheckoutProductSchema . safeParse ( productWithCustomPrice ) ;
@@ -180,23 +182,23 @@ describe("Product Schemas", () => {
180182 expect ( result . success ) . toBe ( false ) ;
181183 } ) ;
182184
183- test ( "should reject product without price field" , ( ) => {
184- const productWithoutPrice = {
185+ test ( "should reject product without prices field" , ( ) => {
186+ const productWithoutPrices = {
185187 ...baseProductData ,
186- price : undefined ,
188+ prices : undefined ,
187189 } ;
188190
189- const result = CheckoutProductSchema . safeParse ( productWithoutPrice ) ;
191+ const result = CheckoutProductSchema . safeParse ( productWithoutPrices ) ;
190192 expect ( result . success ) . toBe ( false ) ;
191193 } ) ;
192194
193- test ( "should allow product with null price " , ( ) => {
194- const productWithNullPrice = {
195+ test ( "should validate product with empty prices array " , ( ) => {
196+ const productWithEmptyPrices = {
195197 ...baseProductData ,
196- price : null ,
198+ prices : [ ] ,
197199 } ;
198200
199- const result = CheckoutProductSchema . safeParse ( productWithNullPrice ) ;
201+ const result = CheckoutProductSchema . safeParse ( productWithEmptyPrices ) ;
200202 expect ( result . success ) . toBe ( true ) ;
201203 } ) ;
202204
@@ -210,13 +212,15 @@ describe("Product Schemas", () => {
210212 expect ( result . success ) . toBe ( false ) ;
211213 } ) ;
212214
213- test ( "should reject product with invalid price object " , ( ) => {
215+ test ( "should reject product with invalid price in prices array " , ( ) => {
214216 const productWithInvalidPrice = {
215217 ...baseProductData ,
216- price : {
217- ...baseProductPriceData ,
218- amountType : "INVALID_TYPE" as any ,
219- } ,
218+ prices : [
219+ {
220+ ...baseProductPriceData ,
221+ amountType : "INVALID_TYPE" as any ,
222+ } ,
223+ ] ,
220224 } ;
221225
222226 const result = CheckoutProductSchema . safeParse ( productWithInvalidPrice ) ;
@@ -250,32 +254,38 @@ describe("Product Schemas", () => {
250254 {
251255 ...baseProductData ,
252256 id : "product_fixed" ,
253- price : {
254- ...baseProductPriceData ,
255- id : "price_fixed" ,
256- amountType : "FIXED" as const ,
257- priceAmount : 2999 ,
258- } ,
257+ prices : [
258+ {
259+ ...baseProductPriceData ,
260+ id : "price_fixed" ,
261+ amountType : "FIXED" as const ,
262+ priceAmount : 2999 ,
263+ } ,
264+ ] ,
259265 } ,
260266 {
261267 ...baseProductData ,
262268 id : "product_custom" ,
263- price : {
264- ...baseProductPriceData ,
265- id : "price_custom" ,
266- amountType : "CUSTOM" as const ,
267- priceAmount : null ,
268- } ,
269+ prices : [
270+ {
271+ ...baseProductPriceData ,
272+ id : "price_custom" ,
273+ amountType : "CUSTOM" as const ,
274+ priceAmount : null ,
275+ } ,
276+ ] ,
269277 } ,
270278 {
271279 ...baseProductData ,
272280 id : "product_free" ,
273- price : {
274- ...baseProductPriceData ,
275- id : "price_free" ,
276- amountType : "FREE" as const ,
277- priceAmount : 0 ,
278- } ,
281+ prices : [
282+ {
283+ ...baseProductPriceData ,
284+ id : "price_free" ,
285+ amountType : "FREE" as const ,
286+ priceAmount : 0 ,
287+ } ,
288+ ] ,
279289 } ,
280290 ] ;
281291
0 commit comments