Skip to content

Commit

Permalink
Added Gmail API test for submit reference
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Dec 28, 2024
1 parent c30d861 commit c9c9784
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ test('API tests', async t => {
let oauth2PubsubId;
let oauth2AppId;

let gmailReceivedEmailId;
let gmailReceivedMessageId;

t.before(async () => {
testAccount = await nodemailer.createTestAccount();
await webhooksServer.init();
Expand Down Expand Up @@ -627,16 +630,14 @@ test('API tests', async t => {
assert.ok(response.body.messageId);
assert.ok(response.body.queueId);

let finalMessageId;

let sent = false;
let messageSentWebhook = false;
while (!sent) {
await new Promise(r => setTimeout(r, 1000));
let webhooks = webhooksServer.webhooks.get(gmailAccountId2);
messageSentWebhook = webhooks.find(wh => wh.event === 'messageSent' && wh.data.originalMessageId === messageId);
if (messageSentWebhook) {
finalMessageId = messageSentWebhook.data.messageId;
gmailReceivedMessageId = messageSentWebhook.data.messageId;
sent = true;
}
}
Expand All @@ -646,15 +647,69 @@ test('API tests', async t => {
while (!received) {
await new Promise(r => setTimeout(r, 1000));
let webhooks = webhooksServer.webhooks.get(gmailAccountId1);
messageNewWebhook = webhooks.find(wh => wh.event === 'messageNew' && wh.data.messageId === finalMessageId);
messageNewWebhook = webhooks.find(wh => wh.event === 'messageNew' && wh.data.messageId === gmailReceivedMessageId);
if (messageNewWebhook) {
received = true;
}
}

// * is added by gmail
assert.strictEqual(messageNewWebhook.data.text.plain.trim(), '*Hallo hallo! 🙃*');
assert.strictEqual(messageNewWebhook.data.messageId, finalMessageId);
assert.strictEqual(messageNewWebhook.data.messageId, gmailReceivedMessageId);
assert.strictEqual(messageNewWebhook.data.subject.trim(), 'Hallo hallo 🤣');

gmailReceivedEmailId = messageNewWebhook.data.id;
assert.ok(gmailReceivedEmailId);
});

await t.test('reply by reference by API', async () => {
let messageId = `<test-${Date.now()}@example.com>`;

const response = await server
.post(`/v1/account/${gmailAccountId1}/submit`)
.send({
reference: {
message: gmailReceivedEmailId,
action: 'reply',
inline: true
},
text: 'Keedu kartul! 🍟',
html: '<b>Keedu kartul! 🍟</b>',
messageId
})
.expect(200);

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

let gmailReceivedMessageId;

let sent = false;
let messageSentWebhook = false;
while (!sent) {
await new Promise(r => setTimeout(r, 1000));
let webhooks = webhooksServer.webhooks.get(gmailAccountId1);
messageSentWebhook = webhooks.find(wh => wh.event === 'messageSent' && wh.data.originalMessageId === messageId);
if (messageSentWebhook) {
gmailReceivedMessageId = messageSentWebhook.data.messageId;
sent = true;
}
}

let received = false;
let messageNewWebhook = false;
while (!received) {
await new Promise(r => setTimeout(r, 1000));
let webhooks = webhooksServer.webhooks.get(gmailAccountId2);
messageNewWebhook = webhooks.find(wh => wh.event === 'messageNew' && wh.data.messageId === gmailReceivedMessageId);
if (messageNewWebhook) {
received = true;
}
}

assert.strictEqual(messageNewWebhook.data.subject.trim(), 'Re: Hallo hallo 🤣');
assert.strictEqual(messageNewWebhook.data.inReplyTo, gmailReceivedMessageId);

assert.ok(messageNewWebhook);
});
});

0 comments on commit c9c9784

Please sign in to comment.