251209:1453 Frontend: progress nest = UAT & Bug Fixing
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-09 14:53:42 +07:00
parent 8aceced902
commit aa96cd90e3
125 changed files with 11052 additions and 785 deletions

View File

@@ -1,12 +1,26 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FileStorageController } from './file-storage.controller';
import { FileStorageService } from './file-storage.service';
describe('FileStorageController', () => {
let controller: FileStorageController;
let mockFileStorageService: Partial<FileStorageService>;
beforeEach(async () => {
mockFileStorageService = {
upload: jest.fn(),
download: jest.fn(),
delete: jest.fn(),
};
const module: TestingModule = await Test.createTestingModule({
controllers: [FileStorageController],
providers: [
{
provide: FileStorageService,
useValue: mockFileStorageService,
},
],
}).compile();
controller = module.get<FileStorageController>(FileStorageController);
@@ -15,4 +29,25 @@ describe('FileStorageController', () => {
it('should be defined', () => {
expect(controller).toBeDefined();
});
describe('uploadFile', () => {
it('should upload a file successfully', async () => {
const mockFile = {
originalname: 'test.pdf',
buffer: Buffer.from('test'),
mimetype: 'application/pdf',
size: 100,
} as Express.Multer.File;
const mockResult = { attachment_id: 1, originalFilename: 'test.pdf' };
(mockFileStorageService.upload as jest.Mock).mockResolvedValue(
mockResult
);
const mockReq = { user: { userId: 1, username: 'testuser' } };
const result = await controller.uploadFile(mockFile, mockReq as any);
expect(mockFileStorageService.upload).toHaveBeenCalledWith(mockFile, 1);
});
});
});