fix: harden real backend workflows and channel connections

This commit is contained in:
hectorzhao
2026-07-06 17:54:53 +08:00
parent 8cca361441
commit b5132d7f4e
47 changed files with 2530 additions and 314 deletions
+36
View File
@@ -27,6 +27,7 @@ describe('FilesService', () => {
bucket: 'cmpp-platform',
fileName: '营业执照.png',
contentType: 'image/png',
sizeBytes: '12',
purpose: 'signature_material',
}));
@@ -47,4 +48,39 @@ describe('FilesService', () => {
}),
});
});
it('downloads file content from object storage by FileObject id', async () => {
const fileObject = {
id: 'file-1',
tenantId: 'tenant-1',
bucket: 'cmpp-platform',
objectKey: 'signature-materials/sig-1/file.png',
fileName: 'file.png',
contentType: 'image/png',
sizeBytes: BigInt(12),
checksum: null,
purpose: 'signature_material',
createdAt: new Date('2026-07-06T00:00:00.000Z'),
};
const prisma = {
fileObject: {
findUnique: jest.fn().mockResolvedValue(fileObject),
},
};
const objectStorage = {
getObject: jest.fn().mockResolvedValue(Buffer.from('file-content')),
};
const service = new FilesService(prisma as never, objectStorage as never);
await expect(service.getDownload('file-1')).resolves.toEqual({
fileObject: expect.objectContaining({
id: 'file-1',
fileName: 'file.png',
sizeBytes: '12',
}),
content: Buffer.from('file-content'),
});
expect(prisma.fileObject.findUnique).toHaveBeenCalledWith({ where: { id: 'file-1' } });
expect(objectStorage.getObject).toHaveBeenCalledWith('signature-materials/sig-1/file.png');
});
});