Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Replace config files with .env files
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXyfir committed Feb 25, 2019
1 parent 7b6980e commit a360f4d
Show file tree
Hide file tree
Showing 38 changed files with 359 additions and 295 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
config.ts
config.js
coverage/
dist/
dist/
.env
4 changes: 2 additions & 2 deletions server/__tests__/domains.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getDomainAuth, getDomain } from 'lib/domains/get';
import 'lib/tests/prepare';
import { listDomainUsers } from 'lib/domains/users/list';
import { addDomainUser } from 'lib/domains/users/add';
import { getDomainAuth } from 'lib/domains/get';
import { verifyDomain } from 'lib/domains/verify';
import { deleteDomain } from 'lib/domains/delete';
import { listDomains } from 'lib/domains/list';
import { addDomain } from 'lib/domains/add';
import { Ptorx } from 'types/ptorx';
import 'lib/tests/prepare';

test('create domain', async () => {
const domain = await addDomain({ domain: 'example.com' }, 1234);
Expand Down
2 changes: 1 addition & 1 deletion server/__tests__/filters.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'lib/tests/prepare';
import { deleteFilter } from 'lib/filters/delete';
import { listFilters } from 'lib/filters/list';
import { addFilter } from 'lib/filters/add';
import { Ptorx } from 'types/ptorx';
import 'lib/tests/prepare';

test('create filter 1', async () => {
const filter = await addFilter({ type: 'subject', name: 'name' }, 1234);
Expand Down
2 changes: 1 addition & 1 deletion server/__tests__/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'lib/tests/prepare';
import { verifyJWT } from 'lib/jwt/verify';
import { signJWT } from 'lib/jwt/sign';
import 'lib/tests/prepare';

test('sign and verify jwt', async () => {
const encoded = await signJWT(
Expand Down
45 changes: 23 additions & 22 deletions server/__tests__/mail.ts
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';
Expand All @@ -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', {
Expand All @@ -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);
});
Expand Down Expand Up @@ -105,7 +104,7 @@ test('save mail', async () => {
text: 'Hello',
to: {
html: '',
text: `user@${CONFIG.DOMAIN}`,
text: `user@${process.enve.DOMAIN}`,
value: []
},
textAsHtml: '',
Expand All @@ -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);
Expand All @@ -147,7 +146,7 @@ test('filter mail', async () => {
text: 'Match',
to: {
html: '',
text: `match@${CONFIG.DOMAIN}`,
text: `match@${process.enve.DOMAIN}`,
value: []
},
textAsHtml: '',
Expand All @@ -166,7 +165,7 @@ test('filter mail', async () => {
text: 'No',
to: {
html: '',
text: `no@${CONFIG.DOMAIN}`,
text: `no@${process.enve.DOMAIN}`,
value: []
},
textAsHtml: '',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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?');
Expand All @@ -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: [
{
Expand All @@ -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));
Expand Down Expand Up @@ -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]',
Expand Down
18 changes: 11 additions & 7 deletions server/__tests__/messages.ts
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';
Expand All @@ -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"'],
Expand All @@ -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"'],
Expand All @@ -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);
});
Expand Down Expand Up @@ -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');
});
Expand Down
2 changes: 1 addition & 1 deletion server/__tests__/modifiers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'lib/tests/prepare';
import { deleteModifier } from 'lib/modifiers/delete';
import { listModifiers } from 'lib/modifiers/list';
import { addModifier } from 'lib/modifiers/add';
import { Ptorx } from 'types/ptorx';
import 'lib/tests/prepare';

test('create modifier', async () => {
const modifier = await addModifier({ name: 'name', template: 'test' }, 1234);
Expand Down
4 changes: 2 additions & 2 deletions server/__tests__/payments.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'lib/tests/prepare';
import { finishPayment } from 'lib/payments/finish';
import { startPayment } from 'lib/payments/start';
import { addPayment } from 'lib/payments/add';
import { verifyJWT } from 'lib/jwt/verify';
import { getUser } from 'lib/users/get';
import { signJWT } from 'lib/jwt/sign';
import { Ptorx } from 'types/ptorx';
import 'lib/tests/prepare';
import { getUser } from 'lib/users/get';

test('create payment', async () => {
const paid = Date.now();
Expand Down
7 changes: 3 additions & 4 deletions server/__tests__/primary-emails.ts
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/);
Expand Down
13 changes: 6 additions & 7 deletions server/__tests__/proxy-emails.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import 'lib/tests/prepare';
import { deleteProxyEmail } from 'lib/proxy-emails/delete';
import { listProxyEmails } from 'lib/proxy-emails/list';
import { editProxyEmail } from 'lib/proxy-emails/edit';
import { addProxyEmail } from 'lib/proxy-emails/add';
import { getProxyEmail } from 'lib/proxy-emails/get';
import { addModifier } from 'lib/modifiers/add';
import { addFilter } from 'lib/filters/add';
import * as CONFIG from 'constants/config';
import { Ptorx } from 'types/ptorx';
import 'lib/tests/prepare';

test('create custom proxy email', async () => {
const proxyEmail = await addProxyEmail(
{
domainId: CONFIG.DOMAIN_ID,
domainId: process.enve.DOMAIN_ID,
address: 'test',
name: 'name'
},
Expand All @@ -26,18 +25,18 @@ test('create custom proxy email', async () => {
...proxyEmail,
name: 'name',
address: 'test',
domainId: CONFIG.DOMAIN_ID,
domainId: process.enve.DOMAIN_ID,
saveMail: false,
links: [],
fullAddress: `test@${CONFIG.DOMAIN}`
fullAddress: `test@${process.enve.DOMAIN}`
};
expect(proxyEmail).toMatchObject(_proxyEmail);
});

test('create random proxy email', async () => {
const proxyEmail = await addProxyEmail(
{
domainId: CONFIG.DOMAIN_ID,
domainId: process.enve.DOMAIN_ID,
saveMail: true
},
1234
Expand All @@ -46,7 +45,7 @@ test('create random proxy email', async () => {
const _proxyEmail: Ptorx.ProxyEmail = {
...proxyEmail,
name: '',
domainId: CONFIG.DOMAIN_ID,
domainId: process.enve.DOMAIN_ID,
saveMail: true
};
expect(proxyEmail).toMatchObject(_proxyEmail);
Expand Down
2 changes: 1 addition & 1 deletion server/__tests__/users.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'lib/tests/prepare';
import { chargeCredits } from 'lib/users/charge';
import { getUser } from 'lib/users/get';
import { Ptorx } from 'types/ptorx';
import 'lib/tests/prepare';

test('get user', async () => {
const userId = Date.now();
Expand Down
Loading

0 comments on commit a360f4d

Please sign in to comment.