diff --git a/resources/payments.ts b/resources/payments.ts index f3637643..41ac4b8c 100644 --- a/resources/payments.ts +++ b/resources/payments.ts @@ -26,12 +26,12 @@ export class Payments extends BaseResource { * Optional. A comma-separated list of related resources to include in the response. * Related resources include: customer, account, transaction. See Getting Related Resources */ - public async get(id: string, include?: string): Promise>> { + public async get(id: string, include?: string): Promise & Include> { const params = {...(include && { include })} - return this.httpGet>>(`/${id}`, { params }) + return this.httpGet & Include>(`/${id}`, { params }) } - public async list(params?: PaymentListParams): Promise & Meta>> { + public async list(params?: PaymentListParams): Promise & Include & Meta> { const parameters: any = { "page[limit]": (params?.limit ? params.limit : 100), "page[offset]": (params?.offset ? params.offset : 0), @@ -62,7 +62,7 @@ export class Payments extends BaseResource { parameters[`filter[direction][${idx}]`] = d }) - return this.httpGet & Meta>>("", { params: parameters }) + return this.httpGet & Include & Meta>("", { params: parameters }) } } diff --git a/resources/receivedPayments.ts b/resources/receivedPayments.ts index 44830a03..2f39f4a5 100644 --- a/resources/receivedPayments.ts +++ b/resources/receivedPayments.ts @@ -23,12 +23,12 @@ export class ReceivedPayments extends BaseResource { * Optional. A comma-separated list of related resources to include in the response. * Related resources include: customer, account. See Getting Related Resources */ - public async get(id: string, include?: string): Promise>> { + public async get(id: string, include?: string): Promise & Include> { const params = {...(include && { include })} - return this.httpGet>>(`/${id}`, { params }) + return this.httpGet & Include>(`/${id}`, { params }) } - public async list(params?: ReceivedPaymentListParams): Promise>> { + public async list(params?: ReceivedPaymentListParams): Promise & Include> { const parameters: any = { "page[limit]": (params?.limit ? params.limit : 100), "page[offset]": (params?.offset ? params.offset : 0), @@ -45,7 +45,7 @@ export class ReceivedPayments extends BaseResource { parameters[`filter[status][${idx}]`] = s }) - return this.httpGet>>("", { params: parameters }) + return this.httpGet & Include>("", { params: parameters }) } } diff --git a/resources/rewards.ts b/resources/rewards.ts index 5dd1a0ff..fe6a60f6 100644 --- a/resources/rewards.ts +++ b/resources/rewards.ts @@ -16,12 +16,12 @@ export class Rewards extends BaseResource { * Optional. A comma-separated list of related resources to include in the response. * Related resources include: customer, account, transaction. See [Getting Related Resources](https://developers.unit.co/about-jsonapi/#intro-getting-related-resources) */ - public async get(id: string, include?: string): Promise>> { + public async get(id: string, include?: string): Promise & Include> { const params = {...(include && { include })} - return this.httpGet>>(`/${id}`, { params }) + return this.httpGet & Include>(`/${id}`, { params }) } - public async list(params?: RewardListParams): Promise>> { + public async list(params?: RewardListParams): Promise & Include> { const parameters: any = { "page[limit]": (params?.limit ? params.limit : 100), "page[offset]": (params?.offset ? params.offset : 0), @@ -42,7 +42,7 @@ export class Rewards extends BaseResource { parameters[`filter[status][${idx}]`] = s }) - return this.httpGet>>("", { params: parameters }) + return this.httpGet & Include>("", { params: parameters }) } } diff --git a/tests/payments.spec.ts b/tests/payments.spec.ts index 1fd0884e..b36ff486 100644 --- a/tests/payments.spec.ts +++ b/tests/payments.spec.ts @@ -1,4 +1,4 @@ -import { CreateBookPaymentRequest, Unit } from "../unit" //CreateLinkedPaymentRequest +import { Account, CreateBookPaymentRequest, Unit } from "../unit" //CreateLinkedPaymentRequest import { createIndividualAccount } from "./accounts.spec" // import { createCounterpartyForTest } from "./counterparties.spec" @@ -11,7 +11,7 @@ describe("Payments List", () => { test("Get Payments List", async () => { const res = await unit.payments.list() res.data.forEach(element => { - expect(element.type === "achPayment" || element.type === "bookPayment").toBeTruthy() + expect(element.type).toContain("Payment") paymentsId.push(element.id) }) }) @@ -19,9 +19,13 @@ describe("Payments List", () => { describe("Get Payment Test", () => { test("get each payment", async () => { - paymentsId.forEach(async id => { - const res = await unit.payments.get(id) - expect(res.data.type === "achPayment" || res.data.type === "bookPayment").toBeTruthy() + const paymentsList = (await unit.payments.list({type: ["AchPayment", "BillPayment", "WirePayment"]})).data + paymentsList.forEach(async p => { + const res = await unit.payments.get(p.id, "account") + expect(res.data.type).toContain("Payment") + const acc = res.included ? res.included[0] as unknown : undefined + if(acc) + expect((acc as Account).type).toContain("Account") }) }) }) diff --git a/tests/receivedPayments.spec.ts b/tests/receivedPayments.spec.ts new file mode 100644 index 00000000..8c12f475 --- /dev/null +++ b/tests/receivedPayments.spec.ts @@ -0,0 +1,38 @@ +import { Account, Unit } from "../unit" + +import dotenv from "dotenv" +import { AchReceivedPayment } from "../types" +dotenv.config() +const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test") +const receivedPaymentsId: string[] = [] + +describe("ReceivedPayments List", () => { + test("Get ReceivedPayments List", async () => { + const res = await unit.receivedPayments.list() + res.data.forEach(element => { + expect(element.type === "achReceivedPayment").toBeTruthy() + receivedPaymentsId.push(element.id) + }) + }) +}) + +describe("Get ReceivedPayment Test", () => { + test("get each ReceivedPayment", async () => { + receivedPaymentsId.forEach(async id => { + const res = await unit.receivedPayments.get(id, "account") + expect(res.data.type === "achReceivedPayment").toBeTruthy() + const acc = res.included as unknown + expect((acc as Account).type).toContain("Account") + }) + }) +}) + +describe("Update ReceivedPayment Test", () => { + test("update an ReceivedPayment", async () => { + receivedPaymentsId.forEach(async rp => { + const payment: AchReceivedPayment = await (await unit.receivedPayments.get(receivedPaymentsId[0])).data + const res = await unit.receivedPayments.update(payment.id, {type: payment.type, attributes: {tags: {"update": "test"}}}) + expect(res.data.type).toBe("achReceivedPayment") + }) + }) +})