11import * as assert from "assert" ;
2- import { testingApiClient , startNockRec } from "./helpers/integrationTestsHelpers" ;
3- import { BatchFactory } from "./factories/BatchFactory" ;
4- import { RecipientFactory } from "./factories/RecipientFactory" ;
5- import { RecipientAccountFactory } from "./factories/RecipientAccountFactory" ;
6-
7- const batchFactory = new BatchFactory ( ) ;
8- const recipientFactory = new RecipientFactory ( ) ;
9- const recipientAccountFactory = new RecipientAccountFactory ( ) ;
2+ import { testingApiClient , startNockRec } from "./helpers/integrationTestsHelpers" ;
3+ import { BatchFactory } from "./factories/BatchFactory" ;
4+ import { RecipientFactory } from "./factories/RecipientFactory" ;
5+ import { RecipientAccountFactory } from "./factories/RecipientAccountFactory" ;
6+ import { Batch } from "../../lib" ;
7+
8+ let batchFactory : BatchFactory ;
9+ let recipientFactory : RecipientFactory ;
10+ let recipientAccountFactory : RecipientAccountFactory ;
11+
12+ before ( async ( ) => {
13+ batchFactory = new BatchFactory ( ) ;
14+ recipientFactory = new RecipientFactory ( ) ;
15+ recipientAccountFactory = new RecipientAccountFactory ( ) ;
16+ } ) ;
1017
1118async function createRecipient ( email : string ) {
1219 const recipient = await recipientFactory . createResource ( { email } ) ;
1320 await recipientAccountFactory . createResource ( { recipient } ) ;
21+
1422 return recipient ;
1523 }
1624
17- describe ( "Batch/Payment Integration " , ( ) => {
25+ describe ( "Batch" , ( ) => {
1826 it ( 'creates a batch' , async ( ) => {
1927 const nockDone = await startNockRec ( 'batch-create.json' ) ;
2028
2129 const batch = await batchFactory . createResource ( ) ;
2230 const all = await testingApiClient . batch . all ( ) ;
2331
32+ nockDone ( ) ;
33+
2434 assert . ok ( batch ) ;
2535 assert . ok ( batch . id ) ;
2636 assert . ok ( all . length > 0 ) ;
2737
28- nockDone ( ) ;
29- } )
38+ assert . strictEqual ( batch . constructor , Batch ) ;
39+ assert . strictEqual ( batch . description , batchFactory . defaultAttrs . description ) ;
40+ } ) ;
3041
3142 it ( "updates a batch" , async ( ) => {
3243 const nockDone = await startNockRec ( 'batch-update.json' ) ;
@@ -36,20 +47,21 @@ describe("Batch/Payment Integration", () => {
3647 } ) ;
3748 assert . strictEqual ( batch . description , "Integration Test Update" ) ;
3849
39- await testingApiClient . batch . update ( batch . id , {
50+ batch = await testingApiClient . batch . update ( batch . id , {
4051 description : "Integration Test Update 2" ,
4152 } ) ;
42- batch = await testingApiClient . batch . find ( batch . id ) ;
53+
54+ nockDone ( ) ;
55+
4356 assert . ok ( batch ) ;
57+
58+ assert . strictEqual ( batch . constructor , Batch ) ;
4459 assert . strictEqual ( batch . description , "Integration Test Update 2" ) ;
4560 assert . strictEqual ( batch . status , "open" ) ;
61+ } ) ;
4662
47- nockDone ( ) ;
48- } )
49-
50- //tslint:disable-next-line:mocha-no-side-effect-code
5163 it ( "create with payments" , async ( ) => {
52- const nockDone = await startNockRec ( 'batch-create-with-payments.json' )
64+ const nockDone = await startNockRec ( 'batch-create-with-payments.json' ) ;
5365
5466 const recipient = await createRecipient ( '[email protected] ' ) ; 5567 const otherRecipient = await createRecipient ( '[email protected] ' ) ; @@ -65,59 +77,58 @@ describe("Batch/Payment Integration", () => {
6577 sourceAmount : "10.00" ,
6678 recipient : { id : otherRecipient . id } ,
6779 } ,
68- ]
80+ ] ,
6981 } ) ;
7082
71- assert . ok ( batch ) ;
72- assert . ok ( batch . id ) ;
7383 const findBatch = await testingApiClient . batch . find ( batch . id ) ;
7484
85+ nockDone ( ) ;
86+
87+ assert . ok ( batch ) ;
88+ assert . ok ( batch . id ) ;
7589 assert . ok ( findBatch ) ;
90+
91+ assert . strictEqual ( batch . constructor , Batch ) ;
7692 assert . strictEqual ( batch . totalPayments , 2 ) ;
7793
78- let payments = await testingApiClient . batch . paymentList ( batch . id ) ;
94+ const payments = await testingApiClient . batch . paymentList ( batch . id ) ;
7995 for ( const item of payments ) {
8096 assert . strictEqual ( item . status , "pending" ) ;
8197 }
82-
83- nockDone ( ) ;
8498 } ) ;
8599
86- //tslint:disable-next-line:mocha-no-side-effect-code
87100 it ( "starts processing batch payments" , async ( ) => {
88- const nockDone = await startNockRec ( 'batch-processing-payments.json' )
101+ const nockDone = await startNockRec ( 'batch-processing-payments.json' ) ;
89102
90103 const recipient = await createRecipient ( '[email protected] ' ) ; 91- const other_recipient = await createRecipient ( '[email protected] ' ) ; 104+ const otherRecipient = await createRecipient ( '[email protected] ' ) ; 92105
93106 const batch = await batchFactory . createResource ( {
94107 payments : [
95108 {
96109 targetAmount : "10.00" ,
97110 targetCurrency : "EUR" ,
98- recipient : { id : recipient . id } ,
111+ recipient : { id : recipient . id } ,
99112 } ,
100113 {
101114 sourceAmount : "10.00" ,
102- recipient : { id : other_recipient . id } ,
115+ recipient : { id : otherRecipient . id } ,
103116 } ,
104- ]
117+ ] ,
105118 } ) ;
106119
107- assert . ok ( batch ) ;
108- assert . ok ( batch . id ) ;
109-
110120 const summary = await testingApiClient . batch . summary ( batch . id ) ;
111- assert . strictEqual ( 2 , summary . detail [ "bank-transfer" ] . count , "Bad Count" ) ;
112-
113121 const quote = await testingApiClient . batch . generateQuote ( batch . id ) ;
114- assert . ok ( quote , "failed to get quote" ) ;
115122
116123 // There's an issue here when it runs too quick. It returns "Operation In Progress"
117124 // Sleep when running against real API
118125 const start = await testingApiClient . batch . startProcessing ( batch . id ) ;
119- assert . ok ( start , "Failed to start" ) ;
120126
121127 nockDone ( ) ;
128+
129+ assert . ok ( batch ) ;
130+ assert . ok ( batch . id ) ;
131+ assert . ok ( quote , "failed to get quote" ) ;
132+ assert . ok ( start , "Failed to start" ) ;
122133 } ) ;
123134} ) ;
0 commit comments