mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
2731099db3
* feat: add events for execution * feat: add events for execution and command side * feat: add events for execution and command side * feat: add api endpoints for set and delete executions with integration tests * feat: add integration and unit tests and more existence checks * feat: add integration and unit tests and more existence checks * feat: unit tests for includes in executions * feat: integration tests for includes in executions * fix: linting * fix: update internal/api/api.go Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> * fix: update internal/command/command.go Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> * fix: apply suggestions from code review Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> * fix: change api return * fix: change aggregateID with prefix of execution type and add to documentation * fix: change body in proto for documentation and correct linting * fix: changed existing check to single query in separate writemodel * fix: linter changes and list endpoints for conditions in executions * fix: remove writemodel query on exeuction set as state before is irrelevant * fix: testing for exists write models and correction * fix: translations for errors and event types --------- Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
331 lines
6.9 KiB
Go
331 lines
6.9 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/target"
|
|
)
|
|
|
|
func targetAddEvent(aggID, resourceOwner string) *target.AddedEvent {
|
|
return target.NewAddedEvent(context.Background(),
|
|
target.NewAggregate(aggID, resourceOwner),
|
|
"name",
|
|
domain.TargetTypeWebhook,
|
|
"https://example.com",
|
|
time.Second,
|
|
false,
|
|
false,
|
|
)
|
|
}
|
|
|
|
func targetRemoveEvent(aggID, resourceOwner string) *target.RemovedEvent {
|
|
return target.NewRemovedEvent(context.Background(),
|
|
target.NewAggregate(aggID, resourceOwner),
|
|
"name",
|
|
)
|
|
}
|
|
|
|
func TestCommandSide_targetsExistsWriteModel(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: "target, single",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "target, single reset",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
|
|
targetAddEvent("target", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "target, single before removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "target, single removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "target, multiple",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "target, multiple, first removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "target, multiple, second removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "target, multiple, third removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
res: false,
|
|
},
|
|
{
|
|
name: "target, multiple, before removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
res: true,
|
|
},
|
|
{
|
|
name: "target, multiple, all removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target3", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
res: false,
|
|
},
|
|
|
|
{
|
|
name: "target, multiple, two removed",
|
|
fields: fields{
|
|
eventstore: expectEventstore(
|
|
expectFilter(
|
|
eventFromEventPusher(
|
|
targetAddEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target1", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target2", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetAddEvent("target3", "org1"),
|
|
),
|
|
eventFromEventPusher(
|
|
targetRemoveEvent("target2", "org1"),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
args: args{
|
|
ctx: context.Background(),
|
|
ids: []string{"target1", "target2", "target3"},
|
|
},
|
|
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.existsTargetsByIDs(tt.args.ctx, tt.args.ids, tt.args.resourceOwner))
|
|
|
|
})
|
|
}
|
|
}
|