Skip to content

Commit

Permalink
Added API test for message submission
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Dec 25, 2024
1 parent 841d054 commit a76f774
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/get-raw-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const crypto = require('crypto');
const { MIME_BOUNDARY_PREFIX } = require('./consts');

function getKeyHeader(licenseInfo) {
if (!licenseInfo) {
if (!licenseInfo?.details?.key) {
return 'UNLICENSED_COPY';
}
return msgpack.encode({ n: crypto.randomBytes(4), t: Date.now(), l: Buffer.from(licenseInfo.details.key, 'hex') }).toString('base64url');
Expand Down
42 changes: 42 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,48 @@ test('API tests', async t => {
assert.strictEqual(messageNewWebhook.data.subject, 'Fwd: Test message 🤣');
});

await t.test('submit by reference', async () => {
const response = await server
.post(`/v1/account/${defaultAccountId}/submit`)
.send({
reference: {
message: message2.id,
action: 'forward',
inline: true,
forwardAttachments: true,
messageId: '<test2@example.com>'
},
to: [
{
name: 'Test Received',
address: 'test.received@example.com'
}
],
text: 'Hallo hallo! 🙃',
html: '<b>Hallo hallo! 🙃</b>',
messageId: '<test4@example.com>'
})
.expect(200);

assert.ok(response.body.messageId);
assert.ok(response.body.queueId);

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 === '<test4@example.com>');
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('create a mailbox', async () => {
const response = await server
.post(`/v1/account/${defaultAccountId}/mailbox`)
Expand Down

0 comments on commit a76f774

Please sign in to comment.