mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
61 lines
2.2 KiB
Go
61 lines
2.2 KiB
Go
|
package model
|
||
|
|
||
|
import (
|
||
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||
|
"github.com/caos/zitadel/internal/usergrant/model"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestAppendGrantStateEvent(t *testing.T) {
|
||
|
type args struct {
|
||
|
existing *UserGrant
|
||
|
grant *UserGrantID
|
||
|
event *es_models.Event
|
||
|
state model.UserGrantState
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
result *UserGrant
|
||
|
}{
|
||
|
{
|
||
|
name: "append deactivate grant event",
|
||
|
args: args{
|
||
|
existing: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}},
|
||
|
grant: &UserGrantID{GrantID: "GrantID"},
|
||
|
event: &es_models.Event{},
|
||
|
state: model.USERGRANTSTATE_INACTIVE,
|
||
|
},
|
||
|
result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.USERGRANTSTATE_INACTIVE)},
|
||
|
},
|
||
|
{
|
||
|
name: "append reactivate grant event",
|
||
|
args: args{
|
||
|
existing: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}},
|
||
|
grant: &UserGrantID{GrantID: "GrantID"},
|
||
|
event: &es_models.Event{},
|
||
|
state: model.USERGRANTSTATE_ACTIVE,
|
||
|
},
|
||
|
result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.USERGRANTSTATE_ACTIVE)},
|
||
|
},
|
||
|
{
|
||
|
name: "append remove grant event",
|
||
|
args: args{
|
||
|
existing: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}},
|
||
|
grant: &UserGrantID{GrantID: "GrantID"},
|
||
|
event: &es_models.Event{},
|
||
|
state: model.USERGRANTSTATE_REMOVED,
|
||
|
},
|
||
|
result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.USERGRANTSTATE_REMOVED)},
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
tt.args.existing.appendGrantStateEvent(tt.args.state)
|
||
|
if tt.args.existing.State != tt.result.State {
|
||
|
t.Errorf("got wrong result: actual: %v, expected: %v ", tt.result.State, tt.args.existing.State)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|