Skip to content

Commit

Permalink
added api test to upload by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Dec 25, 2024
1 parent 7204c65 commit c5d2459
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ test('API tests', async t => {
auth: {
user: testAccount.user,
pass: testAccount.pass
}
},
resyncDelay: 60 * 1000
},
smtp: {
host: testAccount.smtp.host,
Expand Down Expand Up @@ -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: '<invalid@value>'
},
to: [
{
name: 'Test Received',
address: '[email protected]'
}
],
text: 'Hallo hallo! πŸ™ƒ',
html: '<b>Hallo hallo! πŸ™ƒ</b>',
messageId: '<[email protected]>'
})
// 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: '<[email protected]>'
},
to: [
{
name: 'Test Received',
address: '[email protected]'
}
],
text: 'Hallo hallo! πŸ™ƒ',
html: '<b>Hallo hallo! πŸ™ƒ</b>',
messageId: '<[email protected]>'
})
.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 === '<[email protected]>');
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`)
Expand Down

0 comments on commit c5d2459

Please sign in to comment.