fix(channels): forward line and zalo URL attachments

This commit is contained in:
William Valentin
2026-02-17 10:19:00 -08:00
parent 27b3acf5e6
commit 288ef5ac3c
4 changed files with 130 additions and 8 deletions
+50
View File
@@ -74,6 +74,56 @@ describe('LineAdapter', () => {
expect(mockFetch.mock.calls[0]?.[0]).toBe('https://api.line.me/v2/bot/message/push');
});
it('send emits URL attachments and warns for binary attachments', async () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const adapter = new LineAdapter({
channelAccessToken: 'token',
channelSecret: 'secret',
});
await adapter.connect();
mockFetch.mockResolvedValue({
ok: true,
status: 200,
text: async () => '',
} as Response);
await adapter.send('U123', {
text: 'hello line',
attachments: [
{ mimeType: 'text/plain', url: 'https://example.com/file.txt', filename: 'file.txt' },
{ mimeType: 'image/png', data: 'aGVsbG8=' },
],
});
expect(mockFetch).toHaveBeenCalledTimes(2);
const secondBody = JSON.parse(String(mockFetch.mock.calls[1]?.[1]?.body ?? '{}'));
expect(secondBody.messages?.[0]?.text).toBe('file.txt: https://example.com/file.txt');
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',
channelSecret: 'secret',
});
await adapter.connect();
mockFetch.mockResolvedValue({
ok: true,
status: 200,
text: async () => '',
} as Response);
await adapter.send('U123', {
text: ' ',
attachments: [{ mimeType: 'text/plain', url: 'https://example.com/file.txt', filename: 'file.txt' }],
});
expect(mockFetch).toHaveBeenCalledTimes(1);
const body = JSON.parse(String(mockFetch.mock.calls[0]?.[1]?.body ?? '{}'));
expect(body.messages?.[0]?.text).toBe('file.txt: https://example.com/file.txt');
});
it('handleRequest validates signature and dispatches text event', async () => {
const adapter = new LineAdapter({
channelAccessToken: 'token',