mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
1c5ecba42a
* feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: split request and response logic to handle the different context information * feat: split request and response logic to handle the different context information * fix: integration test * fix: import alias * fix: refactor execution package * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * docs: basic documentation for executions and targets * fix: change order for interceptors * fix: merge back origin/main * fix: change target definition command and query side (#7735) * fix: change target definition command and query side * fix: correct refactoring name changes * fix: correct refactoring name changes * fix: changing execution defintion with target list and type * fix: changing execution definition with target list and type * fix: add back search queries for target and include * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * docs: add example to actions v2 * docs: add example to actions v2 * fix: correct integration tests on query for executions * fix: add separate event for execution v2 as content changed * fix: add separate event for execution v2 as content changed * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * Update internal/api/grpc/server/middleware/execution_interceptor.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Elio Bischof <elio@zitadel.com>
491 lines
14 KiB
Go
491 lines
14 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/execution"
|
|
)
|
|
|
|
func TestCommandSide_executionsExistsWriteModel(t *testing.T) {
|
|
type fields struct {
|
|
eventstore func(t *testing.T) *eventstore.Eventstore
|
|
}
|
|
type args struct {
|
|
ctx context.Context
|
|
ids []string
|
|
resourceOwner string
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
res bool
|
|
}{
|
|
{
|
|
name: "execution, single",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "execution, single reset",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "execution, single before removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "execution, single removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution", "org1"),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "execution, multiple",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: true,
|
|
},
|
|
|
|
{
|
|
name: "execution, multiple, first removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "execution, multiple, second removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "execution, multiple, third removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "execution, multiple, before removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "execution, multiple, all removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: false,
|
|
},
|
|
|
|
{
|
|
name: "execution, multiple, two removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution1", "org1"),
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewSetEventV2(context.Background(),
|
|
execution.NewAggregate("execution3", "org1"),
|
|
[]*execution.Target{
|
|
{Type: domain.ExecutionTargetTypeTarget, Target: "target"},
|
|
{Type: domain.ExecutionTargetTypeInclude, Target: "include"},
|
|
},
|
|
),
|
|
),
|
|
eventFromEventPusher(
|
|
execution.NewRemovedEvent(context.Background(),
|
|
execution.NewAggregate("execution2", "org1"),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"execution1", "execution2", "execution3"},
|
|
},
|
|
res: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
c := &Commands{
|
|
eventstore: tt.fields.eventstore(t),
|
|
}
|
|
assert.Equal(t, tt.res, c.existsExecutionsByIDs(tt.args.ctx, tt.args.ids, tt.args.resourceOwner))
|
|
|
|
})
|
|
}
|
|
}
|