|
|
@@ -6,7 +6,8 @@
|
|
6
|
6
|
*/
|
|
7
|
7
|
|
|
8
|
8
|
// Change email here to your actual email
|
|
9
|
|
-// const email = 'myalias@myactualemail.com'
|
|
|
9
|
+let email = undefined
|
|
|
10
|
+// email = 'myalias@myactualemail.com'
|
|
10
|
11
|
|
|
11
|
12
|
const test = require('ava')
|
|
12
|
13
|
const { stub } = require('sinon')
|
|
|
@@ -16,11 +17,11 @@ const plugin = require('../lib/plugins/user.js')
|
|
16
|
17
|
|
|
17
|
18
|
// Necessary Dependencies/Configurations for Brevo Transac Email
|
|
18
|
19
|
const crypto = require('crypto')
|
|
19
|
|
-const SibApiV3Sdk = require('sib-api-v3-sdk')
|
|
20
|
|
-const defaultClient = SibApiV3Sdk.ApiClient.instance
|
|
21
|
|
-const apiKey = defaultClient.authentications['api-key']
|
|
|
20
|
+const Brevo = require('@getbrevo/brevo')
|
|
|
21
|
+const apiInstance = new Brevo.TransactionalEmailsApi()
|
|
|
22
|
+const apiKey = apiInstance.apiClient.authentications['api-key']
|
|
22
|
23
|
apiKey.apiKey = process.env.BREVO_KEY
|
|
23
|
|
-const apiInstance = new SibApiV3Sdk.TransactionalEmailsApi()
|
|
|
24
|
+const sendSmtpEmail = new Brevo.SendSmtpEmail()
|
|
24
|
25
|
|
|
25
|
26
|
// Existing activeSession to test against (should not match)
|
|
26
|
27
|
const activeSessions = {
|
|
|
@@ -53,6 +54,11 @@ const pathToTest = {
|
|
53
|
54
|
}
|
|
54
|
55
|
|
|
55
|
56
|
test('path /send-email should send test transac email', async t => {
|
|
|
57
|
+ /* If email is left undefined, simply pass the test */
|
|
|
58
|
+ if (!email) {
|
|
|
59
|
+ t.log('no actual email was given, bypassing test...')
|
|
|
60
|
+ return t.pass()
|
|
|
61
|
+ }
|
|
56
|
62
|
/**
|
|
57
|
63
|
* Create a new server and register services,
|
|
58
|
64
|
* models and routes for testing
|
|
|
@@ -80,6 +86,9 @@ test('path /send-email should send test transac email', async t => {
|
|
80
|
86
|
}
|
|
81
|
87
|
}
|
|
82
|
88
|
|
|
|
89
|
+ hashedSessionToken = Object.keys(activeSessions).find(hashedToken => {
|
|
|
90
|
+ return activeSessions[`${hashedToken}`].email === userCredentials.email
|
|
|
91
|
+ })
|
|
83
|
92
|
/**
|
|
84
|
93
|
* Sends a Transactional Email via Brevo
|
|
85
|
94
|
* @ returns {Object}
|
|
|
@@ -101,17 +110,21 @@ test('path /send-email should send test transac email', async t => {
|
|
101
|
110
|
emailWasRespondedTo: false,
|
|
102
|
111
|
accessToken: null,
|
|
103
|
112
|
}
|
|
104
|
|
- const sendSmtpEmail = {
|
|
|
113
|
+ sendSmtpEmail.sender = {
|
|
|
114
|
+ name: 'My Test Company',
|
|
|
115
|
+ email: 'mytestemail@email.com',
|
|
|
116
|
+ }
|
|
|
117
|
+ sendSmtpEmail.subject = 'My Test Company'
|
|
|
118
|
+ sendSmtpEmail = {
|
|
105
|
119
|
to: [
|
|
106
|
120
|
{
|
|
107
|
121
|
email: userCredentials.email,
|
|
108
|
122
|
},
|
|
109
|
123
|
],
|
|
110
|
|
- templateId: 1,
|
|
111
|
|
- params: {
|
|
112
|
|
- // TODO: Change this in production...
|
|
113
|
|
- link: `localhost:3000/verify/${hashedSessionToken}`,
|
|
114
|
|
- },
|
|
|
124
|
+ }
|
|
|
125
|
+ sendSmtpEmail.templateId = Number(process.env.BREVO_TEMPLATE_ID)
|
|
|
126
|
+ sendSmtpEmail.params = {
|
|
|
127
|
+ link: `${process.env.BREVO_LINK}/verify/${hashedSessionToken}`,
|
|
115
|
128
|
}
|
|
116
|
129
|
return await apiInstance.sendTransacEmail(sendSmtpEmail).then(
|
|
117
|
130
|
data => {
|
|
|
@@ -123,10 +136,6 @@ test('path /send-email should send test transac email', async t => {
|
|
123
|
136
|
)
|
|
124
|
137
|
}
|
|
125
|
138
|
|
|
126
|
|
- hashedSessionToken = Object.keys(activeSessions).find(hashedToken => {
|
|
127
|
|
- return activeSessions[`${hashedToken}`].email === userCredentials.email
|
|
128
|
|
- })
|
|
129
|
|
-
|
|
130
|
139
|
stub(server.services()['userService'], 'emailSent').returns(
|
|
131
|
140
|
await emailSent(userCredentials),
|
|
132
|
141
|
)
|