Refactor to vertical slice

This commit is contained in:
Jose Selesan
2026-06-26 14:05:37 -03:00
parent 3949c9add1
commit c8477de5d2
149 changed files with 5011 additions and 5127 deletions

View File

@@ -1,27 +1,22 @@
import { beforeEach, expect, mock, test } from 'bun:test';
const rescheduleAdminBookingMock = mock(
async (_userId: string, _id: string, _input: unknown) => ({})
import { Errors } from '@/lib/errors';
import { err, ok } from '@/lib/result';
const rescheduleAdminBookingMock = mock(async (_userId: string, _id: string, _input: unknown) =>
ok({})
);
class MockAdminBookingServiceError extends Error {
status: 400 | 403 | 404 | 409;
constructor(message: string, status: 400 | 403 | 404 | 409 = 400) {
super(message);
this.name = 'AdminBookingServiceError';
this.status = status;
}
}
mock.module('@/modules/admin-booking/services/admin-booking.service', () => ({
__esModule: true,
AdminBookingServiceError: MockAdminBookingServiceError,
rescheduleAdminBooking: rescheduleAdminBookingMock,
}));
mock.module(
'@/modules/admin-booking/features/reschedule-admin-booking/reschedule-admin-booking.business',
() => ({
__esModule: true,
rescheduleAdminBooking: rescheduleAdminBookingMock,
})
);
const { rescheduleAdminBookingHandler } = await import(
'@/modules/admin-booking/handlers/reschedule-admin-booking.handler'
'@/modules/admin-booking/features/reschedule-admin-booking/reschedule-admin-booking.handler'
);
type HandlerContext = {
@@ -82,7 +77,7 @@ test('returns 200 with the updated booking', async () => {
updatedAt: '2026-07-14T00:00:00.000Z',
} as const;
rescheduleAdminBookingMock.mockResolvedValue(updatedBooking);
rescheduleAdminBookingMock.mockResolvedValue(ok(updatedBooking));
const { c, json } = createContext({
userId: 'user-1',
@@ -96,16 +91,13 @@ test('returns 200 with the updated booking', async () => {
startTime: '14:00',
});
expect(json.mock.calls[0]?.[0]).toEqual(updatedBooking);
expect(json.mock.calls[0]?.[1]).toBeUndefined();
expect(json.mock.calls[0]?.[1]).toBe(200);
expect(response).toBeDefined();
});
test('maps AdminBookingServiceError to an error response', async () => {
rescheduleAdminBookingMock.mockRejectedValue(
new MockAdminBookingServiceError(
'Solo se pueden reprogramar reservas en estado confirmada.',
409
)
rescheduleAdminBookingMock.mockResolvedValue(
err(Errors.conflict('Solo se pueden reprogramar reservas en estado confirmada.'))
);
const { c, json } = createContext({
@@ -119,7 +111,10 @@ test('maps AdminBookingServiceError to an error response', async () => {
startTime: '14:00',
});
expect(json.mock.calls[0]?.[0]).toEqual({
message: 'Solo se pueden reprogramar reservas en estado confirmada.',
type: 'https://api.myapp.dev/problems/conflict',
title: 'Conflict',
status: 409,
detail: 'Solo se pueden reprogramar reservas en estado confirmada.',
});
expect(json.mock.calls[0]?.[1]).toBe(409);
expect(response).toBeDefined();