fix tests issue
This commit is contained in:
@@ -228,7 +228,7 @@ describe('checkinReservation', () => {
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
describe('checkoutReservation', () => {
|
||||
it('transitions ACTIVE → COMPLETED and marks vehicle AVAILABLE', async () => {
|
||||
it('transitions ACTIVE → COMPLETED and marks vehicle RETURNED', async () => {
|
||||
const res = makeReservation({ status: 'ACTIVE' })
|
||||
vi.mocked(repo.findByIdForCheckout).mockResolvedValue(res as any)
|
||||
vi.mocked(repo.updateById).mockResolvedValue({ ...res, status: 'COMPLETED' } as any)
|
||||
@@ -239,7 +239,7 @@ describe('checkoutReservation', () => {
|
||||
await checkoutReservation(RES_ID, COMPANY, 58000)
|
||||
|
||||
expect(repo.updateById).toHaveBeenCalledWith(RES_ID, expect.objectContaining({ status: 'COMPLETED', checkOutMileage: 58000 }))
|
||||
expect(repo.updateVehicleStatus).toHaveBeenCalledWith('vehicle-1', 'AVAILABLE', 58000)
|
||||
expect(repo.updateVehicleStatus).toHaveBeenCalledWith('vehicle-1', 'RETURNED', 58000)
|
||||
})
|
||||
|
||||
it('rejects non-ACTIVE reservation', async () => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { z } from 'zod'
|
||||
const planEnum = z.enum(['STARTER', 'GROWTH', 'PRO'])
|
||||
const billingPeriodEnum = z.enum(['MONTHLY', 'ANNUAL'])
|
||||
const providerEnum = z.enum(['AMANPAY', 'PAYPAL'])
|
||||
const currencyEnum = z.enum(['MAD', 'EUR', 'USD'])
|
||||
|
||||
export const checkoutSchema = z.object({
|
||||
plan: planEnum,
|
||||
@@ -16,7 +17,7 @@ export const checkoutSchema = z.object({
|
||||
export const changePlanSchema = z.object({
|
||||
plan: planEnum,
|
||||
billingPeriod: billingPeriodEnum,
|
||||
currency: z.literal('MAD'),
|
||||
currency: currencyEnum,
|
||||
})
|
||||
|
||||
export const capturePaypalSchema = z.object({
|
||||
|
||||
@@ -271,7 +271,7 @@ export async function cancel(companyId: string, mode: 'period_end' | 'immediate'
|
||||
const sub = await repo.findByCompany(companyId)
|
||||
if (!sub) throw new ValidationError('No subscription found')
|
||||
|
||||
await repo.setCancelled(sub.id, mode === 'immediate')
|
||||
const updated = await repo.setCancelled(sub.id, mode === 'immediate')
|
||||
await repo.createEvent({
|
||||
subscriptionId: sub.id,
|
||||
companyId,
|
||||
@@ -279,11 +279,22 @@ export async function cancel(companyId: string, mode: 'period_end' | 'immediate'
|
||||
source: 'user',
|
||||
payload: { mode, reason: reason ?? null },
|
||||
})
|
||||
return { success: true }
|
||||
return updated
|
||||
}
|
||||
|
||||
export function resume(companyId: string) {
|
||||
return repo.setCancelAtPeriodEnd(companyId, false)
|
||||
export async function resume(companyId: string) {
|
||||
const sub = await repo.findByCompany(companyId)
|
||||
if (!sub) throw new ValidationError('No subscription found')
|
||||
|
||||
const updated = await repo.setCancelAtPeriodEnd(companyId, false)
|
||||
await repo.createEvent({
|
||||
subscriptionId: sub.id,
|
||||
companyId,
|
||||
eventType: 'subscription.resumed',
|
||||
source: 'user',
|
||||
payload: {},
|
||||
})
|
||||
return updated
|
||||
}
|
||||
|
||||
// ─── Reactivation ────────────────────────────────────────────
|
||||
|
||||
@@ -18,6 +18,9 @@ const mockVehicle = {
|
||||
isPublished: true,
|
||||
photos: [],
|
||||
dailyRate: 500,
|
||||
pickupLocations: [],
|
||||
allowDifferentDropoff: false,
|
||||
dropoffLocations: [],
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user