diff --git a/internal/query/projection/idp_login_policy_link.go b/internal/query/projection/idp_login_policy_link.go index 8518c24ffe..183942d5f2 100644 --- a/internal/query/projection/idp_login_policy_link.go +++ b/internal/query/projection/idp_login_policy_link.go @@ -70,6 +70,10 @@ func (p *idpLoginPolicyLinkProjection) reducers() []handler.AggregateReducer { Event: org.LoginPolicyIDPProviderRemovedEventType, Reduce: p.reduceRemoved, }, + { + Event: org.LoginPolicyRemovedEventType, + Reduce: p.reducePolicyRemoved, + }, { Event: org.OrgRemovedEventType, Reduce: p.reduceOrgRemoved, @@ -206,3 +210,15 @@ func (p *idpLoginPolicyLinkProjection) reduceOrgRemoved(event eventstore.Event) }, ), nil } + +func (p *idpLoginPolicyLinkProjection) reducePolicyRemoved(event eventstore.Event) (*handler.Statement, error) { + e, ok := event.(*org.LoginPolicyRemovedEvent) + if !ok { + return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SF3dg", "reduce.wrong.event.type %s", org.LoginPolicyRemovedEventType) + } + return crdb.NewDeleteStatement(e, + []handler.Condition{ + handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, e.Aggregate().ID), + }, + ), nil +} diff --git a/internal/query/projection/idp_login_policy_link_test.go b/internal/query/projection/idp_login_policy_link_test.go index ae2e612f2e..197d35c10c 100644 --- a/internal/query/projection/idp_login_policy_link_test.go +++ b/internal/query/projection/idp_login_policy_link_test.go @@ -247,6 +247,33 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, }, + { + name: "reducePolicyRemoved", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.LoginPolicyRemovedEventType), + org.AggregateType, + nil, + ), org.LoginPolicyRemovedEventMapper), + }, + reduce: (&idpLoginPolicyLinkProjection{}).reducePolicyRemoved, + want: wantReduce{ + aggregateType: org.AggregateType, + sequence: 15, + previousSequence: 10, + projection: IDPLoginPolicyLinkTable, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (aggregate_id = $1)", + expectedArgs: []interface{}{ + "agg-id", + }, + }, + }, + }, + }, + }, { name: "org.IDPConfigRemovedEvent", args: args{