Skip to content

Commit

Permalink
[feat] added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maielo committed Aug 31, 2021
1 parent 3cde91b commit a96be41
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
.DS_Store
node_modules
dist
test
.package-lock.json
config
148 changes: 147 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "dist/index.js",
"scripts": {
"start": "npx tsdx watch --onSuccess \"node ./dist/index.js\"",
"customtest": "npx nodemon test/test.js",
"build": "npx tsdx build --target node",
"lint": "npx tsdx lint",
"test": "npx tsdx test --watch",
"prepare": "npx tsdx build --target node",
"np:publish": "git push origin master && np --no-tests --no-2fa",
"size": "size-limit",
Expand All @@ -16,6 +16,7 @@
"peerDependencies": {},
"devDependencies": {
"@size-limit/preset-small-lib": "^4.10.2",
"@types/jest": "^27.0.1",
"@types/nodemailer": "^6.4.4",
"babel-runtime": "^6.26.0",
"nodemon": "^2.0.7",
Expand Down
35 changes: 35 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import NmSender from '../src/index';
import credentials from '../config/credentials';

const nm = new NmSender({
host: credentials.EMAIL_SMTP_HOST,
password: credentials.EMAIL_SMTP_PASSWORD,
user: credentials.EMAIL_SMTP_LOGIN,
port: credentials.EMAIL_SMTP_PORT,
defaultFromAddress: credentials.EMAIL_DEFAULT_ADDRESS,
retryTime: 1, // in SEC
maxRetries: 2,
});

describe('nm-sender', () => {
it('Should be able to send email`', async () => {
expect.assertions(1);
const info = await nm.sendMail({
to: credentials.EMAIL_TO_TEST_ADDRESS,
subject: 'hey test',
text: 'Hello there, email should be fine',
});

expect(info.accepted[0]).toEqual(credentials.EMAIL_TO_TEST_ADDRESS);
});

it('When fails it should retry and gives up', async () => {
expect(async () => {
await nm.sendMail({
to: 'nonexistentinal-email-email@email-asd-asd-asd-asd.com',
subject: 'hey test',
text: 'Hello there, email should not be sent',
});
}).rejects.toBeDefined();
});
});

0 comments on commit a96be41

Please sign in to comment.