zitadel/internal/eventstore/models/search_query_test.go
Silvan fbeab4c582
Eventstore (#22)
* feat: eventstore repository

* fix: remove gorm

* version

* feat: pkg

* feat: eventstore without eventstore-lib

* rename files

* gnueg

* fix: add object

* fix: global model

* feat(eventstore): sdk

* fix(eventstore): search query

* fix(eventstore): rename app to eventstore

* delete empty test

* remove unused func

* merge master

* fix(eventstore): tests

* fix(models): delete unused struct

* feat(eventstore): implemented push events

* feat(eventstore): overwrite context data

* feat(types): SQL-config

* feat(eventstore): options to overwrite editor

* Update internal/eventstore/models/field.go

Co-Authored-By: livio-a <livio.a@gmail.com>

* fix(eventstore): code quality

* fix(eventstore): rename modifier* to editor*

* fix(eventstore): delete editor_org

Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
Co-authored-by: livio-a <livio.a@gmail.com>
2020-04-06 06:42:21 +02:00

60 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{&Filter{field: Field_AggregateID, operation: Operation_Equals, value: "hodor"}}},
want: &SearchQuery{Filters: []*Filter{&Filter{field: Field_AggregateID, operation: Operation_Equals, value: "hodor"}}},
},
{
name: "overwrite idFilter",
fields: fields{query: NewSearchQuery()},
args: args{filters: []*Filter{
&Filter{field: Field_AggregateID, operation: Operation_Equals, value: "hodor"},
&Filter{field: Field_AggregateID, operation: Operation_Equals, value: "ursli"},
}},
want: &SearchQuery{Filters: []*Filter{&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)
}
}
})
}
}