zitadel/internal/project/repository/view/model/project_member_test.go
Florian Forster fa9f581d56
chore(v2): move to new org (#3499)
* chore: move to new org

* logging

* fix: org rename caos -> zitadel

Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
2022-04-26 23:01:45 +00:00

62 lines
2.2 KiB
Go

package model
import (
"encoding/json"
"reflect"
"testing"
"github.com/lib/pq"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
"github.com/zitadel/zitadel/internal/repository/project"
)
func mockProjectMemberData(member *es_model.ProjectMember) []byte {
data, _ := json.Marshal(member)
return data
}
func TestProjectMemberAppendEvent(t *testing.T) {
type args struct {
event *es_models.Event
member *ProjectMemberView
}
tests := []struct {
name string
args args
result *ProjectMemberView
}{
{
name: "append added member event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_models.EventType(project.MemberAddedType), ResourceOwner: "OrgID", Data: mockProjectMemberData(&es_model.ProjectMember{UserID: "UserID", Roles: pq.StringArray{"Role"}})},
member: &ProjectMemberView{},
},
result: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: pq.StringArray{"Role"}},
},
{
name: "append changed member event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_models.EventType(project.MemberAddedType), ResourceOwner: "OrgID", Data: mockProjectMemberData(&es_model.ProjectMember{UserID: "UserID", Roles: pq.StringArray{"RoleChanged"}})},
member: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: pq.StringArray{"Role"}},
},
result: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: pq.StringArray{"RoleChanged"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.member.AppendEvent(tt.args.event)
if tt.args.member.ProjectID != tt.result.ProjectID {
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.member.ProjectID)
}
if tt.args.member.UserID != tt.result.UserID {
t.Errorf("got wrong result userID: expected: %v, actual: %v ", tt.result.UserID, tt.args.member.UserID)
}
if !reflect.DeepEqual(tt.args.member.Roles, tt.result.Roles) {
t.Errorf("got wrong result Roles: expected: %v, actual: %v ", tt.result.Roles, tt.args.member.Roles)
}
})
}
}