feat: add country selection during onboarding and implement payment management features
- Introduced CountryStep component for selecting the country during onboarding, affecting payment currency. - Updated FirstGroupStep to include country information. - Enhanced PaymentsProvider to manage payment states and renewals. - Created PaymentRow component for displaying individual payment details. - Implemented PaymentsView for listing and filtering payments by group and status. - Added API endpoints for fetching and creating payments, including batch processing. - Defined payment schemas for validation and data handling. - Updated GroupHeader and GroupDetailView to include charging functionality for group members.
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
|
||||
import { Hono } from 'hono';
|
||||
|
||||
mock.module('@/lib/prisma', () => ({
|
||||
default: {
|
||||
payment: {
|
||||
findMany: mock(),
|
||||
count: mock(),
|
||||
},
|
||||
const db = {
|
||||
group: {
|
||||
findMany: mock(),
|
||||
},
|
||||
payment: {
|
||||
findMany: mock(),
|
||||
count: mock(),
|
||||
},
|
||||
};
|
||||
|
||||
mock.module('@/lib/prisma', () => ({
|
||||
default: db,
|
||||
getPrismaClient: mock(),
|
||||
UnitOfWork: class {},
|
||||
}));
|
||||
@@ -15,43 +20,61 @@ mock.module('@/lib/prisma', () => ({
|
||||
import prisma from '@/lib/prisma';
|
||||
import { paymentsRoutes } from '@/modules/payments';
|
||||
|
||||
const app = new Hono();
|
||||
app.route('/payments', paymentsRoutes);
|
||||
const userId = 'user-1';
|
||||
|
||||
const payment = {
|
||||
id: 'payment-1',
|
||||
groupId: 'group-1',
|
||||
attendeeId: 'attendee-1',
|
||||
groupId: 'group-1',
|
||||
attendeeId: 'attendee-1',
|
||||
amount: { toString: () => '150.50' } as { toString(): string },
|
||||
currency: 'MXN',
|
||||
status: 'pending',
|
||||
currency: 'ARS',
|
||||
status: 'PENDING',
|
||||
description: 'Mensualidad de Septiembre',
|
||||
checkoutUrl: 'https://mercadopago.com/checkout/payment-1',
|
||||
dueDate: new Date('2026-09-01T10:00:00.000Z'),
|
||||
paidAt: null,
|
||||
createdAt: new Date('2026-08-01T10:00:00.000Z'),
|
||||
updatedAt: new Date('2026-08-01T10:00:00.000Z'),
|
||||
group: { name: 'Cuadrilla Alfa', price: 150.5 },
|
||||
attendee: { fullName: 'Juana Pérez' },
|
||||
};
|
||||
|
||||
function makeApp(userValue: unknown) {
|
||||
const app = new Hono();
|
||||
app.use('*', async (c, next) => {
|
||||
c.set('user', userValue as never);
|
||||
await next();
|
||||
});
|
||||
app.route('/payments', paymentsRoutes);
|
||||
return app;
|
||||
}
|
||||
|
||||
describe('payments routes', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('lists payments with pagination and converts Decimal amounts', async () => {
|
||||
it('lists payments scoped to the user, with attendee and group names', async () => {
|
||||
prisma.group.findMany.mockResolvedValue([{ id: 'group-1' }]);
|
||||
prisma.payment.findMany.mockResolvedValue([payment]);
|
||||
prisma.payment.count.mockResolvedValue(1);
|
||||
|
||||
const res = await app.request('/payments');
|
||||
const res = await makeApp({ id: userId }).request('/payments');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({
|
||||
data: [
|
||||
{
|
||||
id: 'payment-1',
|
||||
groupId: 'group-1',
|
||||
attendeeId: 'attendee-1',
|
||||
groupId: 'group-1',
|
||||
groupName: 'Cuadrilla Alfa',
|
||||
attendeeId: 'attendee-1',
|
||||
attendeeName: 'Juana Pérez',
|
||||
amount: 150.5,
|
||||
currency: 'MXN',
|
||||
status: 'pending',
|
||||
currency: 'ARS',
|
||||
status: 'PENDING',
|
||||
description: 'Mensualidad de Septiembre',
|
||||
checkoutUrl: payment.checkoutUrl,
|
||||
dueDate: payment.dueDate.toISOString(),
|
||||
paidAt: null,
|
||||
createdAt: payment.createdAt.toISOString(),
|
||||
@@ -60,15 +83,49 @@ groupId: 'group-1',
|
||||
],
|
||||
pagination: { page: 1, pageSize: 10, total: 1, totalPages: 1 },
|
||||
});
|
||||
expect(prisma.group.findMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
OR: [{ createdById: userId }, { members: { some: { userId } } }],
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
expect(prisma.payment.findMany).toHaveBeenCalledWith({
|
||||
where: { groupId: { in: ['group-1'] } },
|
||||
include: {
|
||||
group: { select: { name: true, price: true } },
|
||||
attendee: { select: { fullName: true } },
|
||||
},
|
||||
skip: 0,
|
||||
take: 10,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
});
|
||||
|
||||
it('filters payments by group and status', async () => {
|
||||
prisma.group.findMany.mockResolvedValue([{ id: 'group-1' }]);
|
||||
prisma.payment.findMany.mockResolvedValue([]);
|
||||
prisma.payment.count.mockResolvedValue(0);
|
||||
|
||||
const res = await makeApp({ id: userId }).request(
|
||||
'/payments?groupId=group-1&status=OVERDUE',
|
||||
);
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(prisma.payment.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { groupId: 'group-1', status: 'OVERDUE' },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects requests without a session user', async () => {
|
||||
const res = await makeApp(null).request('/payments');
|
||||
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
|
||||
it('rejects invalid pagination query parameters', async () => {
|
||||
const res = await app.request('/payments?pageSize=101');
|
||||
const res = await makeApp({ id: userId }).request('/payments?pageSize=101');
|
||||
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user