This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace config files with .env files
- Loading branch information
Showing
38 changed files
with
359 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
node_modules/ | ||
config.ts | ||
config.js | ||
coverage/ | ||
dist/ | ||
dist/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import 'lib/tests/prepare'; | ||
import { SendMailOptions, createTransport } from 'nodemailer'; | ||
import { listProxyEmails } from 'lib/proxy-emails/list'; | ||
import { startSMTPServer } from 'lib/mail/smtp-server'; | ||
|
@@ -17,10 +18,8 @@ import { ParsedMail } from 'mailparser'; | |
import { addFilter } from 'lib/filters/add'; | ||
import { sendMail } from 'lib/mail/send'; | ||
import { saveMail } from 'lib/mail/save'; | ||
import * as CONFIG from 'constants/config'; | ||
import { getUser } from 'lib/users/get'; | ||
import { Ptorx } from 'types/ptorx'; | ||
import 'lib/tests/prepare'; | ||
|
||
test('build template', async () => { | ||
const template = await buildTemplate('verify-email', { | ||
|
@@ -39,26 +38,26 @@ test('get recipient: non-ptorx email', async () => { | |
test('get recipient: proxy email', async () => { | ||
const proxyEmail = await addProxyEmail( | ||
{ | ||
domainId: CONFIG.DOMAIN_ID, | ||
domainId: process.enve.DOMAIN_ID, | ||
address: 'recipient' | ||
}, | ||
1234 | ||
); | ||
const user = await getUser(1234); | ||
const recipient = await getRecipient(`recipient@${CONFIG.DOMAIN}`); | ||
const recipient = await getRecipient(`recipient@${process.enve.DOMAIN}`); | ||
const _recipient: Ptorx.Recipient = { | ||
user, | ||
address: `recipient@${CONFIG.DOMAIN}`, | ||
domainId: CONFIG.DOMAIN_ID, | ||
address: `recipient@${process.enve.DOMAIN}`, | ||
domainId: process.enve.DOMAIN_ID, | ||
proxyEmailId: proxyEmail.id | ||
}; | ||
expect(recipient).toMatchObject(_recipient); | ||
}); | ||
|
||
test('get recipient: bad address on proxy domain', async () => { | ||
const recipient = await getRecipient(`doesnotexist@${CONFIG.DOMAIN}`); | ||
const recipient = await getRecipient(`doesnotexist@${process.enve.DOMAIN}`); | ||
const _recipient: Ptorx.Recipient = { | ||
address: `doesnotexist@${CONFIG.DOMAIN}` | ||
address: `doesnotexist@${process.enve.DOMAIN}` | ||
}; | ||
expect(recipient).toMatchObject(_recipient); | ||
}); | ||
|
@@ -105,7 +104,7 @@ test('save mail', async () => { | |
text: 'Hello', | ||
to: { | ||
html: '', | ||
text: `user@${CONFIG.DOMAIN}`, | ||
text: `user@${process.enve.DOMAIN}`, | ||
value: [] | ||
}, | ||
textAsHtml: '', | ||
|
@@ -127,7 +126,7 @@ test('save mail', async () => { | |
headers: ['Header: Value'], | ||
html: null, | ||
subject: 'subject', | ||
to: `user@${CONFIG.DOMAIN}`, | ||
to: `user@${process.enve.DOMAIN}`, | ||
text: 'Hello' | ||
}; | ||
expect(message).toMatchObject(_message); | ||
|
@@ -147,7 +146,7 @@ test('filter mail', async () => { | |
text: 'Match', | ||
to: { | ||
html: '', | ||
text: `match@${CONFIG.DOMAIN}`, | ||
text: `match@${process.enve.DOMAIN}`, | ||
value: [] | ||
}, | ||
textAsHtml: '', | ||
|
@@ -166,7 +165,7 @@ test('filter mail', async () => { | |
text: 'No', | ||
to: { | ||
html: '', | ||
text: `no@${CONFIG.DOMAIN}`, | ||
text: `no@${process.enve.DOMAIN}`, | ||
value: [] | ||
}, | ||
textAsHtml: '', | ||
|
@@ -227,7 +226,7 @@ test('modify mail', async () => { | |
html: '<div>Hello <b>world</b>!</div>', | ||
from: '[email protected]', | ||
text: 'Hello world!', | ||
to: `user@${CONFIG.DOMAIN}` | ||
to: `user@${process.enve.DOMAIN}` | ||
}; | ||
|
||
let modifier = await addModifier( | ||
|
@@ -264,7 +263,9 @@ test('modify mail', async () => { | |
1234 | ||
); | ||
await modifyMail(mail, modifier.id, 1234); | ||
expect(mail.text).toBe(`[email protected] -> user@${CONFIG.DOMAIN} (Value)`); | ||
expect(mail.text).toBe( | ||
`[email protected] -> user@${process.enve.DOMAIN} (Value)` | ||
); | ||
}); | ||
|
||
test('send mail', async () => { | ||
|
@@ -299,12 +300,12 @@ test('smtp server', async () => { | |
session.envelope.mailFrom !== false | ||
? session.envelope.mailFrom.address | ||
: '' | ||
).toBe(CONFIG.PERSISTENT_PROXY_EMAIL); | ||
).toBe(process.enve.PERSISTENT_PROXY_EMAIL); | ||
expect(session.envelope.rcptTo[0].address).toBe('[email protected]'); | ||
|
||
// Headers from/to should be unchanged | ||
expect(message.from.text).toBe('You <[email protected]>'); | ||
expect(message.to.text).toBe(CONFIG.PERSISTENT_PROXY_EMAIL); | ||
expect(message.to.text).toBe(process.enve.PERSISTENT_PROXY_EMAIL); | ||
|
||
expect(message.subject).toBe('Hi'); | ||
expect(message.text).toBe('Hello world?'); | ||
|
@@ -315,18 +316,18 @@ test('smtp server', async () => { | |
message.headerLines.find(h => h.key == 'x-custom-header') | ||
).not.toBeUndefined(); | ||
expect(message.replyTo.text).toMatch( | ||
new RegExp(`^\\d+--.+--reply-x@${CONFIG.DOMAIN}$`) | ||
new RegExp(`^\\d+--.+--reply-x@${process.enve.DOMAIN}$`) | ||
); | ||
}); | ||
|
||
// Send to ACTUAL SMTP server | ||
const transporter = createTransport({ | ||
secure: false, | ||
host: '127.0.0.1', | ||
port: CONFIG.SMTP_PORT, | ||
port: process.enve.SMTP_PORT, | ||
tls: { rejectUnauthorized: false } | ||
}); | ||
// foo@example.com -> CONFIG.PERSISTENT_PROXY_EMAIL -> [email protected] | ||
// foo@example.com -> process.enve.PERSISTENT_PROXY_EMAIL -> [email protected] | ||
await transporter.sendMail({ | ||
attachments: [ | ||
{ | ||
|
@@ -340,7 +341,7 @@ test('smtp server', async () => { | |
from: 'You <[email protected]>', | ||
html: '<b>Hello world?</b>', | ||
text: 'Hello world?', | ||
to: CONFIG.PERSISTENT_PROXY_EMAIL | ||
to: process.enve.PERSISTENT_PROXY_EMAIL | ||
}); | ||
await promise; | ||
await new Promise(r => server.close(r)); | ||
|
@@ -371,11 +372,11 @@ test('reply to message', async () => { | |
// Send to ACTUAL SMTP server | ||
const transporter = createTransport({ | ||
host: '127.0.0.1', | ||
port: CONFIG.SMTP_PORT, | ||
port: process.enve.SMTP_PORT, | ||
secure: false, | ||
tls: { rejectUnauthorized: false } | ||
}); | ||
// foo@example.com -> --reply-x@CONFIG.DOMAIN -> [email protected] | ||
// foo@example.com -> --reply-x@process.enve.DOMAIN -> [email protected] | ||
await transporter.sendMail({ | ||
subject: 'Hello', | ||
from: '[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import 'lib/tests/prepare'; | ||
import { getMessage, getMessageAttachmentBin } from 'lib/messages/get'; | ||
import { deleteExpiredMessages } from 'jobs/delete-expired-messages'; | ||
import { replyToMessage } from 'lib/messages/reply'; | ||
|
@@ -7,19 +8,20 @@ import { listMessages } from 'lib/messages/list'; | |
import { captureMail } from 'lib/tests/capture-mail'; | ||
import { sendMessage } from 'lib/messages/send'; | ||
import { addMessage } from 'lib/messages/add'; | ||
import * as CONFIG from 'constants/config'; | ||
import { Ptorx } from 'types/ptorx'; | ||
import { MySQL } from 'lib/MySQL'; | ||
import 'lib/tests/prepare'; | ||
|
||
test('create message', async () => { | ||
const proxyEmail = await addProxyEmail({ domainId: CONFIG.DOMAIN_ID }, 1234); | ||
const proxyEmail = await addProxyEmail( | ||
{ domainId: process.enve.DOMAIN_ID }, | ||
1234 | ||
); | ||
const message = await addMessage( | ||
{ | ||
proxyEmailId: proxyEmail.id, | ||
subject: 'subject', | ||
from: '[email protected]', | ||
to: `test@${CONFIG.DOMAIN}`, | ||
to: `test@${process.enve.DOMAIN}`, | ||
text: 'Hello World', | ||
html: '<div>Hello World</div>', | ||
headers: ['Content-Type: text/html; charset="utf-8"'], | ||
|
@@ -43,7 +45,7 @@ test('create message', async () => { | |
proxyEmailId: proxyEmail.id, | ||
subject: 'subject', | ||
from: '[email protected]', | ||
to: `test@${CONFIG.DOMAIN}`, | ||
to: `test@${process.enve.DOMAIN}`, | ||
text: 'Hello World', | ||
html: '<div>Hello World</div>', | ||
headers: ['Content-Type: text/html; charset="utf-8"'], | ||
|
@@ -56,7 +58,9 @@ test('create message', async () => { | |
} | ||
], | ||
replyTo: null, | ||
ptorxReplyTo: `${message.id}--${message.key}--reply-x@${CONFIG.DOMAIN}` | ||
ptorxReplyTo: `${message.id}--${message.key}--reply-x@${ | ||
process.enve.DOMAIN | ||
}` | ||
}; | ||
expect(message).toMatchObject(_message); | ||
}); | ||
|
@@ -95,7 +99,7 @@ test('send and reply to messages', async () => { | |
|
||
const promise = captureMail(2, incoming => { | ||
expect(incoming.text.trim()).toBe('content'); | ||
expect(incoming.from.text).toEndWith(`@${CONFIG.DOMAIN}`); | ||
expect(incoming.from.text).toEndWith(`@${process.enve.DOMAIN}`); | ||
expect(incoming.to.text).toBe('[email protected]'); | ||
expect(incoming.subject).toBe('subject'); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
import 'lib/tests/prepare'; | ||
import { verifyPrimaryEmail } from 'lib/primary-emails/verify'; | ||
import { deletePrimaryEmail } from 'lib/primary-emails/delete'; | ||
import { listPrimaryEmails } from 'lib/primary-emails/list'; | ||
import { getPrimaryEmail } from 'lib/primary-emails/get'; | ||
import { addPrimaryEmail } from 'lib/primary-emails/add'; | ||
import { captureMail } from 'lib/tests/capture-mail'; | ||
import * as CONFIG from 'constants/config'; | ||
import { Ptorx } from 'types/ptorx'; | ||
import 'lib/tests/prepare'; | ||
|
||
test('create primary email', async () => { | ||
expect.assertions(12); | ||
|
||
const promise = captureMail(1, message => { | ||
expect(message.subject).toBe(`Verify your email for ${CONFIG.NAME}`); | ||
expect(message.from.text).toBe(`noreply-x@${CONFIG.DOMAIN}`); | ||
expect(message.subject).toBe(`Verify your email for ${process.enve.NAME}`); | ||
expect(message.from.text).toBe(`noreply-x@${process.enve.DOMAIN}`); | ||
expect(message.to.text).toBe('[email protected]'); | ||
expect(message.html).toMatch(/http.+Verify My Email/); | ||
expect(message.text).toMatch(/Verify My Email: http/); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.