refactor media module
This commit is contained in:
@@ -11,10 +11,19 @@ import { GetMediaOutputDTO } from './dtos/GetMediaOutputDTO';
|
||||
import { DeleteMediaOutputDTO } from './dtos/DeleteMediaOutputDTO';
|
||||
import { GetAvatarOutputDTO } from './dtos/GetAvatarOutputDTO';
|
||||
import { UpdateAvatarOutputDTO } from './dtos/UpdateAvatarOutputDTO';
|
||||
import { UpdateAvatarInputDTO } from './dtos/UpdateAvatarInputDTO';
|
||||
import type { MulterFile } from './types/MulterFile';
|
||||
|
||||
describe('MediaController', () => {
|
||||
let controller: MediaController;
|
||||
let service: jest.Mocked<MediaService>;
|
||||
let service: MediaService & {
|
||||
requestAvatarGeneration: ReturnType<typeof vi.fn>;
|
||||
uploadMedia: ReturnType<typeof vi.fn>;
|
||||
getMedia: ReturnType<typeof vi.fn>;
|
||||
deleteMedia: ReturnType<typeof vi.fn>;
|
||||
getAvatar: ReturnType<typeof vi.fn>;
|
||||
updateAvatar: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
@@ -35,7 +44,14 @@ describe('MediaController', () => {
|
||||
}).compile();
|
||||
|
||||
controller = module.get<MediaController>(MediaController);
|
||||
service = module.get(MediaService) as jest.Mocked<MediaService>;
|
||||
service = module.get(MediaService) as MediaService & {
|
||||
requestAvatarGeneration: ReturnType<typeof vi.fn>;
|
||||
uploadMedia: ReturnType<typeof vi.fn>;
|
||||
getMedia: ReturnType<typeof vi.fn>;
|
||||
deleteMedia: ReturnType<typeof vi.fn>;
|
||||
getAvatar: ReturnType<typeof vi.fn>;
|
||||
updateAvatar: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
});
|
||||
|
||||
const createMockResponse = (): Response => {
|
||||
@@ -92,7 +108,7 @@ describe('MediaController', () => {
|
||||
|
||||
describe('uploadMedia', () => {
|
||||
it('should upload media and return 201 on success', async () => {
|
||||
const file: Express.Multer.File = { filename: 'file.jpg' } as Express.Multer.File;
|
||||
const file: MulterFile = { filename: 'file.jpg' } as MulterFile;
|
||||
const input: UploadMediaInputDTO = { type: 'image' } as UploadMediaInputDTO;
|
||||
const dto: UploadMediaOutputDTO = {
|
||||
success: true,
|
||||
@@ -111,7 +127,7 @@ describe('MediaController', () => {
|
||||
});
|
||||
|
||||
it('should return 400 when upload fails', async () => {
|
||||
const file: Express.Multer.File = { filename: 'file.jpg' } as Express.Multer.File;
|
||||
const file: MulterFile = { filename: 'file.jpg' } as MulterFile;
|
||||
const input: UploadMediaInputDTO = { type: 'image' } as UploadMediaInputDTO;
|
||||
const dto: UploadMediaOutputDTO = {
|
||||
success: false,
|
||||
@@ -217,7 +233,7 @@ describe('MediaController', () => {
|
||||
describe('updateAvatar', () => {
|
||||
it('should update avatar and return result', async () => {
|
||||
const driverId = 'driver-123';
|
||||
const input: UpdateAvatarInputDTO = { avatarUrl: 'https://example.com/new-avatar.png' };
|
||||
const input: UpdateAvatarInputDTO = { driverId: 'driver-123', avatarUrl: 'https://example.com/new-avatar.png' };
|
||||
const dto: UpdateAvatarOutputDTO = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user