test(channels): cover line and zalo minio upload fallback path
This commit is contained in:
@@ -146,6 +146,44 @@ describe('LineAdapter', () => {
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('falls back to warning notice when MinIO upload fails', async () => {
|
||||
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
const adapter = new LineAdapter({
|
||||
channelAccessToken: 'token',
|
||||
channelSecret: 'secret',
|
||||
minio: {
|
||||
enabled: true,
|
||||
endpoint: 'localhost:9000',
|
||||
accessKey: 'minio',
|
||||
secretKey: 'secret',
|
||||
bucket: 'flynn',
|
||||
prefix: 'channels/line',
|
||||
secure: false,
|
||||
},
|
||||
minioExecRunner: vi.fn(async () => {
|
||||
throw new Error('mc unavailable');
|
||||
}),
|
||||
});
|
||||
await adapter.connect();
|
||||
mockFetch.mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
text: async () => '',
|
||||
} as Response);
|
||||
|
||||
await adapter.send('U123', {
|
||||
text: '',
|
||||
attachments: [{ mimeType: 'image/png', data: 'aGVsbG8=', filename: 'file.png' }],
|
||||
});
|
||||
|
||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||
const body = JSON.parse(String(mockFetch.mock.calls[0]?.[1]?.body ?? '{}'));
|
||||
expect(body.messages?.[0]?.text).toBe('[LINE] Binary attachment not uploaded yet: file.png (image/png).');
|
||||
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('LINE: MinIO upload failed'));
|
||||
expect(warnSpy).toHaveBeenCalledWith('LINE: skipping attachment data (image/png) — upload not implemented');
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('send delivers URL attachment even when text is empty', async () => {
|
||||
const adapter = new LineAdapter({
|
||||
channelAccessToken: 'token',
|
||||
|
||||
@@ -131,6 +131,43 @@ describe('ZaloAdapter', () => {
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('falls back to warning notice when MinIO upload fails', 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 () => {
|
||||
throw new Error('mc unavailable');
|
||||
}),
|
||||
});
|
||||
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('[Zalo] Binary attachment not uploaded yet: file.pdf (application/pdf).');
|
||||
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Zalo: MinIO upload failed'));
|
||||
expect(warnSpy).toHaveBeenCalledWith('Zalo: skipping attachment data (application/pdf) — upload not implemented');
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('send delivers URL attachment even when text is empty', async () => {
|
||||
const adapter = new ZaloAdapter({ oaAccessToken: 'token' });
|
||||
await adapter.connect();
|
||||
|
||||
Reference in New Issue
Block a user