test(channels): cover line and zalo minio upload fallback path
This commit is contained in:
@@ -3712,6 +3712,18 @@
|
|||||||
"docs/plans/state.json"
|
"docs/plans/state.json"
|
||||||
],
|
],
|
||||||
"test_status": "pnpm test:run src/channels/line/adapter.test.ts src/channels/zalo/adapter.test.ts src/daemon/channels.test.ts + pnpm typecheck passing"
|
"test_status": "pnpm test:run src/channels/line/adapter.test.ts src/channels/zalo/adapter.test.ts src/daemon/channels.test.ts + pnpm typecheck passing"
|
||||||
|
},
|
||||||
|
"line-zalo-minio-failure-fallback-coverage": {
|
||||||
|
"status": "completed",
|
||||||
|
"date": "2026-02-17",
|
||||||
|
"updated": "2026-02-17",
|
||||||
|
"summary": "Added regression coverage for LINE/Zalo MinIO upload failure behavior to ensure adapters emit warning logs and still send explicit in-chat binary fallback notices when `mc` share operations fail.",
|
||||||
|
"files_modified": [
|
||||||
|
"src/channels/line/adapter.test.ts",
|
||||||
|
"src/channels/zalo/adapter.test.ts",
|
||||||
|
"docs/plans/state.json"
|
||||||
|
],
|
||||||
|
"test_status": "pnpm test:run src/channels/line/adapter.test.ts src/channels/zalo/adapter.test.ts + pnpm typecheck passing"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"overall_progress": {
|
"overall_progress": {
|
||||||
|
|||||||
@@ -146,6 +146,44 @@ describe('LineAdapter', () => {
|
|||||||
warnSpy.mockRestore();
|
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 () => {
|
it('send delivers URL attachment even when text is empty', async () => {
|
||||||
const adapter = new LineAdapter({
|
const adapter = new LineAdapter({
|
||||||
channelAccessToken: 'token',
|
channelAccessToken: 'token',
|
||||||
|
|||||||
@@ -131,6 +131,43 @@ describe('ZaloAdapter', () => {
|
|||||||
warnSpy.mockRestore();
|
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 () => {
|
it('send delivers URL attachment even when text is empty', async () => {
|
||||||
const adapter = new ZaloAdapter({ oaAccessToken: 'token' });
|
const adapter = new ZaloAdapter({ oaAccessToken: 'token' });
|
||||||
await adapter.connect();
|
await adapter.connect();
|
||||||
|
|||||||
Reference in New Issue
Block a user