Skip to content

Commit cbd88ad

Browse files
authored
Merge pull request #10 from zero-bites/test-epic-final-touches
[Chore] Post-characterization testing adjustments
2 parents 1fb015b + a652224 commit cbd88ad

29 files changed

+1994
-1018
lines changed

.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"ui": "bdd",
33
"timeout": 15000,
44
"extension": ["ts"],
5-
"spec": ["test/integration/*Spec.ts"],
5+
"spec": ["'test/integration/*Spec.ts'"],
66
"require": ["ts-node/register", "test/hooks.ts"],
77
"package": "./package.json"
88
}

lib/BatchGateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class BatchGateway {
119119

120120
const result = await this.gateway.client.patch<types.Batch.Result>(endPoint, body);
121121

122-
return true;
122+
return Batch.factory(result.batch);
123123
}
124124

125125
/**

lib/OfflinePaymentGateway.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ export class OfflinePaymentGateway {
7171
offlinePaymentId,
7272
);
7373

74-
const result = await this.gateway.client.patch<{ ok: boolean }>(
75-
endPoint,
76-
body,
77-
);
74+
const result = await this.gateway.client.patch<
75+
types.OfflinePayment.Response
76+
>(endPoint, body);
7877

79-
return true;
78+
return OfflinePayment.factory(result.offlinePayment);
8079
}
8180

8281
/**

lib/RecipientGateway.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class RecipientGateway {
102102

103103
const result = await this.gateway.client.patch<types.Recipient.Response>(endPoint, body);
104104

105-
return true;
105+
return Recipient.factory(result.recipient);
106106
}
107107

108108
/**
@@ -120,7 +120,7 @@ export class RecipientGateway {
120120
return true;
121121
}
122122

123-
async search(page: number, pageSize: number, term: string) {
123+
async search(page: number = 1, pageSize: number = 10, term: string = "") {
124124
// tslint:disable-next-line:max-line-length
125125
const endPoint = buildURL('recipients');
126126
const query = querystring.stringify({

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
"main": "./dist/index",
66
"types": "./dist/index",
77
"directories": {
8-
"test": "tests"
8+
"test": "test"
99
},
1010
"files": [
1111
"dist",
1212
"lib"
1313
],
1414
"scripts": {
15-
"test": "npm run test:unit",
16-
"test:unit": "TS_NODE_PROJECT=test/tsconfig.json mocha --require ts-node/register \"test/unit/**/*Spec.ts\"",
17-
"test:integration": "TS_NODE_PROJECT=test/tsconfig.json mocha --require ts-node/register \"test/integration/**/*Spec.ts\"",
15+
"test": "mocha",
1816
"build": "rm -rf dist/ && tsc && echo Done",
1917
"docs": "./node_modules/.bin/typedoc --mode file --name 'Payment Rails JavaScript SDK' --readme none --theme markdown --out docs --hideGenerator lib",
2018
"clean": "rm -rf dist/"

test/integration/BalanceSpec.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import {startNockRec, testingApiClient} from "./helpers/integrationTestsHelpers";
2-
import * as assert from "assert";
3-
4-
describe("Balance", () => {
5-
it("lists all balances", async () => {
6-
const nockDone = await startNockRec('balance-all.json');
7-
8-
const balances = await testingApiClient.balances.all();
9-
10-
assert.ok(balances);
11-
assert.strictEqual(2, balances.length);
12-
assert.strictEqual("paymentrails", balances[0].type);
13-
assert.strictEqual("paypal", balances[1].type);
14-
15-
nockDone();
16-
});
17-
18-
it("lists balances for a given kind", async () => {
19-
const nockDone = await startNockRec('balance-find.json');
20-
21-
const balances = await testingApiClient.balances.find("paypal");
22-
23-
assert.ok(balances);
24-
assert.strictEqual(1, balances.length);
25-
assert.strictEqual("paypal", balances[0].type);
26-
27-
nockDone();
28-
});
29-
});
1+
import { startNockRec, testingApiClient } from "./helpers/integrationTestsHelpers";
2+
import * as assert from "assert";
3+
import { Balance } from "../../lib";
4+
5+
describe("Balance", () => {
6+
it("lists all balances", async () => {
7+
const nockDone = await startNockRec('balance-all.json');
8+
9+
const balances = await testingApiClient.balances.all();
10+
11+
nockDone();
12+
13+
assert.ok(balances);
14+
assert.strictEqual(balances.length, 1);
15+
assert.strictEqual(balances[0].constructor, Balance);
16+
assert.strictEqual(balances[0].type, "paymentrails");
17+
});
18+
19+
it("lists balances for a given kind", async () => {
20+
const nockDone = await startNockRec('balance-find.json');
21+
22+
const balances = await testingApiClient.balances.find("paymentrails");
23+
24+
nockDone();
25+
26+
assert.ok(balances);
27+
assert.strictEqual(balances.length, 1);
28+
assert.strictEqual(balances[0].constructor, Balance);
29+
assert.strictEqual(balances[0].type, "paymentrails");
30+
});
31+
});
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
import * 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

1118
async 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
});

test/integration/InvoiceLineSpec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RecipientFactory } from './factories/RecipientFactory';
33
import { InvoiceFactory } from './factories/InvoiceFactory';
44
import { InvoiceLineFactory } from './factories/InvoiceLineFactory';
55
import * as assert from 'assert';
6+
import { InvoiceLine } from "../../lib/InvoiceLine";
67

78
let recipientFactory: RecipientFactory;
89
let invoiceFactory: InvoiceFactory;
@@ -26,7 +27,8 @@ describe('InvoiceLine', () => {
2627

2728
assert.ok(invoiceLines);
2829
assert.strictEqual(invoiceLines.length, 1);
29-
assert.strictEqual('testInvoiceLine', invoiceLines[0].externalId);
30+
assert.strictEqual(invoiceLines[0].constructor, InvoiceLine);
31+
assert.strictEqual(invoiceLines[0].externalId, 'testInvoiceLine');
3032
});
3133

3234
it('updates an invoice line', async () => {
@@ -51,7 +53,10 @@ describe('InvoiceLine', () => {
5153
nockDone();
5254

5355
assert.ok(updatedInvoice);
54-
assert.strictEqual('updated line description', updatedInvoice.lines[0].description);
56+
assert.strictEqual(invoiceLines.length, 1);
57+
assert.strictEqual(invoiceLines[0].constructor, InvoiceLine);
58+
assert.strictEqual(updatedInvoice.lines.length, 1);
59+
assert.strictEqual(updatedInvoice.lines[0].description, 'updated line description');
5560
});
5661

5762
it('deletes an invoice line', async () => {

0 commit comments

Comments
 (0)