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