2020-05-18 09:32:16 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
2020-09-24 09:38:28 +00:00
|
|
|
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
2020-05-18 09:32:16 +00:00
|
|
|
)
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func mockIamData(iam *IAM) []byte {
|
2020-05-18 09:32:16 +00:00
|
|
|
data, _ := json.Marshal(iam)
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProjectRoleAppendEvent(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
event *es_models.Event
|
2020-08-26 07:56:23 +00:00
|
|
|
iam *IAM
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2020-08-26 07:56:23 +00:00
|
|
|
result *IAM
|
2020-05-18 09:32:16 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "append set up start event",
|
|
|
|
args: args{
|
2020-08-26 07:56:23 +00:00
|
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: IAMSetupStarted, ResourceOwner: "OrgID"},
|
|
|
|
iam: &IAM{},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
2020-09-24 09:38:28 +00:00
|
|
|
result: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "append set up done event",
|
|
|
|
args: args{
|
2020-08-26 07:56:23 +00:00
|
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: IAMSetupDone, ResourceOwner: "OrgID"},
|
2020-09-24 09:38:28 +00:00
|
|
|
iam: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
2020-09-24 09:38:28 +00:00
|
|
|
result: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1, SetUpDone: Step1},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "append globalorg event",
|
|
|
|
args: args{
|
2020-08-26 07:56:23 +00:00
|
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: GlobalOrgSet, ResourceOwner: "OrgID", Data: mockIamData(&IAM{GlobalOrgID: "GlobalOrg"})},
|
2020-09-24 09:38:28 +00:00
|
|
|
iam: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
2020-09-24 09:38:28 +00:00
|
|
|
result: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1, GlobalOrgID: "GlobalOrg"},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "append iamproject event",
|
|
|
|
args: args{
|
2020-08-26 07:56:23 +00:00
|
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: IAMProjectSet, ResourceOwner: "OrgID", Data: mockIamData(&IAM{IAMProjectID: "IamProject"})},
|
2020-09-24 09:38:28 +00:00
|
|
|
iam: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
2020-09-24 09:38:28 +00:00
|
|
|
result: &IAM{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, SetUpStarted: Step1, IAMProjectID: "IamProject"},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
tt.args.iam.AppendEvent(tt.args.event)
|
|
|
|
if tt.args.iam.AggregateID != tt.result.AggregateID {
|
|
|
|
t.Errorf("got wrong result AggregateID: expected: %v, actual: %v ", tt.result.AggregateID, tt.args.iam.AggregateID)
|
|
|
|
}
|
|
|
|
if tt.args.iam.SetUpDone != tt.result.SetUpDone {
|
|
|
|
t.Errorf("got wrong result SetUpDone: expected: %v, actual: %v ", tt.result.SetUpDone, tt.args.iam.SetUpDone)
|
|
|
|
}
|
|
|
|
if tt.args.iam.GlobalOrgID != tt.result.GlobalOrgID {
|
|
|
|
t.Errorf("got wrong result GlobalOrgID: expected: %v, actual: %v ", tt.result.GlobalOrgID, tt.args.iam.GlobalOrgID)
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if tt.args.iam.IAMProjectID != tt.result.IAMProjectID {
|
|
|
|
t.Errorf("got wrong result IAMProjectID: expected: %v, actual: %v ", tt.result.IAMProjectID, tt.args.iam.IAMProjectID)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|