@@ -19,8 +19,12 @@ import {
1919 StripeSubscriptionFactory ,
2020 StripeSubscriptionItemFactory ,
2121 MockStripeConfigProvider ,
22+ StripeCouponFactory ,
2223} from '@fxa/payments/stripe' ;
23- import { PromotionCodeCouldNotBeAttachedError } from './error' ;
24+ import {
25+ CouponErrorInvalid ,
26+ PromotionCodeCouldNotBeAttachedError ,
27+ } from './error' ;
2428import { STRIPE_PRICE_METADATA } from './types' ;
2529import { SubscriptionManager } from './subscription.manager' ;
2630
@@ -157,8 +161,13 @@ describe('PromotionCodeManager', () => {
157161
158162 describe ( 'assertValidPromotionCodeNameForPrice' , ( ) => {
159163 it ( 'resolves correctly when valid' , async ( ) => {
160- const mockPromotionCode = StripePromotionCodeFactory ( ) ;
161164 const mockPrice = StripePriceFactory ( ) ;
165+ const mockPromotionCode = StripePromotionCodeFactory ( {
166+ coupon : StripeCouponFactory ( {
167+ currency : mockPrice . currency ,
168+ } ) ,
169+ } ) ;
170+ const mockCartCurrency = mockPrice . currency ;
162171
163172 jest
164173 . spyOn ( promotionCodeManager , 'retrieveByName' )
@@ -170,14 +179,16 @@ describe('PromotionCodeManager', () => {
170179 await expect (
171180 promotionCodeManager . assertValidPromotionCodeNameForPrice (
172181 mockPromotionCode . code ,
173- mockPrice
182+ mockPrice ,
183+ mockCartCurrency
174184 )
175185 ) . resolves . toEqual ( undefined ) ;
176186 } ) ;
177187
178188 it ( 'throws an error if promotion code is not found' , async ( ) => {
179189 const mockPromotionCode = StripePromotionCodeFactory ( ) ;
180190 const mockPrice = StripePriceFactory ( ) ;
191+ const mockCartCurrency = mockPrice . currency ;
181192
182193 jest
183194 . spyOn ( stripeClient , 'promotionCodesList' )
@@ -186,14 +197,16 @@ describe('PromotionCodeManager', () => {
186197 await expect ( ( ) =>
187198 promotionCodeManager . assertValidPromotionCodeNameForPrice (
188199 mockPromotionCode . code ,
189- mockPrice
200+ mockPrice ,
201+ mockCartCurrency
190202 )
191203 ) . rejects . toBeInstanceOf ( PromotionCodeCouldNotBeAttachedError ) ;
192204 } ) ;
193205
194206 it ( 'throws an error if promotion code is not valid' , async ( ) => {
195207 const mockPromotionCode = StripePromotionCodeFactory ( ) ;
196208 const mockPrice = StripePriceFactory ( ) ;
209+ const mockCartCurrency = mockPrice . currency ;
197210
198211 jest
199212 . spyOn ( promotionCodeManager , 'retrieveByName' )
@@ -207,10 +220,35 @@ describe('PromotionCodeManager', () => {
207220 await expect (
208221 promotionCodeManager . assertValidPromotionCodeNameForPrice (
209222 mockPromotionCode . code ,
210- mockPrice
223+ mockPrice ,
224+ mockCartCurrency
211225 )
212226 ) . rejects . toBeInstanceOf ( PromotionCodeCouldNotBeAttachedError ) ;
213227 } ) ;
228+
229+ it ( 'throws an error if currencies do no match' , async ( ) => {
230+ const mockPrice = StripePriceFactory ( {
231+ currency : 'cad' ,
232+ } ) ;
233+ const mockPromotionCode = StripePromotionCodeFactory ( {
234+ coupon : StripeCouponFactory ( {
235+ currency : 'cad' ,
236+ } ) ,
237+ } ) ;
238+ const mockCartCurrency = 'usd' ;
239+
240+ jest
241+ . spyOn ( promotionCodeManager , 'retrieveByName' )
242+ . mockResolvedValue ( mockPromotionCode ) ;
243+
244+ await expect (
245+ promotionCodeManager . assertValidPromotionCodeNameForPrice (
246+ mockPromotionCode . code ,
247+ mockPrice ,
248+ mockCartCurrency
249+ )
250+ ) . rejects . toBeInstanceOf ( CouponErrorInvalid ) ;
251+ } ) ;
214252 } ) ;
215253
216254 describe ( 'applyPromoCodeToSubscription' , ( ) => {
0 commit comments