174 lines
4.4 KiB
Go
174 lines
4.4 KiB
Go
|
package tests
|
|||
|
|
|||
|
import (
|
|||
|
_ "embed"
|
|||
|
"github.com/gofiber/fiber/v2"
|
|||
|
"github.com/pioz/faker"
|
|||
|
"github.com/stretchr/testify/assert"
|
|||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
|||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/answerwc"
|
|||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/mailclient"
|
|||
|
"testing"
|
|||
|
"time"
|
|||
|
)
|
|||
|
|
|||
|
//go:embed mail/to_client.tmpl
|
|||
|
var toClientTemplate string
|
|||
|
|
|||
|
//go:embed mail/reminder.tmpl
|
|||
|
var reminderTemplate string
|
|||
|
|
|||
|
func TestProcessMessageToSMTP(t *testing.T) {
|
|||
|
clientDeps := mailclient.ClientDeps{
|
|||
|
Host: "connect.mailclient.bz",
|
|||
|
Port: "587",
|
|||
|
Sender: "skeris@mailing.pena.digital",
|
|||
|
Auth: &mailclient.PlainAuth{Username: "kotilion.95@gmail.com", Password: "vWwbCSg4bf0p"},
|
|||
|
ApiKey: "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
|||
|
FiberClient: &fiber.Client{},
|
|||
|
}
|
|||
|
|
|||
|
client := mailclient.NewClient(clientDeps)
|
|||
|
|
|||
|
recipient := "sadasdsadsadsafd.dasdsadasdad@mail.ru"
|
|||
|
subject := "Test"
|
|||
|
|
|||
|
data := mailclient.EmailTemplateData{
|
|||
|
QuizConfig: model.ResultInfo{
|
|||
|
Theme: "Taemplste Quiz",
|
|||
|
},
|
|||
|
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",
|
|||
|
},
|
|||
|
AllAnswers: []model.ResultAnswer{
|
|||
|
{QuestionID: 1, Content: "Pasha"},
|
|||
|
{QuestionID: 2, Content: "From a friend"},
|
|||
|
},
|
|||
|
QuestionsMap: map[uint64]string{
|
|||
|
1: "How did you hear about us?",
|
|||
|
2: "How did you hear about us?",
|
|||
|
},
|
|||
|
AnswerTime: time.Now().Format("Monday, 2 January 2006 г., 15:04 UTC-07:00"),
|
|||
|
}
|
|||
|
|
|||
|
err := client.SendMailWithAttachment(recipient, subject, toClientTemplate, data, nil)
|
|||
|
if err != nil {
|
|||
|
t.Errorf("Error sending email: %v", err)
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
func TestProcessReminderToClient(t *testing.T) {
|
|||
|
clientDeps := mailclient.ClientDeps{
|
|||
|
Host: "connect.mailclient.bz",
|
|||
|
Port: "587",
|
|||
|
Sender: "skeris@mailing.pena.digital",
|
|||
|
Auth: &mailclient.PlainAuth{Username: "kotilion.95@gmail.com", Password: "vWwbCSg4bf0p"},
|
|||
|
ApiKey: "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
|||
|
FiberClient: &fiber.Client{},
|
|||
|
}
|
|||
|
|
|||
|
client := mailclient.NewClient(clientDeps)
|
|||
|
|
|||
|
recipient := "mullinp@internet.ru"
|
|||
|
subject := "Test Reminder"
|
|||
|
|
|||
|
quizConfig := model.ResultInfo{
|
|||
|
ReplName: "Test Quiz",
|
|||
|
Reply: "mullinp@internet.ru",
|
|||
|
Theme: "Reminder Theme",
|
|||
|
}
|
|||
|
|
|||
|
err := client.SendMailWithAttachment(recipient, subject, reminderTemplate, mailclient.EmailTemplateData{
|
|||
|
QuizConfig: quizConfig,
|
|||
|
AnswerContent: model.ResultContent{},
|
|||
|
AllAnswers: []model.ResultAnswer{},
|
|||
|
QuestionsMap: nil,
|
|||
|
}, nil)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
t.Errorf("Error sending email: %v", err)
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
func TestProcessMessageToClient(t *testing.T) {
|
|||
|
|
|||
|
smtpData := mailclient.ClientDeps{
|
|||
|
Host: "connect.mailclient.bz",
|
|||
|
Port: "587",
|
|||
|
Sender: "skeris@mailing.pena.digital",
|
|||
|
Auth: &mailclient.PlainAuth{Username: "kotilion.95@gmail.com", Password: "vWwbCSg4bf0p"},
|
|||
|
ApiKey: "P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev",
|
|||
|
FiberClient: &fiber.Client{},
|
|||
|
}
|
|||
|
|
|||
|
mailClient := mailclient.NewClient(smtpData)
|
|||
|
|
|||
|
deps := answerwc.DepsSendToClient{
|
|||
|
Redis: nil,
|
|||
|
Dal: nil,
|
|||
|
MailClient: mailClient,
|
|||
|
}
|
|||
|
|
|||
|
errChan := make(chan<- error)
|
|||
|
|
|||
|
w := answerwc.NewSendToClient(deps, nil, 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)
|
|||
|
}
|