@@ -14,6 +14,7 @@ const perSeatSubscriptionUuid = uuidv4();
1414const licenseUuid = uuidv4 ( ) ;
1515const licenseTwoUuid = uuidv4 ( ) ;
1616const licenseThreeUuid = uuidv4 ( ) ;
17+ const couponUuid = uuidv4 ( ) ;
1718const perSeatBasicLicenseUuids = [ uuidv4 ( ) , uuidv4 ( ) , uuidv4 ( ) , uuidv4 ( ) , uuidv4 ( ) , uuidv4 ( ) ] ;
1819const testGrantee = '123456' ;
1920const testEmail = 'tester@domain.com' ;
@@ -231,6 +232,18 @@ describe('Subscriptions V2 Tests', () => {
231232 expect ( data ) . toEqual ( { ...subscriptionSchema , owner : 'updated-owner' } ) ;
232233 } ) ;
233234
235+ it ( 'addCoupon: Should successfully add the specified coupon to the subscription' , async ( ) => {
236+ const data = await salable . subscriptions . addCoupon ( subscriptionUuid , { couponUuid } ) ;
237+
238+ expect ( data ) . toBeUndefined ( ) ;
239+ } ) ;
240+
241+ it ( 'removeCoupon: Should successfully remove the specified coupon from the subscription' , async ( ) => {
242+ const data = await salable . subscriptions . removeCoupon ( subscriptionUuid , { couponUuid } ) ;
243+
244+ expect ( data ) . toBeUndefined ( ) ;
245+ } ) ;
246+
234247 it ( 'cancel: Should successfully cancel the subscription' , async ( ) => {
235248 const data = await salable . subscriptions . cancel ( subscriptionUuid , { when : 'now' } ) ;
236249
@@ -340,8 +353,8 @@ const invoiceSchema: Invoice = {
340353 account_tax_ids : expect . toBeOneOf ( [ expect . toBeArray ( ) , null ] ) ,
341354 amount_due : expect . any ( Number ) ,
342355 amount_paid : expect . any ( Number ) ,
343- amount_remaining : expect . any ( Number ) ,
344356 amount_overpaid : expect . any ( Number ) ,
357+ amount_remaining : expect . any ( Number ) ,
345358 amount_shipping : expect . any ( Number ) ,
346359 application : expect . toBeOneOf ( [ expect . any ( String ) , null ] ) ,
347360 application_fee_amount : expect . toBeOneOf ( [ expect . any ( Number ) , null ] ) ,
@@ -388,6 +401,7 @@ const invoiceSchema: Invoice = {
388401 on_behalf_of : expect . toBeOneOf ( [ expect . any ( String ) , null ] ) ,
389402 paid : expect . any ( Boolean ) ,
390403 paid_out_of_band : expect . any ( Boolean ) ,
404+ parent : expect . toBeObject ( ) ,
391405 payment_intent : expect . any ( String ) ,
392406 payment_settings : expect . toBeObject ( ) ,
393407 period_end : expect . any ( Number ) ,
@@ -410,7 +424,6 @@ const invoiceSchema: Invoice = {
410424 subtotal_excluding_tax : expect . any ( Number ) ,
411425 tax : expect . toBeOneOf ( [ expect . any ( Number ) , null ] ) ,
412426 test_clock : expect . toBeOneOf ( [ expect . any ( String ) , null ] ) ,
413- parent : expect . toBeObject ( ) ,
414427 total : expect . any ( Number ) ,
415428 total_discount_amounts : expect . toBeOneOf ( [ expect . toBeArray ( ) , null ] ) ,
416429 total_excluding_tax : expect . any ( Number ) ,
@@ -476,6 +489,7 @@ const stripePaymentMethodSchema = {
476489
477490const deleteTestData = async ( ) => {
478491 await prismaClient . license . deleteMany ( { } ) ;
492+ await prismaClient . couponsOnSubscriptions . deleteMany ( { } ) ;
479493 await prismaClient . subscription . deleteMany ( { } ) ;
480494} ;
481495
@@ -700,4 +714,32 @@ const generateTestData = async () => {
700714 quantity : 2 ,
701715 } ,
702716 } ) ;
717+
718+ await prismaClient . coupon . create ( {
719+ data : {
720+ uuid : couponUuid ,
721+ paymentIntegrationCouponId : stripeEnvs . couponId ,
722+ name : 'Percentage Coupon' ,
723+ duration : 'ONCE' ,
724+ discountType : 'PERCENTAGE' ,
725+ percentOff : 10 ,
726+ expiresAt : null ,
727+ maxRedemptions : null ,
728+ isTest : false ,
729+ durationInMonths : 1 ,
730+ status : 'ACTIVE' ,
731+ product : {
732+ connect : {
733+ uuid : testUuids . productUuid ,
734+ } ,
735+ } ,
736+ appliesTo : {
737+ create : {
738+ plan : {
739+ connect : { uuid : testUuids . paidPlanTwoUuid } ,
740+ } ,
741+ } ,
742+ } ,
743+ } ,
744+ } ) ;
703745} ;
0 commit comments