1- import { PayPalManager } from './paypal.manager ' ;
1+ import { faker } from '@faker-js/faker ' ;
22import { Kysely } from 'kysely' ;
3+
34import { DB , testAccountDatabaseSetup } from '@fxa/shared/db/mysql/account' ;
5+
6+ import { NVPSetExpressCheckoutResponseFactory } from './factories' ;
47import { PayPalClient } from './paypal.client' ;
5- import { faker } from '@faker-js/faker ' ;
8+ import { PayPalManager } from './paypal.manager ' ;
69
710describe ( 'paypalManager' , ( ) => {
8- let paypalManager : PayPalManager ;
911 let kyselyDb : Kysely < DB > ;
12+ let paypalClient : PayPalClient ;
13+ let paypalManager : PayPalManager ;
1014
1115 beforeAll ( async ( ) => {
1216 kyselyDb = await testAccountDatabaseSetup ( [
1317 'paypalCustomers' ,
1418 'accountCustomers' ,
1519 ] ) ;
16- paypalManager = new PayPalManager (
17- kyselyDb ,
18- new PayPalClient ( {
19- sandbox : false ,
20- user : faker . string . uuid ( ) ,
21- pwd : faker . string . uuid ( ) ,
22- signature : faker . string . uuid ( ) ,
23- } )
24- ) ;
20+
21+ paypalClient = new PayPalClient ( {
22+ sandbox : false ,
23+ user : faker . string . uuid ( ) ,
24+ pwd : faker . string . uuid ( ) ,
25+ signature : faker . string . uuid ( ) ,
26+ } ) ;
27+
28+ paypalManager = new PayPalManager ( kyselyDb , paypalClient ) ;
2529 } ) ;
2630
2731 afterAll ( async ( ) => {
@@ -33,4 +37,25 @@ describe('paypalManager', () => {
3337 it ( 'instantiates class (TODO: remove me)' , ( ) => {
3438 expect ( paypalManager ) . toBeTruthy ( ) ;
3539 } ) ;
40+
41+ describe ( 'getCheckoutToken' , ( ) => {
42+ it ( 'returns token and calls setExpressCheckout with passed options' , async ( ) => {
43+ const currencyCode = faker . finance . currencyCode ( ) ;
44+ const token = faker . string . uuid ( ) ;
45+ const successfulSetExpressCheckoutResponse =
46+ NVPSetExpressCheckoutResponseFactory ( {
47+ TOKEN : token ,
48+ } ) ;
49+
50+ paypalClient . setExpressCheckout = jest
51+ . fn ( )
52+ . mockResolvedValueOnce ( successfulSetExpressCheckoutResponse ) ;
53+
54+ const result = await paypalManager . getCheckoutToken ( currencyCode ) ;
55+
56+ expect ( result ) . toEqual ( successfulSetExpressCheckoutResponse . TOKEN ) ;
57+ expect ( paypalClient . setExpressCheckout ) . toBeCalledTimes ( 1 ) ;
58+ expect ( paypalClient . setExpressCheckout ) . toBeCalledWith ( { currencyCode } ) ;
59+ } ) ;
60+ } ) ;
3661} ) ;
0 commit comments