harden media
This commit is contained in:
@@ -19,9 +19,8 @@ vi.mock('@/hooks/useEffectiveDriverId', () => {
|
||||
};
|
||||
});
|
||||
|
||||
// Mock services hook to inject stub driverService/mediaService
|
||||
const mockFindById = vi.fn<[], Promise<DriverDTO | null>>();
|
||||
const mockGetDriverAvatar = vi.fn<(driverId: string) => string>();
|
||||
// Mock services hook to inject stub driverService
|
||||
const mockFindById = vi.fn();
|
||||
|
||||
vi.mock('@/lib/services/ServiceProvider', () => {
|
||||
return {
|
||||
@@ -30,7 +29,7 @@ vi.mock('@/lib/services/ServiceProvider', () => {
|
||||
findById: mockFindById,
|
||||
},
|
||||
mediaService: {
|
||||
getDriverAvatar: mockGetDriverAvatar,
|
||||
getDriverAvatar: vi.fn(),
|
||||
},
|
||||
}),
|
||||
};
|
||||
@@ -66,7 +65,6 @@ describe('UserPill', () => {
|
||||
mockedAuthValue = { session: null };
|
||||
mockedDriverId = null;
|
||||
mockFindById.mockReset();
|
||||
mockGetDriverAvatar.mockReset();
|
||||
});
|
||||
|
||||
it('renders auth links when there is no session', () => {
|
||||
@@ -94,19 +92,19 @@ describe('UserPill', () => {
|
||||
expect(mockFindById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('loads driver via driverService and uses mediaService avatar', async () => {
|
||||
it('loads driver via driverService and uses driver avatarUrl', async () => {
|
||||
const driver: DriverDTO = {
|
||||
id: 'driver-1',
|
||||
iracingId: 'ir-123',
|
||||
name: 'Test Driver',
|
||||
country: 'DE',
|
||||
avatarUrl: '/api/media/avatar/driver-1',
|
||||
};
|
||||
|
||||
mockedAuthValue = { session: { user: { id: 'user-1' } } };
|
||||
mockedDriverId = driver.id;
|
||||
|
||||
mockFindById.mockResolvedValue(driver);
|
||||
mockGetDriverAvatar.mockImplementation((driverId: string) => `/api/media/avatar/${driverId}`);
|
||||
|
||||
render(<UserPill />);
|
||||
|
||||
@@ -115,6 +113,5 @@ describe('UserPill', () => {
|
||||
});
|
||||
|
||||
expect(mockFindById).toHaveBeenCalledWith('driver-1');
|
||||
expect(mockGetDriverAvatar).toHaveBeenCalledWith('driver-1');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user