fix api tests
Build & Deploy / Build & Push Docker Image (push) Successful in 2m52s
Test / Type Check (all packages) (push) Successful in 55s
Build & Deploy / Deploy to VPS (push) Successful in 3s
Test / API Unit Tests (push) Successful in 47s
Test / Homepage Unit Tests (push) Successful in 41s
Test / Storefront Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 41s
Test / API Integration Tests (push) Successful in 1m1s
Build & Deploy / Build & Push Docker Image (push) Successful in 2m52s
Test / Type Check (all packages) (push) Successful in 55s
Build & Deploy / Deploy to VPS (push) Successful in 3s
Test / API Unit Tests (push) Successful in 47s
Test / Homepage Unit Tests (push) Successful in 41s
Test / Storefront Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 41s
Test / API Integration Tests (push) Successful in 1m1s
This commit is contained in:
@@ -59,11 +59,19 @@ import * as service from './site.service'
|
||||
|
||||
const company = { id: 'company_1', slug: 'atlas', email: 'office@example.test', contractSettings: { depositRequired: true }, brand: { publicEmail: 'hello@example.test' } }
|
||||
|
||||
function futureDateRange(startOffsetDays: number, durationDays: number) {
|
||||
const start = new Date(Date.now() + startOffsetDays * 24 * 60 * 60 * 1000)
|
||||
const end = new Date(start.getTime() + durationDays * 24 * 60 * 60 * 1000)
|
||||
return { start, end }
|
||||
}
|
||||
|
||||
function bookingBody(overrides: Record<string, unknown> = {}) {
|
||||
const { start, end } = futureDateRange(30, 3)
|
||||
|
||||
return {
|
||||
vehicleId: 'vehicle_1',
|
||||
startDate: '2026-07-01T00:00:00.000Z',
|
||||
endDate: '2026-07-04T00:00:00.000Z',
|
||||
startDate: start.toISOString(),
|
||||
endDate: end.toISOString(),
|
||||
firstName: 'Nora',
|
||||
lastName: 'Renter',
|
||||
email: 'nora@example.test',
|
||||
@@ -103,6 +111,11 @@ describe('site.service public booking/payment boundaries', () => {
|
||||
})
|
||||
|
||||
it('calculates booking totals from base rate, free-day promo, pricing rules, insurance and additional drivers', async () => {
|
||||
const body = bookingBody({
|
||||
promoCodeUsed: 'FREEDAY',
|
||||
selectedInsurancePolicyIds: ['insurance_1'],
|
||||
additionalDrivers: [{ firstName: 'Second' }],
|
||||
})
|
||||
vi.mocked(repo.findVehicleById).mockResolvedValue({ id: 'vehicle_1', companyId: 'company_1', dailyRate: 500, category: 'SUV' } as never)
|
||||
vi.mocked(repo.upsertCustomer).mockResolvedValue({ id: 'customer_1' } as never)
|
||||
vi.mocked(repo.findOfferByPromoCode).mockResolvedValue({ id: 'offer_1', type: 'FREE_DAY', discountValue: 1 } as never)
|
||||
@@ -111,8 +124,8 @@ describe('site.service public booking/payment boundaries', () => {
|
||||
id: 'reservation_1',
|
||||
bookingReference: 'BK-2026-AB12CD',
|
||||
status: 'DRAFT',
|
||||
startDate: new Date('2026-07-01T10:00:00.000Z'),
|
||||
endDate: new Date('2026-07-04T10:00:00.000Z'),
|
||||
startDate: new Date(body.startDate),
|
||||
endDate: new Date(body.endDate),
|
||||
pickupLocation: 'Casablanca',
|
||||
returnLocation: 'Casablanca',
|
||||
vehicle: { make: 'Dacia', model: 'Duster', year: 2024 },
|
||||
@@ -125,11 +138,7 @@ describe('site.service public booking/payment boundaries', () => {
|
||||
paymentStatus: 'UNPAID',
|
||||
} as never)
|
||||
|
||||
const result = await service.createBooking('atlas', bookingBody({
|
||||
promoCodeUsed: 'FREEDAY',
|
||||
selectedInsurancePolicyIds: ['insurance_1'],
|
||||
additionalDrivers: [{ firstName: 'Second' }],
|
||||
}))
|
||||
const result = await service.createBooking('atlas', body)
|
||||
|
||||
expect(repo.createReservation).toHaveBeenCalledWith(expect.objectContaining({
|
||||
totalDays: 3,
|
||||
|
||||
@@ -82,6 +82,12 @@ import {
|
||||
|
||||
const SLUG = 'test-company'
|
||||
|
||||
function futureDateRange(startOffsetDays: number, durationDays: number) {
|
||||
const start = new Date(Date.now() + startOffsetDays * 24 * 60 * 60 * 1000)
|
||||
const end = new Date(start.getTime() + durationDays * 24 * 60 * 60 * 1000)
|
||||
return { start, end }
|
||||
}
|
||||
|
||||
function makeCompany(overrides: object = {}) {
|
||||
return {
|
||||
id: 'co-1', slug: SLUG, name: 'Test Co', phone: null, email: 'co@test.com',
|
||||
@@ -173,10 +179,11 @@ describe('validatePromoCode', () => {
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
describe('createBooking', () => {
|
||||
const { start: bookingStart, end: bookingEnd } = futureDateRange(30, 3)
|
||||
const baseBody = {
|
||||
vehicleId: 'v-1',
|
||||
startDate: '2026-07-01T00:00:00.000Z',
|
||||
endDate: '2026-07-04T00:00:00.000Z',
|
||||
startDate: bookingStart.toISOString(),
|
||||
endDate: bookingEnd.toISOString(),
|
||||
firstName: 'Ali', lastName: 'Ben', email: 'ali@test.com',
|
||||
phone: '+212600000000',
|
||||
pickupLocation: 'Casablanca',
|
||||
@@ -194,8 +201,8 @@ describe('createBooking', () => {
|
||||
id: 'r-1',
|
||||
bookingReference: 'BK-2026-ABC123',
|
||||
status: 'DRAFT',
|
||||
startDate: new Date('2026-07-01T00:00:00.000Z'),
|
||||
endDate: new Date('2026-07-04T00:00:00.000Z'),
|
||||
startDate: bookingStart,
|
||||
endDate: bookingEnd,
|
||||
pickupLocation: 'Casablanca',
|
||||
returnLocation: 'Casablanca',
|
||||
vehicle: { make: 'Toyota', model: 'Camry', year: 2022 },
|
||||
|
||||
Reference in New Issue
Block a user