Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions resources/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnitResponse<Payment & Include<Account[] | Customer[] | Transaction[]>>> {
public async get(id: string, include?: string): Promise<UnitResponse<Payment> & Include<Account[] | Customer[] | Transaction[]>> {
const params = {...(include && { include })}
return this.httpGet<UnitResponse<Payment & Include<Account[] | Customer[] | Transaction[]>>>(`/${id}`, { params })
return this.httpGet<UnitResponse<Payment> & Include<Account[] | Customer[] | Transaction[]>>(`/${id}`, { params })
}

public async list(params?: PaymentListParams): Promise<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]> & Meta>> {
public async list(params?: PaymentListParams): Promise<UnitResponse<Payment[]> & Include<Account[] | Customer[] | Transaction[]> & Meta> {
const parameters: any = {
"page[limit]": (params?.limit ? params.limit : 100),
"page[offset]": (params?.offset ? params.offset : 0),
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Payments extends BaseResource {
parameters[`filter[direction][${idx}]`] = d
})

return this.httpGet<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]> & Meta>>("", { params: parameters })
return this.httpGet<UnitResponse<Payment[]> & Include<Account[] | Customer[] | Transaction[]> & Meta>("", { params: parameters })
}
}

Expand Down
8 changes: 4 additions & 4 deletions resources/receivedPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnitResponse<AchReceivedPayment & Include<Account[] | Customer[]>>> {
public async get(id: string, include?: string): Promise<UnitResponse<AchReceivedPayment> & Include<Account[] | Customer[]>> {
const params = {...(include && { include })}
return this.httpGet<UnitResponse<AchReceivedPayment & Include<Account[] | Customer[]>>>(`/${id}`, { params })
return this.httpGet<UnitResponse<AchReceivedPayment> & Include<Account[] | Customer[]>>(`/${id}`, { params })
}

public async list(params?: ReceivedPaymentListParams): Promise<UnitResponse<AchReceivedPayment[] & Include<Account[] | Customer[] | Transaction[]>>> {
public async list(params?: ReceivedPaymentListParams): Promise<UnitResponse<AchReceivedPayment[]> & Include<Account[] | Customer[] | Transaction[]>> {
const parameters: any = {
"page[limit]": (params?.limit ? params.limit : 100),
"page[offset]": (params?.offset ? params.offset : 0),
Expand All @@ -45,7 +45,7 @@ export class ReceivedPayments extends BaseResource {
parameters[`filter[status][${idx}]`] = s
})

return this.httpGet<UnitResponse<AchReceivedPayment[] & Include<Account[] | Customer[] | Transaction[]>>>("", { params: parameters })
return this.httpGet<UnitResponse<AchReceivedPayment[]> & Include<Account[] | Customer[] | Transaction[]>>("", { params: parameters })
}
}

Expand Down
8 changes: 4 additions & 4 deletions resources/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnitResponse<Reward & Include<Account[] | Customer[] | Transaction[]>>> {
public async get(id: string, include?: string): Promise<UnitResponse<Reward> & Include<Account[] | Customer[] | Transaction[]>> {
const params = {...(include && { include })}
return this.httpGet<UnitResponse<Reward & Include<Account[] | Customer[] | Transaction[]>>>(`/${id}`, { params })
return this.httpGet<UnitResponse<Reward> & Include<Account[] | Customer[] | Transaction[]>>(`/${id}`, { params })
}

public async list(params?: RewardListParams): Promise<UnitResponse<Reward[] & Include<Account[] | Customer[] | Transaction[]>>> {
public async list(params?: RewardListParams): Promise<UnitResponse<Reward[]> & Include<Account[] | Customer[] | Transaction[]>> {
const parameters: any = {
"page[limit]": (params?.limit ? params.limit : 100),
"page[offset]": (params?.offset ? params.offset : 0),
Expand All @@ -42,7 +42,7 @@ export class Rewards extends BaseResource {
parameters[`filter[status][${idx}]`] = s
})

return this.httpGet<UnitResponse<Reward[] & Include<Account[] | Customer[] | Transaction[]>>>("", { params: parameters })
return this.httpGet<UnitResponse<Reward[]> & Include<Account[] | Customer[] | Transaction[]>>("", { params: parameters })
}

}
14 changes: 9 additions & 5 deletions tests/payments.spec.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -11,17 +11,21 @@ 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)
})
})
})

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")
})
})
})
Expand Down
38 changes: 38 additions & 0 deletions tests/receivedPayments.spec.ts
Original file line number Diff line number Diff line change
@@ -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")
})
})
})