mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
fix: cascading changes for usergrants when managing projects / projectgrants (#3035)
This commit is contained in:
@@ -324,6 +324,62 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceRoleRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.RoleRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key"}`),
|
||||
), project.RoleRemovedEventMapper),
|
||||
},
|
||||
reduce: (&UserGrantProjection{}).reduceRoleRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
projection: UserGrantProjectionTable,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.user_grants SET (roles) = (array_remove(roles, $1)) WHERE (project_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"key",
|
||||
"agg-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceProjectGrantChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grantID", "roleKeys": ["key"]}`),
|
||||
), project.GrantChangedEventMapper),
|
||||
},
|
||||
reduce: (&UserGrantProjection{}).reduceProjectGrantChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
projection: UserGrantProjectionTable,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE zitadel.projections.user_grants SET (roles) = (SELECT ARRAY( SELECT UNNEST(roles) INTERSECT SELECT UNNEST ($1::STRING[]))) WHERE (grant_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
pq.StringArray{"key"},
|
||||
"grantID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user