mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
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:
parent
1c26587a05
commit
48135daa84
@ -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),
|
||||
|
@ -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{
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user