From c5d245961c67f2083e00fe467078d290f05561f3 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Wed, 25 Dec 2024 20:46:57 +0200 Subject: [PATCH] added api test to upload by reference --- test/api-test.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/test/api-test.js b/test/api-test.js index c4935f46..3ff0d23a 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -81,7 +81,8 @@ test('API tests', async t => { auth: { user: testAccount.user, pass: testAccount.pass - } + }, + resyncDelay: 60 * 1000 }, smtp: { host: testAccount.smtp.host, @@ -342,6 +343,72 @@ test('API tests', async t => { assert.deepEqual(messageUpdatedWebhook.data.changes.flags.added, ['\\Seen']); }); + await t.test('upload by reference', async () => { + await server + .post(`/v1/account/${defaultAccountId}/message`) + .send({ + path: 'Inbox', + reference: { + message: message2.id, + action: 'forward', + inline: true, + forwardAttachments: true, + messageId: '' + }, + to: [ + { + name: 'Test Received', + address: 'test.received@example.com' + } + ], + text: 'Hallo hallo! 🙃', + html: 'Hallo hallo! 🙃', + messageId: '' + }) + // fails message-id test + .expect(404); + + const response = await server + .post(`/v1/account/${defaultAccountId}/message`) + .send({ + path: 'Inbox', + reference: { + message: message2.id, + action: 'forward', + inline: true, + forwardAttachments: true, + messageId: '' + }, + to: [ + { + name: 'Test Received', + address: 'test.received@example.com' + } + ], + text: 'Hallo hallo! 🙃', + html: 'Hallo hallo! 🙃', + messageId: '' + }) + .expect(200); + + assert.ok(response.body.id); + + let received = false; + let messageNewWebhook = false; + while (!received) { + await new Promise(r => setTimeout(r, 1000)); + let webhooks = webhooksServer.webhooks.get(defaultAccountId); + messageNewWebhook = webhooks.find(wh => wh.path === 'INBOX' && wh.event === 'messageNew' && wh.data.messageId === ''); + if (messageNewWebhook) { + received = true; + } + } + + assert.ok(/Begin forwarded message/.test(messageNewWebhook.data.text.plain)); + assert.strictEqual(messageNewWebhook.data.attachments[0].filename, 'transparent.gif'); + assert.strictEqual(messageNewWebhook.data.subject, 'Fwd: Test message 🤣'); + }); + await t.test('move message to another folder', async () => { const response = await server .put(`/v1/account/${defaultAccountId}/message/${message2.id}/move`)