Skip to content

Commit 515e23f

Browse files
committed
update "update" methods and crudify recipient test
1 parent 5355678 commit 515e23f

File tree

8 files changed

+723
-568
lines changed

8 files changed

+723
-568
lines changed

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({

test/integration/OfflinePaymentSpec.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('OfflinePayment', () => {
2828
const nockDone = await startNockRec('offline-payment-update.json');
2929

3030
const recipient = await recipientFactory.createResource();
31-
const offlinePayment = await offlinePaymentFactory.createResource({ recipient: { id: recipient.id } });
32-
const updatedOfflinePayment = await testingApiClient.offlinePayment.update(
31+
let offlinePayment = await offlinePaymentFactory.createResource({ recipient: { id: recipient.id } });
32+
offlinePayment = await testingApiClient.offlinePayment.update(
3333
recipient.id,
3434
offlinePayment.id,
3535
{
@@ -40,17 +40,11 @@ describe('OfflinePayment', () => {
4040
withholdingCurrency: 'USD',
4141
},
4242
);
43-
const offlinePaymentResults = await testingApiClient.offlinePayment.search(
44-
{
45-
recipientId: recipient.id,
46-
},
47-
);
4843

4944
nockDone();
5045

51-
assert.ok(updatedOfflinePayment);
52-
assert.strictEqual(1, offlinePaymentResults.length);
53-
assert.strictEqual(true, offlinePaymentResults[0].taxReportable);
46+
assert.ok(offlinePayment);
47+
assert.strictEqual(true, offlinePayment.taxReportable);
5448
});
5549

5650
it('deletes an offline payment', async () => {

test/integration/RecipientSpec.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { Recipient } from "../../lib";
22
import * as assert from "assert";
3-
import {startNockRec, testingApiClient} from "./helpers/integrationTestsHelpers";
4-
import {RecipientFactory} from "./factories/RecipientFactory";
3+
import { startNockRec, testingApiClient } from "./helpers/integrationTestsHelpers";
4+
import { RecipientFactory } from "./factories/RecipientFactory";
55

6-
const recipientFactory = new RecipientFactory();
6+
let recipientFactory: RecipientFactory;
7+
8+
before(async () => {
9+
recipientFactory = new RecipientFactory();
10+
});
711

812
describe("Recipient", () => {
913
it("creates a recipient", async () => {
@@ -19,40 +23,43 @@ describe("Recipient", () => {
1923
nockDone();
2024
});
2125

22-
it("life cycle", async () => {
23-
const nockDone = await startNockRec('recipient-life-cycle.json');
24-
25-
const recipient = await recipientFactory.createResource(
26-
{
27-
type: "individual",
28-
firstName: "Tom",
29-
lastName: "Jones",
30-
31-
}
32-
);
26+
it("updates a recipient", async () => {
27+
const nockDone = await startNockRec('recipient-update.json');
3328

34-
assert.ok(recipient);
35-
assert.strictEqual("Tom", recipient.firstName);
36-
assert.strictEqual("Jones", recipient.lastName);
37-
assert.ok(recipient.id);
29+
const recipient = await recipientFactory.createResource();
30+
const updated = await testingApiClient.recipient.update(recipient.id, {
31+
firstName: "John",
32+
lastName: "Smith",
33+
});
3834

39-
assert.strictEqual("incomplete", recipient.status);
35+
nockDone();
4036

41-
const updateResult = await testingApiClient.recipient.update(recipient.id, {
42-
firstName: "Bob",
37+
assert.ok(updated);
38+
assert.strictEqual("John", updated.firstName);
39+
assert.strictEqual("Smith", updated.lastName);
4340
});
4441

45-
assert.ok(updateResult);
42+
it("deletes a recipient", async () => {
43+
const nockDone = await startNockRec('recipient-delete.json');
4644

47-
const fetchResult = await testingApiClient.recipient.find(recipient.id);
48-
assert.strictEqual("Bob", fetchResult.firstName);
45+
const recipient = await recipientFactory.createResource();
46+
const deleted = await testingApiClient.recipient.remove(recipient.id);
4947

50-
const deleteResult = await testingApiClient.recipient.remove(recipient.id);
51-
assert.strictEqual(deleteResult, true);
48+
nockDone();
49+
50+
assert.ok(deleted);
51+
});
52+
53+
it("searches for a recipient", async () => {
54+
const nockDone = await startNockRec('recipient-search.json');
5255

53-
const fetchDeletedResult = await testingApiClient.recipient.find(recipient.id);
54-
assert.strictEqual("archived", fetchDeletedResult.status);
56+
const recipient = await recipientFactory.createResource();
57+
const recipients = await testingApiClient.recipient.search();
5558

5659
nockDone();
60+
61+
assert.ok(recipients);
62+
assert.strictEqual(1, recipients.length);
63+
assert.strictEqual(recipient.id, recipients[0].id);
64+
});
5765
});
58-
});
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
[
2+
{
3+
"scope": "https://api.railz.io:443",
4+
"method": "POST",
5+
"path": "/v1/recipients",
6+
"body": {
7+
"type": "individual",
8+
"firstName": "Tom",
9+
"lastName": "Jones",
10+
"email": "[email protected]",
11+
"address": {
12+
"street1": "123 Wolfstrasse",
13+
"city": "Berlin",
14+
"country": "DE",
15+
"postalCode": "123123"
16+
}
17+
},
18+
"status": 200,
19+
"response": {
20+
"ok": true,
21+
"recipient": {
22+
"id": "R-8TDbr6EWiNVrbjpUQ6wW9w",
23+
"referenceId": "R-8TDbr6EWiNVrbjpUQ6wW9w",
24+
"parentRecipientId": null,
25+
"email": "[email protected]",
26+
"name": "Tom Jones",
27+
"lastName": "Jones",
28+
"firstName": "Tom",
29+
"legalName": "",
30+
"type": "individual",
31+
"status": "incomplete",
32+
"language": "en",
33+
"complianceStatus": "pending",
34+
"dob": null,
35+
"passport": "",
36+
"placeOfBirth": null,
37+
"updatedAt": "2022-10-27T04:43:57.713Z",
38+
"createdAt": "2022-10-27T04:43:57.713Z",
39+
"tags": [],
40+
"isPortalUser": false,
41+
"taxDeliveryType": "mail",
42+
"contactEmails": [],
43+
"occupation": "",
44+
"address": {
45+
"street1": "123 Wolfstrasse",
46+
"street2": "",
47+
"city": "Berlin",
48+
"postalCode": "123123",
49+
"country": "DE",
50+
"region": null,
51+
"phone": "",
52+
"phoneValidated": false
53+
},
54+
"compliance": {
55+
"status": "pending",
56+
"checkedAt": null
57+
},
58+
"gravatarUrl": "https://www.gravatar.com/avatar/47891e3b30e9fe3c5355801d4cbd5896?d=404",
59+
"governmentId": null,
60+
"ssn": null,
61+
"governmentIds": [],
62+
"birthplace": {
63+
"country": null,
64+
"region": null,
65+
"city": null
66+
},
67+
"citizenships": [],
68+
"routeType": "sepa",
69+
"routeMinimum": "0",
70+
"estimatedFees": "4",
71+
"accounts": [],
72+
"payoutMethod": null,
73+
"primaryCurrency": null,
74+
"riskScore": null,
75+
"merchantId": "M-EZ6uVwg9vSUrG6vJNjR9KA",
76+
"inactiveReasons": {
77+
"primaryAccount": "missing"
78+
},
79+
"taxWithholdingPercentage": null,
80+
"taxForm": null,
81+
"taxFormStatus": null
82+
}
83+
},
84+
"rawHeaders": [
85+
"Date",
86+
"Thu, 27 Oct 2022 04:43:57 GMT",
87+
"Content-Type",
88+
"application/json; charset=utf-8",
89+
"Content-Length",
90+
"1626",
91+
"Connection",
92+
"close",
93+
"Cache-Control",
94+
"no-store, no-cache",
95+
"Content-Security-Policy",
96+
"default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests",
97+
"X-DNS-Prefetch-Control",
98+
"off",
99+
"Expect-CT",
100+
"max-age=0",
101+
"Strict-Transport-Security",
102+
"max-age=15552000; includeSubDomains",
103+
"X-Download-Options",
104+
"noopen",
105+
"X-Content-Type-Options",
106+
"nosniff",
107+
"X-Permitted-Cross-Domain-Policies",
108+
"none",
109+
"Referrer-Policy",
110+
"no-referrer",
111+
"X-XSS-Protection",
112+
"0",
113+
"Access-Control-Allow-Origin",
114+
"*",
115+
"X-Rate-Limit-Limit",
116+
"75",
117+
"X-Rate-Limit-Remaining",
118+
"74",
119+
"X-Rate-Limit-Reset",
120+
"1666845897",
121+
"Vary",
122+
"Origin",
123+
"ETag",
124+
"W/\"65a-bq2t7dCkoOi6NiKvk4399/JrzJc\""
125+
],
126+
"responseIsBinary": false
127+
},
128+
{
129+
"scope": "https://api.railz.io:443",
130+
"method": "DELETE",
131+
"path": "/v1/recipients/R-8TDbr6EWiNVrbjpUQ6wW9w",
132+
"body": "",
133+
"status": 200,
134+
"response": {
135+
"ok": true
136+
},
137+
"rawHeaders": [
138+
"Date",
139+
"Thu, 27 Oct 2022 04:43:58 GMT",
140+
"Content-Type",
141+
"application/json; charset=utf-8",
142+
"Content-Length",
143+
"16",
144+
"Connection",
145+
"close",
146+
"Cache-Control",
147+
"no-store, no-cache",
148+
"Content-Security-Policy",
149+
"default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests",
150+
"X-DNS-Prefetch-Control",
151+
"off",
152+
"Expect-CT",
153+
"max-age=0",
154+
"Strict-Transport-Security",
155+
"max-age=15552000; includeSubDomains",
156+
"X-Download-Options",
157+
"noopen",
158+
"X-Content-Type-Options",
159+
"nosniff",
160+
"X-Permitted-Cross-Domain-Policies",
161+
"none",
162+
"Referrer-Policy",
163+
"no-referrer",
164+
"X-XSS-Protection",
165+
"0",
166+
"Access-Control-Allow-Origin",
167+
"*",
168+
"X-Rate-Limit-Limit",
169+
"75",
170+
"X-Rate-Limit-Remaining",
171+
"73",
172+
"X-Rate-Limit-Reset",
173+
"1666845897",
174+
"Vary",
175+
"Origin",
176+
"ETag",
177+
"W/\"10-QaprLnY+YzA8xRCUPnQQBKFKrLA\""
178+
],
179+
"responseIsBinary": false
180+
}
181+
]

0 commit comments

Comments
 (0)