add tests and registry
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { presentBrand } from './company.presenter'
|
||||
|
||||
const fullBrand = {
|
||||
id: 'brand_1',
|
||||
companyId: 'comp_1',
|
||||
displayName: 'Test Rentals',
|
||||
subdomain: 'test-rentals',
|
||||
logoUrl: 'https://example.com/logo.jpg',
|
||||
primaryColor: '#1A56DB',
|
||||
defaultLocale: 'en',
|
||||
defaultCurrency: 'MAD',
|
||||
amanpayMerchantId: 'merchant-abc',
|
||||
amanpaySecretKey: 'super-secret-key',
|
||||
paypalEmail: 'paypal@example.com',
|
||||
paypalMerchantId: 'paypal-merchant-xyz',
|
||||
isListedOnMarketplace: true,
|
||||
}
|
||||
|
||||
describe('presentBrand', () => {
|
||||
it('strips amanpaySecretKey from the response', () => {
|
||||
const result = presentBrand(fullBrand)
|
||||
expect(result).not.toHaveProperty('amanpaySecretKey')
|
||||
})
|
||||
|
||||
it('strips amanpayMerchantId from the response', () => {
|
||||
const result = presentBrand(fullBrand)
|
||||
expect(result).not.toHaveProperty('amanpayMerchantId')
|
||||
})
|
||||
|
||||
it('strips paypalEmail from the response', () => {
|
||||
const result = presentBrand(fullBrand)
|
||||
expect(result).not.toHaveProperty('paypalEmail')
|
||||
})
|
||||
|
||||
it('strips paypalMerchantId from the response', () => {
|
||||
const result = presentBrand(fullBrand)
|
||||
expect(result).not.toHaveProperty('paypalMerchantId')
|
||||
})
|
||||
|
||||
it('sets amanpayConfigured=true when both amanpay credentials are present', () => {
|
||||
const result = presentBrand(fullBrand)
|
||||
expect(result.amanpayConfigured).toBe(true)
|
||||
})
|
||||
|
||||
it('sets amanpayConfigured=false when amanpaySecretKey is null', () => {
|
||||
const result = presentBrand({ ...fullBrand, amanpaySecretKey: null })
|
||||
expect(result.amanpayConfigured).toBe(false)
|
||||
})
|
||||
|
||||
it('sets amanpayConfigured=false when amanpayMerchantId is null', () => {
|
||||
const result = presentBrand({ ...fullBrand, amanpayMerchantId: null })
|
||||
expect(result.amanpayConfigured).toBe(false)
|
||||
})
|
||||
|
||||
it('sets amanpayConfigured=false when both amanpay fields are null', () => {
|
||||
const result = presentBrand({ ...fullBrand, amanpayMerchantId: null, amanpaySecretKey: null })
|
||||
expect(result.amanpayConfigured).toBe(false)
|
||||
})
|
||||
|
||||
it('sets paypalConfigured=true when paypalEmail is set', () => {
|
||||
const result = presentBrand({ ...fullBrand, paypalMerchantId: null })
|
||||
expect(result.paypalConfigured).toBe(true)
|
||||
})
|
||||
|
||||
it('sets paypalConfigured=true when paypalMerchantId is set', () => {
|
||||
const result = presentBrand({ ...fullBrand, paypalEmail: null })
|
||||
expect(result.paypalConfigured).toBe(true)
|
||||
})
|
||||
|
||||
it('sets paypalConfigured=false when both paypal fields are null', () => {
|
||||
const result = presentBrand({ ...fullBrand, paypalEmail: null, paypalMerchantId: null })
|
||||
expect(result.paypalConfigured).toBe(false)
|
||||
})
|
||||
|
||||
it('preserves all non-credential fields', () => {
|
||||
const result = presentBrand(fullBrand)
|
||||
expect(result).toMatchObject({
|
||||
id: 'brand_1',
|
||||
companyId: 'comp_1',
|
||||
displayName: 'Test Rentals',
|
||||
subdomain: 'test-rentals',
|
||||
logoUrl: 'https://example.com/logo.jpg',
|
||||
primaryColor: '#1A56DB',
|
||||
defaultLocale: 'en',
|
||||
defaultCurrency: 'MAD',
|
||||
isListedOnMarketplace: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('returns null when brand is null', () => {
|
||||
expect(presentBrand(null)).toBeNull()
|
||||
})
|
||||
|
||||
it('returns undefined when brand is undefined', () => {
|
||||
expect(presentBrand(undefined)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -122,4 +122,27 @@ describe('vehicle.service', () => {
|
||||
expect(result).toEqual({ id: 'block_1' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('getMaintenanceLogs', () => {
|
||||
it('throws NotFoundError when vehicle does not belong to the requesting company', async () => {
|
||||
vi.mocked(repo.findById).mockResolvedValue(null)
|
||||
await expect(service.getMaintenanceLogs('veh_1', 'other_company')).rejects.toThrow('Vehicle not found')
|
||||
})
|
||||
|
||||
it('returns maintenance logs when vehicle belongs to the requesting company', async () => {
|
||||
const mockLogs = [{ id: 'log_1', vehicleId: 'veh_1', description: 'Oil change' }]
|
||||
vi.mocked(repo.findById).mockResolvedValue(mockVehicle as any)
|
||||
vi.mocked(repo.findMaintenanceLogs).mockResolvedValue(mockLogs as any)
|
||||
const result = await service.getMaintenanceLogs('veh_1', 'comp_1')
|
||||
expect(repo.findById).toHaveBeenCalledWith('veh_1', 'comp_1')
|
||||
expect(result).toEqual(mockLogs)
|
||||
})
|
||||
|
||||
it('passes companyId to repo.findById for ownership validation', async () => {
|
||||
vi.mocked(repo.findById).mockResolvedValue(mockVehicle as any)
|
||||
vi.mocked(repo.findMaintenanceLogs).mockResolvedValue([])
|
||||
await service.getMaintenanceLogs('veh_1', 'comp_1')
|
||||
expect(repo.findById).toHaveBeenCalledWith('veh_1', 'comp_1')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user