@@ -8,6 +8,7 @@ import type {
88import { describe , expect , it } from 'vitest' ;
99
1010import {
11+ billingDiscountRedemptionFromJSON ,
1112 billingPaymentTotalsFromJSON ,
1213 billingSubscriptionItemNextPaymentFromJSON ,
1314 billingSubscriptionNextPaymentFromJSON ,
@@ -40,6 +41,15 @@ const nextPaymentTotalsJSON = (): BillingTotalsJSON => ({
4041 cycle_days_total : 30 ,
4142 cycle_passed_percent : 50 ,
4243 } ,
44+ discount : {
45+ amount : moneyJSON ( 1000 ) ,
46+ discount_id : 'discount_123' ,
47+ name : 'Welcome' ,
48+ effect : 'percentage' ,
49+ percent_off : 20 ,
50+ promo_code : 'WELCOME20' ,
51+ cycles_remaining : 2 ,
52+ } ,
4353 total : moneyJSON ( 500 ) ,
4454 } ,
4555 total_due_after_free_trial : null ,
@@ -109,6 +119,14 @@ describe('billingPaymentTotalsFromJSON', () => {
109119 cycle_days_total : 30 ,
110120 cycle_passed_percent : 3 ,
111121 } ,
122+ discount : {
123+ amount : moneyJSON ( 100 ) ,
124+ discount_id : 'discount_123' ,
125+ name : 'Fixed discount' ,
126+ effect : 'fixed_amount' ,
127+ amount_off : moneyJSON ( 100 ) ,
128+ cycles_remaining : null ,
129+ } ,
112130 total : moneyJSON ( 16 ) ,
113131 } ,
114132 } ;
@@ -117,6 +135,14 @@ describe('billingPaymentTotalsFromJSON', () => {
117135
118136 expect ( totals . discounts ?. proration ?. amount . amount ) . toBe ( 16 ) ;
119137 expect ( totals . discounts ?. proration ?. cycleDaysPassed ) . toBe ( 1 ) ;
138+ expect ( totals . discounts ?. discount ) . toMatchObject ( {
139+ amount : { amount : 100 } ,
140+ discountId : 'discount_123' ,
141+ name : 'Fixed discount' ,
142+ effect : 'fixed_amount' ,
143+ amountOff : { amount : 100 , amountFormatted : '1.00' , currency : 'USD' , currencySymbol : '$' } ,
144+ cyclesRemaining : null ,
145+ } ) ;
120146 expect ( totals . discounts ?. total . amount ) . toBe ( 16 ) ;
121147 } ) ;
122148
@@ -209,6 +235,15 @@ describe('billingSubscriptionNextPaymentFromJSON', () => {
209235 cycleDaysTotal : 30 ,
210236 cyclePassedPercent : 50 ,
211237 } ,
238+ discount : {
239+ amount : { amount : 1000 } ,
240+ discountId : 'discount_123' ,
241+ name : 'Welcome' ,
242+ effect : 'percentage' ,
243+ percentOff : 20 ,
244+ promoCode : 'WELCOME20' ,
245+ cyclesRemaining : 2 ,
246+ } ,
212247 total : { amount : 500 } ,
213248 } ,
214249 perUnitTotals : [ { name : 'seats' , blockSize : 1 } ] ,
@@ -223,6 +258,55 @@ describe('billingSubscriptionNextPaymentFromJSON', () => {
223258 } ) ;
224259} ) ;
225260
261+ describe ( 'billingDiscountRedemptionFromJSON' , ( ) => {
262+ it ( 'maps an applied subscription item discount' , ( ) => {
263+ const discount = billingDiscountRedemptionFromJSON ( {
264+ object : 'commerce_discount_redemption' ,
265+ id : 'redemption_123' ,
266+ subscription_item_id : 'sub_item_123' ,
267+ discount_id : 'discount_123' ,
268+ name : 'Welcome' ,
269+ source : 'promo_code' ,
270+ promo_code : 'WELCOME20' ,
271+ effect : 'fixed_amount' ,
272+ amount_off : moneyJSON ( 500 ) ,
273+ amount : moneyJSON ( 400 ) ,
274+ cycles_remaining : 2 ,
275+ cycles_applied : 1 ,
276+ status : 'active' ,
277+ redeemed_at : 1_609_459_200_000 ,
278+ redeemed_by : 'user_123' ,
279+ } ) ;
280+
281+ expect ( discount ) . toMatchObject ( {
282+ id : 'redemption_123' ,
283+ subscriptionItemId : 'sub_item_123' ,
284+ discountId : 'discount_123' ,
285+ name : 'Welcome' ,
286+ source : 'promo_code' ,
287+ promoCode : 'WELCOME20' ,
288+ effect : 'fixed_amount' ,
289+ amountOff : {
290+ amount : 500 ,
291+ amountFormatted : '5.00' ,
292+ currency : 'USD' ,
293+ currencySymbol : '$' ,
294+ } ,
295+ amount : {
296+ amount : 400 ,
297+ amountFormatted : '4.00' ,
298+ currency : 'USD' ,
299+ currencySymbol : '$' ,
300+ } ,
301+ cyclesRemaining : 2 ,
302+ cyclesApplied : 1 ,
303+ status : 'active' ,
304+ redeemedAt : new Date ( '2021-01-01T00:00:00.000Z' ) ,
305+ redeemedBy : 'user_123' ,
306+ } ) ;
307+ } ) ;
308+ } ) ;
309+
226310describe ( 'billingSubscriptionItemNextPaymentFromJSON' , ( ) => {
227311 it ( 'maps amount, date, and per_unit_totals' , ( ) => {
228312 const data : BillingSubscriptionItemNextPaymentJSON = {
0 commit comments