mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
04fc59f538
# Which Problems Are Solved If there is no custom text given, the call ends in an internal error as no events have to be pushed. # How the Problems Are Solved If no events have to be pushed, no trying to push an empty list of events. # Additional Changes No additional changes. # Additional Context Closes #6954
198 lines
4.8 KiB
Go
198 lines
4.8 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/text/language"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
|
type fields struct {
|
|
eventstore *eventstore.Eventstore
|
|
}
|
|
type args struct {
|
|
ctx context.Context
|
|
instanceID string
|
|
config *domain.CustomMessageText
|
|
}
|
|
type res struct {
|
|
want *domain.ObjectDetails
|
|
err func(error) bool
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
res res
|
|
}{
|
|
{
|
|
name: "empty message type, error",
|
|
fields: fields{
|
|
eventstore: eventstoreExpect(t),
|
|
},
|
|
args: args{
|
|
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
|
config: &domain.CustomMessageText{
|
|
Language: AllowedLanguage,
|
|
},
|
|
},
|
|
res: res{
|
|
err: zerrors.IsErrorInvalidArgument,
|
|
},
|
|
},
|
|
{
|
|
name: "empty custom message text, success",
|
|
fields: fields{
|
|
eventstore: eventstoreExpect(
|
|
t,
|
|
expectFilter(),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
|
config: &domain.CustomMessageText{
|
|
MessageTextType: "Some type", // TODO: check the type!
|
|
Language: AllowedLanguage,
|
|
},
|
|
},
|
|
res: res{
|
|
want: &domain.ObjectDetails{
|
|
ResourceOwner: "INSTANCE",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "undefined language, error",
|
|
fields: fields{
|
|
eventstore: eventstoreExpect(t),
|
|
},
|
|
args: args{
|
|
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
|
config: &domain.CustomMessageText{},
|
|
},
|
|
res: res{
|
|
err: zerrors.IsErrorInvalidArgument,
|
|
},
|
|
},
|
|
{
|
|
name: "unsupported language, error",
|
|
fields: fields{
|
|
eventstore: eventstoreExpect(t),
|
|
},
|
|
args: args{
|
|
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
|
config: &domain.CustomMessageText{
|
|
Language: UnsupportedLanguage,
|
|
},
|
|
},
|
|
res: res{
|
|
err: zerrors.IsErrorInvalidArgument,
|
|
},
|
|
},
|
|
{
|
|
name: "custom text set all fields, ok",
|
|
fields: fields{
|
|
eventstore: eventstoreExpect(
|
|
t,
|
|
expectFilter(),
|
|
expectPush(
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessageGreeting,
|
|
"Greeting",
|
|
language.English,
|
|
),
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessageSubject,
|
|
"Subject",
|
|
language.English,
|
|
),
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessageTitle,
|
|
"Title",
|
|
language.English,
|
|
),
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessagePreHeader,
|
|
"PreHeader",
|
|
language.English,
|
|
),
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessageText,
|
|
"Text",
|
|
language.English,
|
|
),
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessageButtonText,
|
|
"ButtonText",
|
|
language.English,
|
|
),
|
|
instance.NewCustomTextSetEvent(context.Background(),
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
"Template",
|
|
domain.MessageFooterText,
|
|
"Footer",
|
|
language.English,
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
|
instanceID: "INSTANCE",
|
|
config: &domain.CustomMessageText{
|
|
MessageTextType: "Template",
|
|
Language: language.English,
|
|
Greeting: "Greeting",
|
|
Subject: "Subject",
|
|
Title: "Title",
|
|
PreHeader: "PreHeader",
|
|
Text: "Text",
|
|
ButtonText: "ButtonText",
|
|
FooterText: "Footer",
|
|
},
|
|
},
|
|
res: res{
|
|
want: &domain.ObjectDetails{
|
|
ResourceOwner: "INSTANCE",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
r := &Commands{
|
|
eventstore: tt.fields.eventstore,
|
|
}
|
|
got, err := r.SetDefaultMessageText(tt.args.ctx, tt.args.instanceID, tt.args.config)
|
|
if tt.res.err == nil {
|
|
assert.NoError(t, err)
|
|
}
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
t.Errorf("got wrong err: %v ", err)
|
|
t.FailNow()
|
|
}
|
|
assert.Equal(t, tt.res.want, got)
|
|
})
|
|
}
|
|
}
|