feat(channels): share line and zalo binary attachments via minio

This commit is contained in:
William Valentin
2026-02-17 10:45:31 -08:00
parent bfb073ca5f
commit 108641415f
8 changed files with 385 additions and 4 deletions
+41
View File
@@ -90,6 +90,47 @@ describe('ZaloAdapter', () => {
warnSpy.mockRestore();
});
it('uploads binary attachments to MinIO and sends share URL when configured', async () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const adapter = new ZaloAdapter({
oaAccessToken: 'token',
minio: {
enabled: true,
endpoint: 'localhost:9000',
accessKey: 'minio',
secretKey: 'secret',
bucket: 'flynn',
prefix: 'channels/zalo',
secure: false,
},
minioExecRunner: vi.fn(async (_file, args) => {
if (args[0] === 'share') {
return { stdout: '{"share":"https://minio.local/share/file.pdf"}\n', stderr: '' };
}
return { stdout: '', stderr: '' };
}),
});
await adapter.connect();
mockFetch.mockResolvedValue({
ok: true,
status: 200,
text: async () => '',
} as Response);
await adapter.send('uid-1', {
text: '',
attachments: [
{ mimeType: 'application/pdf', data: 'aGVsbG8=', filename: 'file.pdf' },
],
});
expect(mockFetch).toHaveBeenCalledTimes(1);
const body = JSON.parse(String(mockFetch.mock.calls[0]?.[1]?.body ?? '{}'));
expect(body.message?.text).toBe('file.pdf: https://minio.local/share/file.pdf');
expect(warnSpy).not.toHaveBeenCalled();
warnSpy.mockRestore();
});
it('send delivers URL attachment even when text is empty', async () => {
const adapter = new ZaloAdapter({ oaAccessToken: 'token' });
await adapter.connect();