8aab968e09
Build & Deploy / Build & Push Docker Image (push) Successful in 1m2s
Test / Type Check (all packages) (push) Failing after 28s
Test / API Unit Tests (push) Has been skipped
Test / Homepage Unit Tests (push) Has been skipped
Test / Storefront Unit Tests (push) Has been skipped
Test / Admin Unit Tests (push) Has been skipped
Test / Dashboard Unit Tests (push) Has been skipped
Test / API Integration Tests (push) Has been skipped
Build & Deploy / Deploy to VPS (push) Successful in 3s
Comprehensive rename of all marketplace references to storefront: - API module: apps/api/src/modules/marketplace/ → storefront/ - Components: MarketplaceHeader → StorefrontHeader, MarketplaceShell → StorefrontShell, MarketplaceFooter → StorefrontFooter - Types: marketplace-homepage.ts → storefront-homepage.ts - Test files: employee-marketplace-* → employee-storefront-* - All source code identifiers, imports, route paths, and strings - Documentation (docs/), CI config (.gitlab-ci.yml), scripts - Dashboard, admin, storefront workspace references - Prisma field names preserved (isListedOnMarketplace, marketplaceRating, marketplaceFunnelEvent) as they map to database schema Validation: - API type-check: 0 errors - Storefront type-check: 0 errors - Dashboard type-check: 0 errors - Full monorepo type-check: only pre-existing admin TS18046
142 lines
4.5 KiB
TypeScript
142 lines
4.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
const prismaMock = vi.hoisted(() => ({
|
|
offer: { findMany: vi.fn(), findFirst: vi.fn() },
|
|
company: { findMany: vi.fn(), findFirst: vi.fn(), findFirstOrThrow: vi.fn() },
|
|
vehicle: { findMany: vi.fn(), findFirst: vi.fn(), findFirstOrThrow: vi.fn() },
|
|
reservation: { create: vi.fn(), findUnique: vi.fn(), update: vi.fn() },
|
|
customer: { findUnique: vi.fn(), create: vi.fn(), update: vi.fn() },
|
|
review: { findMany: vi.fn(), create: vi.fn() },
|
|
}))
|
|
|
|
vi.mock('../../lib/prisma', () => ({ prisma: prismaMock }))
|
|
|
|
import * as repo from './storefront.repo'
|
|
|
|
describe('storefront.repo public query and write boundaries', () => {
|
|
it('finds public offers using active/public/current-window filters and featured ordering', async () => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(new Date('2026-06-09T10:00:00.000Z'))
|
|
|
|
await repo.findPublicOffers()
|
|
|
|
expect(prismaMock.offer.findMany).toHaveBeenCalledWith(expect.objectContaining({
|
|
where: {
|
|
isPublic: true,
|
|
isActive: true,
|
|
validFrom: { lte: new Date('2026-06-09T10:00:00.000Z') },
|
|
validUntil: { gte: new Date('2026-06-09T10:00:00.000Z') },
|
|
},
|
|
orderBy: [{ isFeatured: 'desc' }, { createdAt: 'desc' }],
|
|
take: 50,
|
|
}))
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('lists storefront cities only from active listed companies with a public city', async () => {
|
|
await repo.findCitiesFromCompanies()
|
|
|
|
expect(prismaMock.company.findMany).toHaveBeenCalledWith({
|
|
where: {
|
|
status: { in: ['ACTIVE', 'TRIALING'] },
|
|
brand: { isListedOnMarketplace: true, publicCity: { not: null } },
|
|
},
|
|
select: { brand: { select: { publicCity: true } } },
|
|
})
|
|
})
|
|
|
|
it('requires published vehicles and an active company when loading storefront vehicle details', async () => {
|
|
await repo.findVehicleForStorefront('vehicle_1', 'atlas')
|
|
|
|
expect(prismaMock.vehicle.findFirst).toHaveBeenCalledWith({
|
|
where: {
|
|
id: 'vehicle_1',
|
|
isPublished: true,
|
|
company: { slug: 'atlas', status: { in: ['ACTIVE', 'TRIALING'] } },
|
|
},
|
|
include: { company: { include: { brand: true } } },
|
|
})
|
|
})
|
|
|
|
it('patches storefront customer address fields without deleting existing address metadata', async () => {
|
|
prismaMock.customer.findUnique.mockResolvedValueOnce({
|
|
id: 'customer_1',
|
|
address: { fullAddress: 'Old address', loyaltyNote: 'keep', internationalLicenseNumber: 'INT-1' },
|
|
})
|
|
|
|
await repo.upsertMarketplaceCustomer('company_1', {
|
|
email: 'renter@example.test',
|
|
firstName: 'Nora',
|
|
lastName: 'Renter',
|
|
identityDocumentNumber: 'ID-9',
|
|
internationalLicenseNumber: undefined,
|
|
})
|
|
|
|
expect(prismaMock.customer.update).toHaveBeenCalledWith({
|
|
where: { id: 'customer_1' },
|
|
data: expect.objectContaining({
|
|
firstName: 'Nora',
|
|
address: {
|
|
fullAddress: 'Old address',
|
|
loyaltyNote: 'keep',
|
|
internationalLicenseNumber: 'INT-1',
|
|
identityDocumentNumber: 'ID-9',
|
|
},
|
|
}),
|
|
})
|
|
})
|
|
|
|
it('creates storefront reservations as draft storefront-sourced records', async () => {
|
|
const startDate = new Date('2026-07-01T10:00:00.000Z')
|
|
const endDate = new Date('2026-07-05T10:00:00.000Z')
|
|
|
|
await repo.createStorefrontReservation({
|
|
companyId: 'company_1',
|
|
vehicleId: 'vehicle_1',
|
|
customerId: 'customer_1',
|
|
startDate,
|
|
endDate,
|
|
dailyRate: 500,
|
|
totalDays: 4,
|
|
totalAmount: 2000,
|
|
pickupLocation: 'Airport',
|
|
returnLocation: null,
|
|
})
|
|
|
|
expect(prismaMock.reservation.create).toHaveBeenCalledWith({
|
|
data: expect.objectContaining({
|
|
companyId: 'company_1',
|
|
vehicleId: 'vehicle_1',
|
|
customerId: 'customer_1',
|
|
source: 'MARKETPLACE',
|
|
status: 'DRAFT',
|
|
}),
|
|
})
|
|
})
|
|
|
|
it('submits public reviews as published records and prevents null renter ids from becoming explicit nulls', async () => {
|
|
await repo.createReview({
|
|
reservationId: 'reservation_1',
|
|
companyId: 'company_1',
|
|
renterId: null,
|
|
overallRating: 5,
|
|
vehicleRating: 4,
|
|
serviceRating: 5,
|
|
comment: 'Clean car',
|
|
})
|
|
|
|
expect(prismaMock.review.create).toHaveBeenCalledWith({
|
|
data: {
|
|
reservationId: 'reservation_1',
|
|
companyId: 'company_1',
|
|
renterId: undefined,
|
|
overallRating: 5,
|
|
vehicleRating: 4,
|
|
serviceRating: 5,
|
|
comment: 'Clean car',
|
|
isPublished: true,
|
|
},
|
|
})
|
|
})
|
|
})
|