Skip to content

Commit c5d2459

Browse files
committed
added api test to upload by reference
1 parent 7204c65 commit c5d2459

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

test/api-test.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ test('API tests', async t => {
8181
auth: {
8282
user: testAccount.user,
8383
pass: testAccount.pass
84-
}
84+
},
85+
resyncDelay: 60 * 1000
8586
},
8687
smtp: {
8788
host: testAccount.smtp.host,
@@ -342,6 +343,72 @@ test('API tests', async t => {
342343
assert.deepEqual(messageUpdatedWebhook.data.changes.flags.added, ['\\Seen']);
343344
});
344345

346+
await t.test('upload by reference', async () => {
347+
await server
348+
.post(`/v1/account/${defaultAccountId}/message`)
349+
.send({
350+
path: 'Inbox',
351+
reference: {
352+
message: message2.id,
353+
action: 'forward',
354+
inline: true,
355+
forwardAttachments: true,
356+
messageId: '<invalid@value>'
357+
},
358+
to: [
359+
{
360+
name: 'Test Received',
361+
address: 'test.received@example.com'
362+
}
363+
],
364+
text: 'Hallo hallo! 🙃',
365+
html: '<b>Hallo hallo! 🙃</b>',
366+
messageId: '<test3@example.com>'
367+
})
368+
// fails message-id test
369+
.expect(404);
370+
371+
const response = await server
372+
.post(`/v1/account/${defaultAccountId}/message`)
373+
.send({
374+
path: 'Inbox',
375+
reference: {
376+
message: message2.id,
377+
action: 'forward',
378+
inline: true,
379+
forwardAttachments: true,
380+
messageId: '<test2@example.com>'
381+
},
382+
to: [
383+
{
384+
name: 'Test Received',
385+
address: 'test.received@example.com'
386+
}
387+
],
388+
text: 'Hallo hallo! 🙃',
389+
html: '<b>Hallo hallo! 🙃</b>',
390+
messageId: '<test3@example.com>'
391+
})
392+
.expect(200);
393+
394+
assert.ok(response.body.id);
395+
396+
let received = false;
397+
let messageNewWebhook = false;
398+
while (!received) {
399+
await new Promise(r => setTimeout(r, 1000));
400+
let webhooks = webhooksServer.webhooks.get(defaultAccountId);
401+
messageNewWebhook = webhooks.find(wh => wh.path === 'INBOX' && wh.event === 'messageNew' && wh.data.messageId === '<test3@example.com>');
402+
if (messageNewWebhook) {
403+
received = true;
404+
}
405+
}
406+
407+
assert.ok(/Begin forwarded message/.test(messageNewWebhook.data.text.plain));
408+
assert.strictEqual(messageNewWebhook.data.attachments[0].filename, 'transparent.gif');
409+
assert.strictEqual(messageNewWebhook.data.subject, 'Fwd: Test message 🤣');
410+
});
411+
345412
await t.test('move message to another folder', async () => {
346413
const response = await server
347414
.put(`/v1/account/${defaultAccountId}/message/${message2.id}/move`)

0 commit comments

Comments
 (0)