mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-06 19:36:41 +00:00
feat: e-mail templates (#1158)
* View definition added * Get templates and texts from the database. * Fill in texts in templates * Fill in texts in templates * Client API added * Weekly backup * Weekly backup * Daily backup * Weekly backup * Tests added * Corrections from merge branch * Fixes from pull request review
This commit is contained in:
134
internal/iam/repository/eventsourcing/model/mail_text_test.go
Normal file
134
internal/iam/repository/eventsourcing/model/mail_text_test.go
Normal file
@@ -0,0 +1,134 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
)
|
||||
|
||||
func TestAppendAddMailTextEvent(t *testing.T) {
|
||||
type args struct {
|
||||
iam *IAM
|
||||
mailText *MailText
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *IAM
|
||||
}{
|
||||
{
|
||||
name: "append add mailText event",
|
||||
args: args{
|
||||
iam: &IAM{},
|
||||
mailText: &MailText{
|
||||
MailTextType: "PasswordReset",
|
||||
Language: "DE"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &IAM{DefaultMailTexts: []*MailText{&MailText{
|
||||
MailTextType: "PasswordReset",
|
||||
Language: "DE"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mailText != nil {
|
||||
data, _ := json.Marshal(tt.args.mailText)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.iam.appendAddMailTextEvent(tt.args.event)
|
||||
if len(tt.args.iam.DefaultMailTexts) != 1 {
|
||||
t.Errorf("got wrong result should have one mailText actual: %v ", len(tt.args.iam.DefaultMailTexts))
|
||||
}
|
||||
if tt.args.iam.DefaultMailTexts[0] == tt.result.DefaultMailTexts[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.DefaultMailTexts[0], tt.args.iam.DefaultMailTexts[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeMailTextEvent(t *testing.T) {
|
||||
type args struct {
|
||||
iam *IAM
|
||||
mailText *MailText
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *IAM
|
||||
}{
|
||||
{
|
||||
name: "append change mailText event",
|
||||
args: args{
|
||||
iam: &IAM{DefaultMailTexts: []*MailText{&MailText{
|
||||
MailTextType: "PasswordReset",
|
||||
Language: "DE"}}},
|
||||
mailText: &MailText{
|
||||
MailTextType: "ChangedPasswordReset",
|
||||
Language: "DE"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &IAM{DefaultMailTexts: []*MailText{&MailText{
|
||||
MailTextType: "PasswordReset",
|
||||
Language: "ChangedDE"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mailText != nil {
|
||||
data, _ := json.Marshal(tt.args.mailText)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.iam.appendChangeMailTextEvent(tt.args.event)
|
||||
if len(tt.args.iam.DefaultMailTexts) != 1 {
|
||||
t.Errorf("got wrong result should have one mailText actual: %v ", len(tt.args.iam.DefaultMailTexts))
|
||||
}
|
||||
if tt.args.iam.DefaultMailTexts[0] == tt.result.DefaultMailTexts[0] {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.DefaultMailTexts[0], tt.args.iam.DefaultMailTexts[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendRemoveMailTextEvent(t *testing.T) {
|
||||
type args struct {
|
||||
iam *IAM
|
||||
mailText *MailText
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *IAM
|
||||
}{
|
||||
{
|
||||
name: "append remove mailText event",
|
||||
args: args{
|
||||
iam: &IAM{DefaultMailTexts: []*MailText{&MailText{
|
||||
MailTextType: "PasswordReset",
|
||||
Language: "DE",
|
||||
Subject: "Subject"}}},
|
||||
mailText: &MailText{
|
||||
MailTextType: "PasswordReset",
|
||||
Language: "DE"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &IAM{DefaultMailTexts: []*MailText{}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mailText != nil {
|
||||
data, _ := json.Marshal(tt.args.mailText)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.iam.appendRemoveMailTextEvent(tt.args.event)
|
||||
if len(tt.args.iam.DefaultMailTexts) != 0 {
|
||||
t.Errorf("got wrong result should have no mailText actual: %v ", len(tt.args.iam.DefaultMailTexts))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user