fix: Project grant fix (#2529)

* feat: add project resource owner serch query

* fix: project grant cascade changed reduce

* fix: add project removed tests
This commit is contained in:
Fabi 2021-10-19 10:38:21 +02:00 committed by GitHub
parent 1c26587a05
commit 48135daa84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 1 deletions

View File

@ -132,7 +132,7 @@ func (p *ProjectGrantProjection) reduceProjectGrantCascadeChanged(event eventsto
[]handler.Column{
handler.NewCol(ProjectGrantColumnChangeDate, e.CreationDate()),
handler.NewCol(ProjectGrantColumnSequence, e.Sequence()),
handler.NewCol(ProjectGrantColumnRoleKeys, e.RoleKeys),
handler.NewCol(ProjectGrantColumnRoleKeys, pq.StringArray(e.RoleKeys)),
},
[]handler.Condition{
handler.NewCond(ProjectGrantColumnGrantID, e.GrantID),

View File

@ -22,6 +22,33 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
reduce func(event eventstore.EventReader) (*handler.Statement, error)
want wantReduce
}{
{
name: "reduceProjectRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(project.ProjectRemovedType),
project.AggregateType,
nil,
), project.ProjectRemovedEventMapper),
},
reduce: (&ProjectGrantProjection{}).reduceProjectRemoved,
want: wantReduce{
projection: ProjectGrantProjectionTable,
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM zitadel.projections.project_grants WHERE (project_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
{
name: "reduceProjectGrantRemoved",
args: args{
@ -143,6 +170,37 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
},
},
},
{
name: "reduceProjectGrantCascadeChanged",
args: args{
event: getEvent(testEvent(
repository.EventType(project.GrantCascadeChangedType),
project.AggregateType,
[]byte(`{"grantId": "grant-id", "roleKeys": ["admin", "user"] }`),
), project.GrantCascadeChangedEventMapper),
},
reduce: (&ProjectGrantProjection{}).reduceProjectGrantCascadeChanged,
want: wantReduce{
projection: ProjectGrantProjectionTable,
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE zitadel.projections.project_grants SET (change_date, sequence, granted_role_keys) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
pq.StringArray{"admin", "user"},
"grant-id",
"agg-id",
},
},
},
},
},
},
{
name: "reduceProjectGrantAdded",
args: args{

View File

@ -20,6 +20,33 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
reduce func(event eventstore.EventReader) (*handler.Statement, error)
want wantReduce
}{
{
name: "reduceProjectRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(project.ProjectRemovedType),
project.AggregateType,
nil,
), project.ProjectRemovedEventMapper),
},
reduce: (&ProjectRoleProjection{}).reduceProjectRemoved,
want: wantReduce{
projection: ProjectRoleProjectionTable,
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM zitadel.projections.project_roles WHERE (project_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
{
name: "reduceProjectRoleRemoved",
args: args{