mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
fix(nodemailer): Refactored the nodemailer lib
This commit is contained in:
Generated
+1046
-2559
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -68,7 +68,7 @@
|
||||
"husky": "^4.3.8",
|
||||
"mocha": "^8.2.1",
|
||||
"nyc": "^15.1.0",
|
||||
"semantic-release": "^17.3.7",
|
||||
"semantic-release": "^17.4.2",
|
||||
"sinon": "^9.2.4",
|
||||
"standard": "^16.0.3"
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
A library for controlling the sending email.
|
||||
A library for controlling the sending of email.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
/*
|
||||
Unit tests for the nodemailer.js library.
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
|
||||
const NodeMailer = require('../../../src/lib/nodemailer')
|
||||
|
||||
const sinon = require('sinon')
|
||||
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
let sandbox
|
||||
let uut
|
||||
|
||||
describe('NodeMailer', () => {
|
||||
beforeEach(() => {
|
||||
uut = new NodeMailer()
|
||||
@@ -30,7 +32,7 @@ describe('NodeMailer', () => {
|
||||
await uut.sendEmail(data)
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'email\' must be a string!')
|
||||
assert.include(err.message, "Property 'email' must be a string!")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -45,9 +47,10 @@ describe('NodeMailer', () => {
|
||||
await uut.sendEmail(data)
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'formMessage\' must be a string!')
|
||||
assert.include(err.message, "Property 'formMessage' must be a string!")
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if <to> property is not provided', async () => {
|
||||
try {
|
||||
const data = {
|
||||
@@ -58,7 +61,7 @@ describe('NodeMailer', () => {
|
||||
await uut.sendEmail(data)
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'to\' must be a array!')
|
||||
assert.include(err.message, "Property 'to' must be a array!")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -89,13 +92,15 @@ describe('NodeMailer', () => {
|
||||
await uut.sendEmail(data)
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'subject\' must be a string!')
|
||||
assert.include(err.message, "Property 'subject' must be a string!")
|
||||
}
|
||||
})
|
||||
|
||||
it('should send email with default html data', async () => {
|
||||
try {
|
||||
sandbox.stub(uut.transporter, 'sendMail').resolves({ messageId: 'messageId' })
|
||||
sandbox
|
||||
.stub(uut.transporter, 'sendMail')
|
||||
.resolves({ messageId: 'messageId' })
|
||||
const data = {
|
||||
email: 'test@email.com',
|
||||
formMessage: 'test msg',
|
||||
@@ -109,9 +114,12 @@ describe('NodeMailer', () => {
|
||||
assert(false, 'Unexpected result')
|
||||
}
|
||||
})
|
||||
|
||||
it('should send email if htmlData is provided', async () => {
|
||||
try {
|
||||
sandbox.stub(uut.transporter, 'sendMail').resolves({ messageId: 'messageId' })
|
||||
sandbox
|
||||
.stub(uut.transporter, 'sendMail')
|
||||
.resolves({ messageId: 'messageId' })
|
||||
const data = {
|
||||
email: 'test@email.com',
|
||||
formMessage: 'test msg',
|
||||
@@ -128,31 +136,30 @@ describe('NodeMailer', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('validateEmailArray()', () => {
|
||||
it('should throw error if email list is not provided ', async () => {
|
||||
try {
|
||||
await uut.validateEmailArray()
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'emailList\' must be a array!')
|
||||
assert.include(err.message, "Property 'emailList' must be a array!")
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if email list is empty', async () => {
|
||||
try {
|
||||
const emailList = []
|
||||
await uut.validateEmailArray(emailList)
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'emailList\' cant be empty!')
|
||||
assert.include(err.message, "Property 'emailList' cant be empty!")
|
||||
}
|
||||
})
|
||||
|
||||
it('should return true ', async () => {
|
||||
try {
|
||||
const emailList = [
|
||||
'test@email.com',
|
||||
'simple@email.com'
|
||||
]
|
||||
const emailList = ['test@email.com', 'simple@email.com']
|
||||
const result = await uut.validateEmailArray(emailList)
|
||||
assert.isTrue(result)
|
||||
} catch (err) {
|
||||
@@ -160,23 +167,26 @@ describe('NodeMailer', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('getHtmlFromObject()', () => {
|
||||
it('should throw error if the input is not provided ', async () => {
|
||||
try {
|
||||
await uut.getHtmlFromObject()
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'objectData\' must be a object!')
|
||||
assert.include(err.message, "Property 'objectData' must be a object!")
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if the object is empty', async () => {
|
||||
try {
|
||||
await uut.getHtmlFromObject({})
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'subject\' must be a string!')
|
||||
assert.include(err.message, "Property 'subject' must be a string!")
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if "formMessage" property is not provided', async () => {
|
||||
try {
|
||||
const obj = {
|
||||
@@ -185,7 +195,7 @@ describe('NodeMailer', () => {
|
||||
await uut.getHtmlFromObject(obj)
|
||||
assert(false, 'Unexpected result')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Property \'formMessage\' must be a string!')
|
||||
assert.include(err.message, "Property 'formMessage' must be a string!")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -197,13 +207,16 @@ describe('NodeMailer', () => {
|
||||
value1: 'value1',
|
||||
value2: 'value2',
|
||||
value3: 'value3'
|
||||
|
||||
}
|
||||
const result = await uut.getHtmlFromObject(obj)
|
||||
assert.isString(result)
|
||||
assert.include(result, '<p>', 'expect html tag')
|
||||
assert.include(result, '</p>', 'expect html tag')
|
||||
assert.include(result, 'value1', 'Expect value 1 is included in the html')
|
||||
assert.include(
|
||||
result,
|
||||
'value1',
|
||||
'Expect value 1 is included in the html'
|
||||
)
|
||||
assert.include(result, 'value2', 'expect is included in the html')
|
||||
assert.include(result, 'value3', 'expect is included in the html')
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user