Skip to content
Open
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
103 changes: 103 additions & 0 deletions tests/payments/automaticPix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
PaymentRequestAutomaticPix,
CreatePaymentRequestAutomaticPix,
AutomaticPixPayment,
AutomaticPixPaymentListResponse,
ScheduleAutomaticPixPaymentRequest,
RetryAutomaticPixPaymentRequest,
} from '../../src/types'
import { API_URL, createPaymentsClient, mockAs, nock } from './utils'

describe('PluggyPaymentsClient — automatic PIX', () => {
beforeEach(() => {
nock.cleanAll()
})

it('createPaymentRequestPixAutomatico POSTs payments/requests/automatic-pix', async () => {
const payload = mockAs<CreatePaymentRequestAutomaticPix>({ amount: 100 })
const mock = nock(API_URL)
.post('/payments/requests/automatic-pix', payload as Record<string, unknown>)
.reply(200, mockAs<PaymentRequestAutomaticPix>({ id: 'pix-1' }))

const client = createPaymentsClient()
const result = await client.createPaymentRequestPixAutomatico(payload)

expect(result.id).toBe('pix-1')
expect(mock.isDone()).toBe(true)
})

it('scheduleAutomaticPixPayment POSTs .../automatic-pix/schedule with payload', async () => {
const payload = mockAs<ScheduleAutomaticPixPaymentRequest>({ amount: 50 })
const mock = nock(API_URL)
.post('/payments/requests/auth-1/automatic-pix/schedule', payload as Record<string, unknown>)
.reply(200, mockAs<AutomaticPixPayment>({ id: 'apix-1' }))

const client = createPaymentsClient()
const result = await client.scheduleAutomaticPixPayment('auth-1', payload)

expect(result.id).toBe('apix-1')
expect(mock.isDone()).toBe(true)
})

it('retryAutomaticPixPayment POSTs .../automatic-pix/schedules/:id/retry', async () => {
const payload = mockAs<RetryAutomaticPixPaymentRequest>({})
const mock = nock(API_URL)
.post(
'/payments/requests/req-1/automatic-pix/schedules/apix-1/retry',
payload as Record<string, unknown>
)
.reply(200, mockAs<AutomaticPixPayment>({ id: 'apix-1' }))

const client = createPaymentsClient()
const result = await client.retryAutomaticPixPayment('req-1', 'apix-1', payload)

expect(result.id).toBe('apix-1')
expect(mock.isDone()).toBe(true)
})

it('fetchAutomaticPixPayments GETs .../automatic-pix/schedules with filters', async () => {
const mock = nock(API_URL)
.get('/payments/requests/auth-1/automatic-pix/schedules')
.query({ page: '1' })
.reply(200, mockAs<AutomaticPixPaymentListResponse>({ results: [] }))

const client = createPaymentsClient()
await client.fetchAutomaticPixPayments('auth-1', mockAs({ page: 1 }))

expect(mock.isDone()).toBe(true)
})

it('fetchAutomaticPixPayment GETs .../automatic-pix/schedules/:id', async () => {
const mock = nock(API_URL)
.get('/payments/requests/req-1/automatic-pix/schedules/apix-1')
.reply(200, mockAs<AutomaticPixPayment>({ id: 'apix-1' }))

const client = createPaymentsClient()
const result = await client.fetchAutomaticPixPayment('req-1', 'apix-1')

expect(result.id).toBe('apix-1')
expect(mock.isDone()).toBe(true)
})

it('cancelAutomaticPixPayment POSTs .../automatic-pix/schedules/:id/cancel', async () => {
const mock = nock(API_URL)
.post('/payments/requests/req-1/automatic-pix/schedules/apix-1/cancel')
.reply(200, {})

const client = createPaymentsClient()
await client.cancelAutomaticPixPayment('req-1', 'apix-1')

expect(mock.isDone()).toBe(true)
})

it('cancelAutomaticPixAuthorization POSTs .../automatic-pix/cancel', async () => {
const mock = nock(API_URL)
.post('/payments/requests/req-1/automatic-pix/cancel')
.reply(200, {})

const client = createPaymentsClient()
await client.cancelAutomaticPixAuthorization('req-1')

expect(mock.isDone()).toBe(true)
})
})
58 changes: 58 additions & 0 deletions tests/payments/bulkPayments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { BulkPayment, CreateBulkPaymentFields, PageResponse } from '../../src/types'
import { API_URL, createPaymentsClient, mockAs, nock } from './utils'

describe('PluggyPaymentsClient — bulk payments', () => {
beforeEach(() => {
nock.cleanAll()
})

it('createBulkPayment POSTs payments/bulk with payload', async () => {
const payload = mockAs<CreateBulkPaymentFields>({ smartAccountId: 'sa-1', payments: [] })
const mock = nock(API_URL)
.post('/payments/bulk', payload as Record<string, unknown>)
.reply(200, mockAs<BulkPayment>({ id: 'bulk-1' }))

const client = createPaymentsClient()
const result = await client.createBulkPayment(payload)

expect(result.id).toBe('bulk-1')
expect(mock.isDone()).toBe(true)
})

it('fetchBulkPayment GETs payments/bulk/:id', async () => {
const mock = nock(API_URL)
.get('/payments/bulk/bulk-1')
.reply(200, mockAs<BulkPayment>({ id: 'bulk-1' }))

const client = createPaymentsClient()
const result = await client.fetchBulkPayment('bulk-1')

expect(result.id).toBe('bulk-1')
expect(mock.isDone()).toBe(true)
})

it('fetchBulkPayments GETs payments/bulk', async () => {
const page: PageResponse<BulkPayment> = {
page: 1,
total: 0,
totalPages: 0,
results: [],
}
const mock = nock(API_URL).get('/payments/bulk').reply(200, page)

const client = createPaymentsClient()
const result = await client.fetchBulkPayments()

expect(result.results).toEqual([])
expect(mock.isDone()).toBe(true)
})

it('deleteBulkPayment DELETEs payments/bulk/:id', async () => {
const mock = nock(API_URL).delete('/payments/bulk/bulk-1').reply(200, {})

const client = createPaymentsClient()
await client.deleteBulkPayment('bulk-1')

expect(mock.isDone()).toBe(true)
})
})
75 changes: 75 additions & 0 deletions tests/payments/paymentCustomers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
PaymentCustomer,
CreatePaymentCustomer,
PageResponse,
} from '../../src/types'
import { API_URL, createPaymentsClient, mockAs, nock } from './utils'

describe('PluggyPaymentsClient — payment customers', () => {
beforeEach(() => {
nock.cleanAll()
})

it('createPaymentCustomer POSTs payments/customers with payload', async () => {
const payload = mockAs<CreatePaymentCustomer>({ name: 'John', email: 'j@example.com' })
const mock = nock(API_URL)
.post('/payments/customers', payload as Record<string, unknown>)
.reply(200, mockAs<PaymentCustomer>({ id: 'cust-1' }))

const client = createPaymentsClient()
const result = await client.createPaymentCustomer(payload)

expect(result.id).toBe('cust-1')
expect(mock.isDone()).toBe(true)
})

it('fetchPaymentCustomer GETs payments/customers/:id', async () => {
const mock = nock(API_URL)
.get('/payments/customers/cust-1')
.reply(200, mockAs<PaymentCustomer>({ id: 'cust-1' }))

const client = createPaymentsClient()
const result = await client.fetchPaymentCustomer('cust-1')

expect(result.id).toBe('cust-1')
expect(mock.isDone()).toBe(true)
})

it('fetchPaymentCustomers GETs payments/customers', async () => {
const page: PageResponse<PaymentCustomer> = {
page: 1,
total: 0,
totalPages: 0,
results: [],
}
const mock = nock(API_URL).get('/payments/customers').reply(200, page)

const client = createPaymentsClient()
const result = await client.fetchPaymentCustomers()

expect(result.results).toEqual([])
expect(mock.isDone()).toBe(true)
})

it('updatePaymentCustomer PATCHes payments/customers/:id with payload', async () => {
const payload: Partial<CreatePaymentCustomer> = mockAs({ name: 'Jane' })
const mock = nock(API_URL)
.patch('/payments/customers/cust-1', payload as Record<string, unknown>)
.reply(200, mockAs<PaymentCustomer>({ id: 'cust-1' }))

const client = createPaymentsClient()
const result = await client.updatePaymentCustomer('cust-1', payload)

expect(result.id).toBe('cust-1')
expect(mock.isDone()).toBe(true)
})

it('deletePaymentCustomer DELETEs payments/customers/:id', async () => {
const mock = nock(API_URL).delete('/payments/customers/cust-1').reply(200, {})

const client = createPaymentsClient()
await client.deletePaymentCustomer('cust-1')

expect(mock.isDone()).toBe(true)
})
})
40 changes: 40 additions & 0 deletions tests/payments/paymentInstitutions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { PaymentInstitution, PageResponse } from '../../src/types'
import { API_URL, createPaymentsClient, mockAs, nock } from './utils'

describe('PluggyPaymentsClient — payment institutions', () => {
beforeEach(() => {
nock.cleanAll()
})

it('fetchPaymentInstitution GETs payments/recipients/institutions/:id', async () => {
const mock = nock(API_URL)
.get('/payments/recipients/institutions/inst-1')
.reply(200, mockAs<PaymentInstitution>({ id: 'inst-1', name: 'Bank' }))

const client = createPaymentsClient()
const result = await client.fetchPaymentInstitution('inst-1')

expect(result.id).toBe('inst-1')
expect(result.name).toBe('Bank')
expect(mock.isDone()).toBe(true)
})

it('fetchPaymentInstitutions GETs payments/recipients/institutions and forwards name filter', async () => {
const page: PageResponse<PaymentInstitution> = {
page: 1,
total: 1,
totalPages: 1,
results: [mockAs<PaymentInstitution>({ id: 'inst-1', name: 'Itaú' })],
}
const mock = nock(API_URL)
.get('/payments/recipients/institutions')
.query({ name: 'Itaú' })
.reply(200, page)

const client = createPaymentsClient()
const result = await client.fetchPaymentInstitutions({ name: 'Itaú' })

expect(result.results).toHaveLength(1)
expect(mock.isDone()).toBe(true)
})
})
52 changes: 52 additions & 0 deletions tests/payments/paymentIntents.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { PaymentIntent, CreatePaymentIntent, PageResponse } from '../../src/types'
import { API_URL, createPaymentsClient, mockAs, nock } from './utils'

describe('PluggyPaymentsClient — payment intents', () => {
beforeEach(() => {
nock.cleanAll()
})

it('createPaymentIntent POSTs payments/intents with payload', async () => {
const payload = mockAs<CreatePaymentIntent>({ paymentRequestId: 'req-1' })
const mock = nock(API_URL)
.post('/payments/intents', payload as Record<string, unknown>)
.reply(200, mockAs<PaymentIntent>({ id: 'intent-1' }))

const client = createPaymentsClient()
const result = await client.createPaymentIntent(payload)

expect(result.id).toBe('intent-1')
expect(mock.isDone()).toBe(true)
})

it('fetchPaymentIntent GETs payments/intents/:id', async () => {
const mock = nock(API_URL)
.get('/payments/intents/intent-1')
.reply(200, mockAs<PaymentIntent>({ id: 'intent-1' }))

const client = createPaymentsClient()
const result = await client.fetchPaymentIntent('intent-1')

expect(result.id).toBe('intent-1')
expect(mock.isDone()).toBe(true)
})

it('fetchPaymentIntents GETs payments/intents with filters', async () => {
const page: PageResponse<PaymentIntent> = {
page: 1,
total: 1,
totalPages: 1,
results: [mockAs<PaymentIntent>({ id: 'intent-1' })],
}
const mock = nock(API_URL)
.get('/payments/intents')
.query({ page: '1', pageSize: '20' })
.reply(200, page)

const client = createPaymentsClient()
const result = await client.fetchPaymentIntents({ page: 1, pageSize: 20 })

expect(result.results).toHaveLength(1)
expect(mock.isDone()).toBe(true)
})
})
Loading