瀏覽代碼

:white_check_mark: Updated email test, adjusted profile route to not auth

brian_tests
tomit4 2 年之前
父節點
當前提交
fb63c0a468
共有 2 個檔案被更改,包括 26 行新增16 行删除
  1. 2
    1
      backend/lib/routes/profile/get.js
  2. 24
    15
      backend/tests/user-send-email.spec.js

+ 2
- 1
backend/lib/routes/profile/get.js 查看文件

28
     options: {
28
     options: {
29
         ...pluginConfig.docs,
29
         ...pluginConfig.docs,
30
         tags: ['api'],
30
         tags: ['api'],
31
-        auth: 'default_jwt',
31
+        // auth: 'default_jwt',
32
+        auth: false,
32
         cors: true,
33
         cors: true,
33
         handler: async function (request, h) {
34
         handler: async function (request, h) {
34
             const { profile_id } = request.params
35
             const { profile_id } = request.params

+ 24
- 15
backend/tests/user-send-email.spec.js 查看文件

6
  */
6
  */
7
 
7
 
8
 // Change email here to your actual email
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
 const test = require('ava')
12
 const test = require('ava')
12
 const { stub } = require('sinon')
13
 const { stub } = require('sinon')
16
 
17
 
17
 // Necessary Dependencies/Configurations for Brevo Transac Email
18
 // Necessary Dependencies/Configurations for Brevo Transac Email
18
 const crypto = require('crypto')
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
 apiKey.apiKey = process.env.BREVO_KEY
23
 apiKey.apiKey = process.env.BREVO_KEY
23
-const apiInstance = new SibApiV3Sdk.TransactionalEmailsApi()
24
+const sendSmtpEmail = new Brevo.SendSmtpEmail()
24
 
25
 
25
 // Existing activeSession to test against (should not match)
26
 // Existing activeSession to test against (should not match)
26
 const activeSessions = {
27
 const activeSessions = {
53
 }
54
 }
54
 
55
 
55
 test('path /send-email should send test transac email', async t => {
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
      * Create a new server and register services,
63
      * Create a new server and register services,
58
      * models and routes for testing
64
      * models and routes for testing
80
         }
86
         }
81
     }
87
     }
82
 
88
 
89
+    hashedSessionToken = Object.keys(activeSessions).find(hashedToken => {
90
+        return activeSessions[`${hashedToken}`].email === userCredentials.email
91
+    })
83
     /**
92
     /**
84
      * Sends a Transactional Email via Brevo
93
      * Sends a Transactional Email via Brevo
85
      * @ returns {Object}
94
      * @ returns {Object}
101
             emailWasRespondedTo: false,
110
             emailWasRespondedTo: false,
102
             accessToken: null,
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
             to: [
119
             to: [
106
                 {
120
                 {
107
                     email: userCredentials.email,
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
         return await apiInstance.sendTransacEmail(sendSmtpEmail).then(
129
         return await apiInstance.sendTransacEmail(sendSmtpEmail).then(
117
             data => {
130
             data => {
123
         )
136
         )
124
     }
137
     }
125
 
138
 
126
-    hashedSessionToken = Object.keys(activeSessions).find(hashedToken => {
127
-        return activeSessions[`${hashedToken}`].email === userCredentials.email
128
-    })
129
-
130
     stub(server.services()['userService'], 'emailSent').returns(
139
     stub(server.services()['userService'], 'emailSent').returns(
131
         await emailSent(userCredentials),
140
         await emailSent(userCredentials),
132
     )
141
     )

Loading…
取消
儲存