Skip to content

Commit 1a11203

Browse files
ilyamermanarieh
andauthored
Version 1.3.0 (#506)
* Version 1.3.0 * added support for delete recurring payments (#505) * added support for delete reccuring payments * add a test for delete action * no need for input verification in a test --------- Co-authored-by: Arieh Glazer <[email protected]>
1 parent 4937749 commit 1a11203

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@unit-finance/unit-node-sdk",
3-
"version": "1.2.6",
3+
"version": "1.3.0",
44
"description": "",
55
"main": "dist/unit.js",
66
"types": "dist/unit.d.ts",

resources/recurringPayments.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ export class RecurringPayments extends BaseResource {
3434
// when the body is empty.
3535
return this.httpPost<UnitResponse<RecurringPayment>>(`/${paymentId}/enable`, { data: {} })
3636
}
37+
38+
public async delete(paymentId: string): Promise<UnitResponse<RecurringPayment>> {
39+
// NB: We must pass an empty body here because the API is returning a 415 for any requests made
40+
// to this endpoint from this SDK: Content-Type must be application/vnd.api+json
41+
// However, there is code in Axios that strips the Content-Type from the request whenever
42+
// there is no body since it makes no sense to provide it + makes the data over the wire
43+
// that much smaller:
44+
// https://github.com/axios/axios/blob/649d739288c8e2c55829ac60e2345a0f3439c730/dist/axios.js#L1449-L1450
45+
// TODO: Remove the empty body after we update the API to not throw 415 for missing Content-Type
46+
// when the body is empty.
47+
return this.httpDelete<UnitResponse<RecurringPayment>>(`/${paymentId}`, { data: {} })
48+
}
3749

3850
public async get(paymentId: string): Promise<UnitResponse<RecurringPayment>> {
3951
return this.httpGet<UnitResponse<RecurringPayment>>(`/${paymentId}`)

tests/recurringPayments.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,14 @@ describe("Create RecurringDebitAchPayment Test", () => {
260260
expect(res.data.type).toBe("recurringDebitAchPayment")
261261
})
262262
})
263+
264+
describe("Delete RecurringDebitAchPayment Test", () => {
265+
test("Delete RecurringDebitAchPayment", async () => {
266+
const res = await unit.recurringPayments.list()
267+
const payment = res.data[0]
268+
269+
await unit.recurringPayments.delete(payment.id)
270+
271+
expect(await unit.recurringPayments.get(payment.id)).toBeFalsy()
272+
})
273+
})

0 commit comments

Comments
 (0)