#node.js #jestjs #sendinblue
Вопрос:
//account.js
const SibApiV3Sdk = require('sib-api-v3-sdk')
const defaultClient = SibApiV3Sdk.ApiClient.instance
const apiKey = defaultClient.authentications['api-key'].apiKey
apiKey.apiKey = process.env.SIB_API_KEY
const sendWelcomeEmail = (email, name) => {
new SibApiV3Sdk.TransactionalEmailsApi().sendTransacEmail(
{
"subject": "Hello Dear",
"sender": { "email": "hi@example.com" , "name": "Hi" },
"replyTo": { "email": "hello@example.com" , "name": "Hello" },
"to": [{ name , email}],
"htmlContent": `<html><body> Hello ${name}. Let me know how you get along with the app.</body></html>`
}
)
}
const sendCancelationEmail = (email, name) => {
new SibApiV3Sdk.TransactionalEmailsApi().sendTransacEmail(
{
"subject": `Goodbye ${name}!`,
"sender": { "email": "hi@example.com" , "name": "Hi" },
"replyTo": { "email": "hello@example.com" , "name": "Hello" },
"to": [{name , email}],
"htmlContent": `<html><body> Goodbye ${name}. Is there anything we could have done to kept you on board? Hope to see you soon. `
})
}
module.exports = {
sendWelcomeEmail,
sendCancelationEmail
}
// sib-api-v3-sdk.js from __mocks__ directory
module.exports = {
ApiClient: ''
}
Когда я выполняю команду, я получаю
Не удалось запустить набор тестов
TypeError: Cannot read property 'authentications' of undefined
> 39 | const apiKey = defaultClient.authentications['api-key'].apiKey
40 | ^
41 | apiKey.apiKey = process.env.SIB_API_KEY
at Object.<anonymous> (src/emails/account.js:39:30)
at Object.<anonymous> (src/routers/user.js:6:53)
at Object.<anonymous> (src/app.js:3:20)
at Object.<anonymous> (tests/user.test.js:4:13)