add render image if content have it

This commit is contained in:
Pavel 2024-03-27 18:29:50 +03:00
parent 1e625206d1
commit f0563c3c10
8 changed files with 940 additions and 6 deletions

@ -516,7 +516,7 @@
<tr>
<td style="color: #9a9aaf; font-size: 20px; font-style: normal; font-weight: 400; line-height: normal">
{{ .Content }}
{{ renderImage .Content }}
</td>
</tr>
</table>

@ -6,10 +6,10 @@ import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/themakers/hlog"
"html/template"
"mime/multipart"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"strings"
"text/template"
)
type ClientDeps struct {
@ -124,7 +124,7 @@ func (c *Client) Send(msg *Message) error {
}
func generateTextFromTemplate(data EmailTemplateData, tpl string) (string, error) {
t, err := template.New("email").Parse(tpl)
t, err := template.New("email").Funcs(tmplFuncs).Parse(tpl)
if err != nil {
return "", fmt.Errorf("error parsing template: %w", err)
}

@ -2,8 +2,11 @@ package mailclient
import (
"crypto/rand"
"encoding/json"
"fmt"
"html/template"
"io"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
)
type LineWriter struct {
@ -61,3 +64,18 @@ func randomBoundary() string {
}
return fmt.Sprintf("%x", buf[:])
}
var tmplFuncs = template.FuncMap{
"renderImage": RenderImage,
}
func RenderImage(content string) template.HTML {
var res model.ImageContent
err := json.Unmarshal([]byte(content), &res)
if err != nil {
return template.HTML(fmt.Sprintf("%s", template.HTMLEscapeString(content)))
}
tpl := template.HTML(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, res.Image))
fmt.Println(tpl)
return tpl
}

7
go.mod

@ -6,18 +6,21 @@ require (
github.com/go-redis/redis/v8 v8.11.5
github.com/gofiber/fiber/v2 v2.52.0
github.com/golang/protobuf v1.5.3
github.com/pioz/faker v1.7.3
github.com/skeris/appInit v1.0.2
github.com/stretchr/testify v1.8.4
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
github.com/twmb/franz-go v1.16.1
go.uber.org/zap v1.26.0
google.golang.org/grpc v1.61.1
google.golang.org/protobuf v1.32.0
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314133622-a34c0e2e5168
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240327143506-416edf5094db
)
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golang-migrate/migrate/v4 v4.17.0 // indirect
github.com/google/uuid v1.6.0 // indirect
@ -29,6 +32,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/pierrec/lz4/v4 v4.1.19 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.7.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
@ -40,6 +44,7 @@ require (
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d // indirect
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af // indirect
)

12
go.sum

@ -49,9 +49,12 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
@ -77,6 +80,8 @@ github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrB
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/pierrec/lz4/v4 v4.1.19 h1:tYLzDnjDXh9qIxSTKHwXwOYmm9d887Y7Y1ZkyXYHAN4=
github.com/pierrec/lz4/v4 v4.1.19/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pioz/faker v1.7.3 h1:Tez8Emuq0UN+/d6mo3a9m/9ZZ/zdfJk0c5RtRatrceM=
github.com/pioz/faker v1.7.3/go.mod h1:xSpay5w/oz1a6+ww0M3vfpe40pSIykeUPeWEc3TvVlc=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -90,6 +95,7 @@ github.com/skeris/appInit v1.0.2/go.mod h1:4ElEeXWVGzU3dlYq/eMWJ/U5hd+LKisc1z3+y
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf h1:TJJm6KcBssmbWzplF5lzixXl1RBAi/ViPs1GaSOkhwo=
@ -156,6 +162,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
@ -163,12 +170,13 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d h1:gbaDt35HMDqOK84WYmDIlXMI7rstUcRqNttaT6Kx1do=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314133622-a34c0e2e5168 h1:KYujnAq8IOdTe9QESIivXKeaBTt+e4jVN0FiWlKyggw=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314133622-a34c0e2e5168/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240327143506-416edf5094db h1:zSbTQEUxnZAhttiL9WkuX51qxHPEaXGm00Y+WlEnHug=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240327143506-416edf5094db/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=

193
tests/mail/reminder.tmpl Normal file

File diff suppressed because one or more lines are too long

537
tests/mail/to_client.tmpl Normal file

@ -0,0 +1,537 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
/* Сброс стилей */
body,
h1,
h2,
h3,
p,
div,
img,
button,
table,
th,
td {
margin: 0;
padding: 0;
border: 0;
font: inherit;
vertical-align: baseline;
}
body {
background-color: #f2f2f7;
font-family: Arial, sans-serif;
}
@media (max-width: 600px) {
h1 {
font-size: 25px !important;
}
h4 {
font-size: 20px !important;
}
}
</style>
</head>
<body style="background-color: #f2f2f7; font-family: Arial, sans-serif">
<table style="width: 100%; padding: 16px">
<tr>
<td>
<img class="image" style="width: 103px; height: 40px" src="https://storage.yandexcloud.net/squizimages/logo-email-squiz.png" />
</td>
<td>
<p style="text-align: end; color: #9a9aaf; font-size: 14px">Квиз для вашего бизнеса</p>
</td>
</tr>
<tr>
<td colspan="2" style="height: 100%">
<h1
style="
font-size: 30px;
font-weight: 600;
margin-bottom: 13px;
width: 100%;
margin: 0;
margin-bottom: 13px;
margin-top: 50px;
"
>
Поступила новая заявка с квиза “{{.QuizConfig.Theme}}”!
</h1>
</td>
</tr>
<tr>
<td colspan="2" style="height: 100%">
<p style="color: #9a9aaf; font-size: 20px; margin-bottom: 50px">
Время заявки: {{ .AnswerTime }}
</p>
</td>
</tr>
<tr>
<td colspan="2" style="height: 100%">
<a
style="
display: flex;
justify-content: center;
color: #f2f3f7;
text-align: center;
font-size: 18px;
font-style: normal;
font-weight: 400;
line-height: 24px;
border-radius: 8px;
border: 1px solid #7e2aea;
background: #7e2aea;
padding: 10px 43px;
max-height: 63px;
margin-bottom: 50px;
"
>
Посмотреть в личном кабинете
</a>
</td>
</tr>
<tr>
<td colspan="2" style="height: 100%">
<h1
style="font-size: 25px; font-weight: 600; margin-bottom: 15px; width: 100%; margin: 0; margin-bottom: 13px"
>
Контакты
</h1>
</td>
</tr>
<tr>
<td colspan="2" style="padding: 0">
<table
style="
background-color: #fff;
border-radius: 8px;
text-align: left;
max-width: 480px;
width: 100%;
padding: 16px;
margin-bottom: 30px;
"
>
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Имя
</th>
<td>
<p
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
margin-bottom: 15px;
"
>
{{ .AnswerContent.Name}}
</p>
</td>
</tr>
{{ if .AnswerContent.Email }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Email
</th>
<td style="word-break: break-word">
<p
style="
text-align: start;
color: #7e2aea;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
margin-bottom: 15px;
"
>
{{ .AnswerContent.Email }}
</p>
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Phone }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Телефон
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Phone }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Telegram }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Telegram
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Telegram }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Wechat }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Wechat
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Wechat }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Viber }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Viber
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Viber }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Vk }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Vk
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Vk }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Skype }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Skype
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Skype }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Whatsup }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Whatsup
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Whatsup }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Messenger }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Messenger
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Messenger }}
</td>
</tr>
{{ end }}
{{ if .AnswerContent.Address }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
Адрес
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ .AnswerContent.Address }}
</td>
</tr>
{{ end }}
{{ range $key, $value := .AnswerContent.Custom }}
<tr>
<th
style="
text-align: start;
color: #9a9aaf;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ $key }}
</th>
<td
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
"
>
{{ $value }}
</td>
</tr>
{{ end }}
</table>
</td>
</tr>
<tr>
<td colspan="2" style="height: 100%">
<h1
style="font-size: 25px; font-weight: 600; margin-bottom: 15px; width: 100%; margin: 0; margin-bottom: 13px"
>
Ответы
</h1>
</td>
</tr>
{{ range .AllAnswers }}
{{ if index $.QuestionsMap .AnswerID }}
<tr>
<td colspan="2" style="padding: 0">
<table
style="
background-color: #fff;
border-radius: 8px;
text-align: left;
max-width: 480px;
width: 100%;
padding: 16px;
margin-bottom: 15px;
"
>
<tr>
<th colspan="2">
<p
style="
text-align: start;
color: #4d4d4d;
font-size: 20px;
font-style: normal;
font-weight: 400;
line-height: normal;
margin-bottom: 10px;
"
>
{{ index $.QuestionsMap .AnswerID }}
</p>
</th>
</tr>
<tr>
<td style="color: #9a9aaf; font-size: 20px; font-style: normal; font-weight: 400; line-height: normal">
{{ renderImage .Content }}
</td>
</tr>
</table>
</td>
</tr>
{{ end }}
{{end}}
<tr>
<td colspan="2" style="text-align: center; padding: 0">
<a style="color: #7e2aea; font-size: 20px; font-style: normal; font-weight: 400; line-height: normal">
quiz.pena.digital
</a>
</td>
</tr>
</table>
</body>
</html>

173
tests/smtp_test.go Normal file

@ -0,0 +1,173 @@
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)
}