Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 40s
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { brandService } from './brandService';
|
|
import * as db from './db/index.db';
|
|
import type { Logger } from 'pino';
|
|
|
|
// Mock dependencies
|
|
vi.mock('./db/index.db', () => ({
|
|
adminRepo: {
|
|
updateBrandLogo: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
describe('BrandService', () => {
|
|
const mockLogger = {} as Logger;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('updateBrandLogo', () => {
|
|
it('should update brand logo and return the new URL', async () => {
|
|
const brandId = 123;
|
|
const mockFile = {
|
|
filename: 'test-logo.jpg',
|
|
} as Express.Multer.File;
|
|
|
|
vi.mocked(db.adminRepo.updateBrandLogo).mockResolvedValue(undefined);
|
|
|
|
const result = await brandService.updateBrandLogo(brandId, mockFile, mockLogger);
|
|
|
|
expect(result).toBe('/flyer-images/test-logo.jpg');
|
|
expect(db.adminRepo.updateBrandLogo).toHaveBeenCalledWith(
|
|
brandId,
|
|
'/flyer-images/test-logo.jpg',
|
|
mockLogger,
|
|
);
|
|
});
|
|
|
|
it('should throw error if database update fails', async () => {
|
|
const brandId = 123;
|
|
const mockFile = {
|
|
filename: 'test-logo.jpg',
|
|
} as Express.Multer.File;
|
|
const dbError = new Error('DB Error');
|
|
|
|
vi.mocked(db.adminRepo.updateBrandLogo).mockRejectedValue(dbError);
|
|
|
|
await expect(brandService.updateBrandLogo(brandId, mockFile, mockLogger)).rejects.toThrow('DB Error');
|
|
});
|
|
});
|
|
}); |