fix: cascading changes for usergrants when managing projects / projectgrants (#3035)

This commit is contained in:
Livio Amstutz
2022-01-20 08:33:51 +01:00
committed by GitHub
parent eaaf76a6eb
commit 24aef8d16e
5 changed files with 161 additions and 5 deletions

View File

@@ -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) {