mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
33a4802425
* start org * refactor(eventstore): filter in sql for querier * feat(eventstore): Aggregate precondition preconditions are checked right before insert. Insert is still transaction save * feat(eventstore): check preconditions in repository * test(eventstore): test precondition in models * test(eventstore): precondition-tests * refactor(eventstore): querier as type * fix(precondition): rename validation from precondition to validation * test(eventstore): isErr func instead of wantErr bool * fix: delete org files * remove comment Co-authored-by: Livio Amstutz <livio.a@gmail.com>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package models
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSearchQuery_setFilter(t *testing.T) {
|
|
type fields struct {
|
|
query *SearchQuery
|
|
}
|
|
type args struct {
|
|
filters []*Filter
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
want *SearchQuery
|
|
}{
|
|
{
|
|
name: "set idFilter",
|
|
fields: fields{query: NewSearchQuery()},
|
|
args: args{filters: []*Filter{
|
|
{field: Field_AggregateID, operation: Operation_Equals, value: "hodor"},
|
|
}},
|
|
want: &SearchQuery{Filters: []*Filter{
|
|
{field: Field_AggregateID, operation: Operation_Equals, value: "hodor"},
|
|
}},
|
|
},
|
|
{
|
|
name: "overwrite idFilter",
|
|
fields: fields{query: NewSearchQuery()},
|
|
args: args{filters: []*Filter{
|
|
{field: Field_AggregateID, operation: Operation_Equals, value: "hodor"},
|
|
{field: Field_AggregateID, operation: Operation_Equals, value: "ursli"},
|
|
}},
|
|
want: &SearchQuery{Filters: []*Filter{
|
|
{field: Field_AggregateID, operation: Operation_Equals, value: "ursli"},
|
|
}},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tt.fields.query
|
|
for _, filter := range tt.args.filters {
|
|
got = got.setFilter(filter)
|
|
}
|
|
for _, wantFilter := range tt.want.Filters {
|
|
found := false
|
|
for _, gotFilter := range got.Filters {
|
|
if gotFilter.field == wantFilter.field {
|
|
found = true
|
|
if !reflect.DeepEqual(wantFilter, gotFilter) {
|
|
t.Errorf("filter not as expected: want: %v got %v", wantFilter, gotFilter)
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("filter field %v not found", wantFilter.field)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|