@@ -44,7 +44,7 @@ describe('createSubscription integration', () => {
4444 const productPurchase : ProductPurchase = {
4545 product : 'NationalDelivery' ,
4646 ratePlan : 'EverydayPlus' ,
47- firstDeliveryDate : dayjs ( ) . add ( 1 , 'month ' ) . toDate ( ) ,
47+ firstDeliveryDate : dayjs ( ) . add ( 1 , 'week ' ) . toDate ( ) ,
4848 deliveryContact : contact ,
4949 deliveryInstructions : 'Leave at front door' ,
5050 deliveryAgent : 123 ,
@@ -265,4 +265,36 @@ describe('createSubscription integration', () => {
265265 ) ?. unitPrice ,
266266 ) . toEqual ( discountAmount ) ;
267267 } ) ;
268+ test ( 'Payment schedule is not truncated by the subscription term' , async ( ) => {
269+ const inputFields : PreviewCreateSubscriptionInputFields = {
270+ stage : 'CODE' ,
271+ accountNumber : 'A01036826' ,
272+ currency : currency ,
273+ productPurchase : productPurchase ,
274+ } ;
275+ const client = await ZuoraClient . create ( 'CODE' ) ;
276+ const response = await previewCreateSubscription (
277+ client ,
278+ productCatalog ,
279+ mockPromotions ,
280+ inputFields ,
281+ ) ;
282+
283+ // Check that all Digital Pack items have the same amount.
284+ // Previously we had a bug where the last item in the payment schedule was only covering the period
285+ // up until the end of the subscription term, causing it to be a different amount from all the other items.
286+ const digitalPackInvoiceItems =
287+ response . previewResult . invoices [ 0 ] ?. invoiceItems . filter (
288+ ( item ) => item . chargeName === 'Digital Pack' ,
289+ ) ?? [ ] ;
290+
291+ const [ firstDigitalPackItem ] = digitalPackInvoiceItems ;
292+ expect (
293+ digitalPackInvoiceItems . every (
294+ ( item ) =>
295+ firstDigitalPackItem !== undefined &&
296+ item . amountWithoutTax === firstDigitalPackItem . amountWithoutTax ,
297+ ) ,
298+ ) . toBe ( true ) ;
299+ } ) ;
268300} ) ;
0 commit comments