mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
91 lines
2.6 KiB
Go
91 lines
2.6 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
)
|
|
|
|
func TestAppendExternalIDPAddedEvent(t *testing.T) {
|
|
type args struct {
|
|
user *Human
|
|
externalIDP *ExternalIDP
|
|
event *es_models.Event
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *Human
|
|
}{
|
|
{
|
|
name: "append external idp added event",
|
|
args: args{
|
|
user: &Human{},
|
|
externalIDP: &ExternalIDP{IDPConfigID: "IDPConfigID", UserID: "UserID", DisplayName: "DisplayName"},
|
|
event: &es_models.Event{},
|
|
},
|
|
result: &Human{ExternalIDPs: []*ExternalIDP{{IDPConfigID: "IDPConfigID", UserID: "UserID", DisplayName: "DisplayName"}}},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.args.externalIDP != nil {
|
|
data, _ := json.Marshal(tt.args.externalIDP)
|
|
tt.args.event.Data = data
|
|
}
|
|
tt.args.user.appendExternalIDPAddedEvent(tt.args.event)
|
|
if len(tt.args.user.ExternalIDPs) == 0 {
|
|
t.Error("got wrong result expected external idps on user ")
|
|
}
|
|
if tt.args.user.ExternalIDPs[0].UserID != tt.result.ExternalIDPs[0].UserID {
|
|
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.ExternalIDPs[0].UserID, tt.args.user.ExternalIDPs[0].UserID)
|
|
}
|
|
if tt.args.user.ExternalIDPs[0].IDPConfigID != tt.result.ExternalIDPs[0].IDPConfigID {
|
|
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.ExternalIDPs[0].IDPConfigID, tt.args.user.ExternalIDPs[0].IDPConfigID)
|
|
}
|
|
if tt.args.user.ExternalIDPs[0].DisplayName != tt.result.ExternalIDPs[0].DisplayName {
|
|
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.ExternalIDPs[0].DisplayName, tt.args.user.ExternalIDPs[0].IDPConfigID)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendExternalIDPRemovedEvent(t *testing.T) {
|
|
type args struct {
|
|
user *Human
|
|
externalIDP *ExternalIDP
|
|
event *es_models.Event
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *Human
|
|
}{
|
|
{
|
|
name: "append external idp removed event",
|
|
args: args{
|
|
user: &Human{
|
|
ExternalIDPs: []*ExternalIDP{
|
|
{IDPConfigID: "IDPConfigID", UserID: "UserID", DisplayName: "DisplayName"},
|
|
}},
|
|
externalIDP: &ExternalIDP{UserID: "UserID"},
|
|
event: &es_models.Event{},
|
|
},
|
|
result: &Human{},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.args.externalIDP != nil {
|
|
data, _ := json.Marshal(tt.args.externalIDP)
|
|
tt.args.event.Data = data
|
|
}
|
|
tt.args.user.appendExternalIDPRemovedEvent(tt.args.event)
|
|
if len(tt.args.user.ExternalIDPs) != 0 {
|
|
t.Error("got wrong result expected 0 external idps on user ")
|
|
}
|
|
})
|
|
}
|
|
}
|