Skip to content

Commit 8778428

Browse files
Merge pull request #19363 from mozilla/polish-fix-pm-manager-unit-tests
polish(payments-next): Remove "any" from paymentMethod.manager.spec.
2 parents 468510b + 6e35489 commit 8778428

4 files changed

Lines changed: 73 additions & 13 deletions

File tree

libs/payments/customer/src/lib/paymentMethod.manager.spec.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
StripeCustomerFactory,
2222
StripePaymentMethodFactory,
2323
StripeSubscriptionFactory,
24+
StripeCardPaymentMethodFactory,
2425
} from '@fxa/payments/stripe';
2526
import { MockAccountDatabaseNestFactory } from '@fxa/shared/db/mysql/account';
2627
import { MockStatsDProvider } from '@fxa/shared/metrics/statsd';
@@ -159,11 +160,7 @@ describe('PaymentMethodManager', () => {
159160
},
160161
});
161162

162-
const mockPaymentMethod = StripeResponseFactory(
163-
StripePaymentMethodFactory({
164-
type: 'card',
165-
})
166-
);
163+
const mockPaymentMethod = StripeResponseFactory(StripeCardPaymentMethodFactory());
167164
jest.spyOn(paymentMethodManager, 'retrieve').mockResolvedValue(mockPaymentMethod);
168165

169166
await expect(
@@ -222,10 +219,9 @@ describe('PaymentMethodManager', () => {
222219
});
223220

224221
const mockPaymentMethod = StripeResponseFactory(
225-
{
226-
type: 'card',
227-
card: { wallet: { type: 'apple_pay' } },
228-
} as any
222+
StripeCardPaymentMethodFactory({
223+
walletType: 'apple_pay'
224+
})
229225
);
230226
jest.spyOn(paymentMethodManager, 'retrieve').mockResolvedValue(mockPaymentMethod);
231227

@@ -248,10 +244,9 @@ describe('PaymentMethodManager', () => {
248244
});
249245

250246
const mockPaymentMethod = StripeResponseFactory(
251-
{
252-
type: 'card',
253-
card: { wallet: { type: 'google_pay' } },
254-
} as any
247+
StripeCardPaymentMethodFactory({
248+
walletType: 'google_pay'
249+
})
255250
);
256251
jest.spyOn(paymentMethodManager, 'retrieve').mockResolvedValue(mockPaymentMethod);
257252

libs/payments/stripe/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export {
3333
} from './lib/factories/subscription.factory';
3434
export { StripePromotionCodeFactory } from './lib/factories/promotion-code.factory';
3535
export { StripePaymentMethodFactory } from './lib/factories/payment-method.factory';
36+
export { StripeCardPaymentMethodFactory } from './lib/factories/card-payment-method.factory';
3637
export { StripePaymentIntentFactory } from './lib/factories/payment-intent.factory';
3738
export { StripeSetupIntentFactory } from './lib/factories/setup-intent.factory';
3839
export { StripeTaxRateFactory } from './lib/factories/tax-rate.factory';
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import { faker } from '@faker-js/faker';
6+
import { StripePaymentMethod, StripeWalletType } from '../stripe.client.types';
7+
8+
export const StripeCardPaymentMethodFactory = (
9+
override?: Partial<StripePaymentMethod> & { walletType?: StripeWalletType }
10+
): StripePaymentMethod => ({
11+
id: `pm_${faker.string.alphanumeric({ length: 14 })}`,
12+
object: 'payment_method',
13+
billing_details: {
14+
address: {
15+
city: null,
16+
country: null,
17+
line1: null,
18+
line2: null,
19+
postal_code: null,
20+
state: null,
21+
},
22+
email: null,
23+
name: null,
24+
phone: null,
25+
},
26+
card: {
27+
brand: 'visa',
28+
checks: {
29+
address_line1_check: null,
30+
address_postal_code_check: null,
31+
cvc_check: 'unchecked',
32+
},
33+
country: faker.location.countryCode(),
34+
display_brand: 'visa',
35+
exp_month: faker.date.future().getUTCMonth(),
36+
exp_year: faker.date.future().getUTCFullYear(),
37+
fingerprint: faker.string.uuid(),
38+
funding: 'credit',
39+
generated_from: {
40+
charge: null,
41+
payment_method_details: null,
42+
setup_attempt: null,
43+
},
44+
last4: faker.string.numeric({ length: 4 }),
45+
networks: {
46+
available: ['visa'],
47+
preferred: null,
48+
},
49+
three_d_secure_usage: {
50+
supported: true,
51+
},
52+
wallet: override?.walletType
53+
? { type: override.walletType, dynamic_last4: null }
54+
: null,
55+
},
56+
created: faker.date.past().getTime() / 1000,
57+
customer: null,
58+
livemode: true,
59+
metadata: {},
60+
type: 'card',
61+
...override,
62+
});

libs/payments/stripe/src/lib/stripe.client.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ export type StripePaymentMethod = NegotiateExpanded<
353353
'customer'
354354
>;
355355

356+
export type StripeWalletType = 'apple_pay' | 'google_pay';
357+
356358
/**
357359
* Stripe.PaymentIntent with expanded fields removed
358360
*/

0 commit comments

Comments
 (0)