feat: harden CMPP delivery and platform workflows

This commit is contained in:
hectorzhao
2026-07-20 18:07:29 +08:00
parent 80fb5a8f53
commit f02c33cbb7
61 changed files with 1834 additions and 281 deletions
+21
View File
@@ -1,3 +1,4 @@
import { BadRequestException } from '@nestjs/common';
import { FilesService } from './files.service';
describe('FilesService', () => {
@@ -81,6 +82,26 @@ describe('FilesService', () => {
);
});
it('rejects images over 2MB and other files over 10MB before object storage writes', async () => {
const prisma = { fileObject: { create: jest.fn() } };
const objectStorage = { putObject: jest.fn(), getBucket: jest.fn().mockReturnValue('bucket') };
const service = new FilesService(prisma as never, objectStorage as never);
await expect(service.upload({ purpose: 'test' }, {
originalname: 'large.png',
mimetype: 'image/png',
size: 2 * 1024 * 1024 + 1,
buffer: Buffer.alloc(0),
})).rejects.toBeInstanceOf(BadRequestException);
await expect(service.upload({ purpose: 'test' }, {
originalname: 'large.pdf',
mimetype: 'application/pdf',
size: 10 * 1024 * 1024 + 1,
buffer: Buffer.alloc(0),
})).rejects.toBeInstanceOf(BadRequestException);
expect(objectStorage.putObject).not.toHaveBeenCalled();
});
it('downloads file content from object storage by FileObject id', async () => {
const fileObject = {
id: 'file-1',