2024-03-27 15:29:50 +00:00
|
|
|
|
package tests
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "embed"
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-06-24 10:31:08 +00:00
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/clients"
|
2024-03-27 15:29:50 +00:00
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
2024-06-24 10:31:08 +00:00
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/senders"
|
2024-03-27 15:29:50 +00:00
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed mail/to_client.tmpl
|
|
|
|
|
var toClientTemplate string
|
|
|
|
|
|
|
|
|
|
//go:embed mail/reminder.tmpl
|
|
|
|
|
var reminderTemplate string
|
|
|
|
|
|
|
|
|
|
func TestProcessMessageToSMTP(t *testing.T) {
|
2024-06-24 10:31:08 +00:00
|
|
|
|
clientDeps := clients.Deps{
|
|
|
|
|
SmtpHost: "connect.mailclient.bz",
|
|
|
|
|
SmtpPort: "587",
|
|
|
|
|
SmtpSender: "skeris@mailing.pena.digital",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
ApiKey: "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
2024-06-17 15:23:43 +00:00
|
|
|
|
SmtpApiUrl: "https://api.smtp.bz/v1/smtp/send",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
FiberClient: &fiber.Client{},
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 10:31:08 +00:00
|
|
|
|
client := clients.NewSmtpClient(clientDeps)
|
2024-03-27 15:29:50 +00:00
|
|
|
|
|
2024-03-28 12:03:41 +00:00
|
|
|
|
recipient := "pashamullin2001@gmail.com"
|
2024-03-27 15:29:50 +00:00
|
|
|
|
subject := "Test"
|
|
|
|
|
|
2024-06-24 10:31:08 +00:00
|
|
|
|
data := senders.TemplateData{
|
2024-03-27 15:29:50 +00:00
|
|
|
|
QuizConfig: model.ResultInfo{
|
2024-03-28 12:03:41 +00:00
|
|
|
|
Theme: "<h1>Taemplste Quiz</h1>",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
},
|
|
|
|
|
AnswerContent: model.ResultContent{
|
2024-03-28 12:03:41 +00:00
|
|
|
|
Name: "<a>Pasha</a>",
|
|
|
|
|
Phone: "<div>+723456789<div",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
Email: "test@example.com",
|
|
|
|
|
//Adress: "chtoto tam",
|
2024-03-28 12:03:41 +00:00
|
|
|
|
Telegram: "<br>@test</br>",
|
|
|
|
|
Wechat: "<span>test_wechat</span>",
|
|
|
|
|
Viber: "<span><span>+723456789</span></span>",
|
|
|
|
|
Vk: "<body>test_vk<body>",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
Skype: "test_skype",
|
|
|
|
|
Whatsup: "test_whatsup",
|
|
|
|
|
Messenger: "test_messenger",
|
|
|
|
|
},
|
|
|
|
|
AllAnswers: []model.ResultAnswer{
|
2024-03-28 12:03:41 +00:00
|
|
|
|
{AnswerID: 1, QuestionID: 1, Content: "https://www.google.com/search?sca_esv=c51a80de1a7d45f0&sxsrf=ACQVn08xG-a0eH1Vds246-fONoSvvjzVMw:1707762485524&q=ku,n&tbm=isch&source=lnms&sa=X&ved=2ahUKEwi7ub2Ct6aEAxVVb_UHHQIQBVoQ0pQJegQIDRAB&biw=1536&bih=703&dpr=1.25#imgrc=0PWwTuuH2uBQ3M|html", CreatedAt: time.Now()},
|
|
|
|
|
{AnswerID: 2, QuestionID: 2, Content: "From a friend", CreatedAt: time.Now()},
|
|
|
|
|
{AnswerID: 3, QuestionID: 3, Content: "From a friend", CreatedAt: time.Now()},
|
|
|
|
|
{AnswerID: 4, QuestionID: 4, Content: `{"Image":"https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg","Description":"Gekon"}`, CreatedAt: time.Now()},
|
2024-03-27 15:29:50 +00:00
|
|
|
|
},
|
|
|
|
|
QuestionsMap: map[uint64]string{
|
2024-03-28 12:03:41 +00:00
|
|
|
|
1: "?",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
2: "How did you hear about us?",
|
2024-03-28 12:03:41 +00:00
|
|
|
|
3: "que 3",
|
|
|
|
|
4: "que 4",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
},
|
|
|
|
|
AnswerTime: time.Now().Format("Monday, 2 January 2006 г., 15:04 UTC-07:00"),
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 10:31:08 +00:00
|
|
|
|
mailSender := senders.NewMailLeadSender(client)
|
|
|
|
|
err := mailSender.SendMailWithAttachment(recipient, subject, toClientTemplate, data, nil)
|
2024-03-27 15:29:50 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Error sending email: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestProcessReminderToClient(t *testing.T) {
|
2024-06-24 10:31:08 +00:00
|
|
|
|
clientDeps := clients.Deps{
|
|
|
|
|
SmtpHost: "connect.mailclient.bz",
|
|
|
|
|
SmtpPort: "587",
|
|
|
|
|
SmtpSender: "skeris@mailing.pena.digital",
|
2024-03-27 15:29:50 +00:00
|
|
|
|
ApiKey: "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
|
|
|
|
FiberClient: &fiber.Client{},
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 10:31:08 +00:00
|
|
|
|
client := clients.NewSmtpClient(clientDeps)
|
2024-03-27 15:29:50 +00:00
|
|
|
|
|
|
|
|
|
recipient := "mullinp@internet.ru"
|
|
|
|
|
subject := "Test Reminder"
|
|
|
|
|
|
|
|
|
|
quizConfig := model.ResultInfo{
|
|
|
|
|
ReplName: "Test Quiz",
|
|
|
|
|
Reply: "mullinp@internet.ru",
|
|
|
|
|
Theme: "Reminder Theme",
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 10:31:08 +00:00
|
|
|
|
mailSender := senders.NewMailLeadSender(client)
|
|
|
|
|
|
|
|
|
|
err := mailSender.SendMailWithAttachment(recipient, subject, reminderTemplate, senders.TemplateData{
|
2024-03-27 15:29:50 +00:00
|
|
|
|
QuizConfig: quizConfig,
|
|
|
|
|
AnswerContent: model.ResultContent{},
|
|
|
|
|
AllAnswers: []model.ResultAnswer{},
|
|
|
|
|
QuestionsMap: nil,
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Error sending email: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 10:31:08 +00:00
|
|
|
|
//func TestProcessMessageToClient(t *testing.T) {
|
|
|
|
|
// smtpData := clients.Deps{
|
|
|
|
|
// SmtpHost: "connect.mailclient.bz",
|
|
|
|
|
// SmtpPort: "587",
|
|
|
|
|
// SmtpSender: "skeris@mailing.pena.digital",
|
|
|
|
|
// ApiKey: "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
|
|
|
|
// FiberClient: &fiber.Client{},
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// mailClient := clients.NewSmtpClient(smtpData)
|
|
|
|
|
// mailSender := senders.NewMailLeadSender(mailClient)
|
|
|
|
|
//
|
|
|
|
|
// deps := answerwc.DepsSendToClient{
|
|
|
|
|
// Redis: nil,
|
|
|
|
|
// Dal: nil,
|
|
|
|
|
// LeadSenders: []senders.LeadSender{mailSender},
|
|
|
|
|
// CustomerService: nil,
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// errChan := make(chan<- error)
|
|
|
|
|
//
|
|
|
|
|
// w := answerwc.NewSendToClient(deps, errChan)
|
|
|
|
|
//
|
|
|
|
|
// quizConfig := model.QuizConfig{
|
|
|
|
|
// Mailing: model.ResultInfo{
|
|
|
|
|
// Theme: faker.String(),
|
|
|
|
|
// },
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// questionsMap := map[uint64]string{
|
|
|
|
|
// 1: faker.String(),
|
|
|
|
|
// 2: faker.String(),
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// account := model.Account{
|
|
|
|
|
// Email: "pashamullin2001@gmail.com",
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// allAnswers := []model.ResultAnswer{
|
|
|
|
|
// {
|
|
|
|
|
// Content: `{"Image":"https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg","Description":"Gekon"}`,
|
|
|
|
|
// AnswerID: 1,
|
|
|
|
|
// QuestionID: 1,
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// AnswerID: 2,
|
|
|
|
|
// QuestionID: 2,
|
|
|
|
|
// },
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// answerContent := model.ResultContent{
|
|
|
|
|
// Name: "Pasha",
|
|
|
|
|
// Phone: "+723456789",
|
|
|
|
|
// Email: "test@example.com",
|
|
|
|
|
// //Adress: "chtoto tam",
|
|
|
|
|
// Telegram: "@test",
|
|
|
|
|
// Wechat: "test_wechat",
|
|
|
|
|
// Viber: "+723456789",
|
|
|
|
|
// Vk: "test_vk",
|
|
|
|
|
// Skype: "test_skype",
|
|
|
|
|
// Whatsup: "test_whatsup",
|
|
|
|
|
// Messenger: "test_messenger",
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// answerTime := time.Now()
|
|
|
|
|
//
|
|
|
|
|
// err := w.ProcessMessageToClient(quizConfig, questionsMap, account, allAnswers, answerContent, answerTime)
|
|
|
|
|
//
|
|
|
|
|
// assert.NoError(t, err)
|
|
|
|
|
//}
|