mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
fbeab4c582
* 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>
174 lines
4.1 KiB
Go
174 lines
4.1 KiB
Go
package models
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestAggregate_AppendEvent(t *testing.T) {
|
|
type fields struct {
|
|
aggregate *Aggregate
|
|
}
|
|
type args struct {
|
|
typ EventType
|
|
payload interface{}
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
want *Aggregate
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no event type error",
|
|
fields: fields{aggregate: &Aggregate{}},
|
|
args: args{},
|
|
want: &Aggregate{},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid payload error",
|
|
fields: fields{aggregate: &Aggregate{}},
|
|
args: args{typ: "user", payload: 134},
|
|
want: &Aggregate{},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "event added",
|
|
fields: fields{aggregate: &Aggregate{Events: []*Event{}}},
|
|
args: args{typ: "user.deactivated"},
|
|
want: &Aggregate{Events: []*Event{&Event{Type: "user.deactivated"}}},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "event added",
|
|
fields: fields{aggregate: &Aggregate{Events: []*Event{&Event{}}}},
|
|
args: args{typ: "user.deactivated"},
|
|
want: &Aggregate{Events: []*Event{&Event{}, &Event{Type: "user.deactivated"}}},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := tt.fields.aggregate.AppendEvent(tt.args.typ, tt.args.payload)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("Aggregate.AppendEvent() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if len(tt.fields.aggregate.Events) != len(got.Events) {
|
|
t.Errorf("events len should be %d but was %d", len(tt.fields.aggregate.Events), len(got.Events))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAggregate_Validate(t *testing.T) {
|
|
type fields struct {
|
|
aggregate *Aggregate
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "aggregate nil error",
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "aggregate empty error",
|
|
wantErr: true,
|
|
fields: fields{aggregate: &Aggregate{}},
|
|
},
|
|
{
|
|
name: "no id error",
|
|
wantErr: true,
|
|
fields: fields{aggregate: &Aggregate{
|
|
typ: "user",
|
|
version: "v1.0.0",
|
|
editorService: "svc",
|
|
editorUser: "hodor",
|
|
resourceOwner: "org",
|
|
latestSequence: 5,
|
|
Events: []*Event{&Event{
|
|
AggregateType: "user",
|
|
AggregateVersion: "v1.0.0",
|
|
EditorService: "management",
|
|
EditorUser: "hodor",
|
|
ResourceOwner: "org",
|
|
Type: "born",
|
|
}},
|
|
}},
|
|
},
|
|
{
|
|
name: "no type error",
|
|
wantErr: true,
|
|
fields: fields{aggregate: &Aggregate{
|
|
id: "aggID",
|
|
version: "v1.0.0",
|
|
editorService: "svc",
|
|
editorUser: "hodor",
|
|
resourceOwner: "org",
|
|
latestSequence: 5,
|
|
Events: []*Event{&Event{
|
|
AggregateID: "hodor",
|
|
AggregateVersion: "v1.0.0",
|
|
EditorService: "management",
|
|
EditorUser: "hodor",
|
|
ResourceOwner: "org",
|
|
Type: "born",
|
|
}},
|
|
}},
|
|
},
|
|
{
|
|
name: "invalid version error",
|
|
wantErr: true,
|
|
fields: fields{aggregate: &Aggregate{
|
|
id: "aggID",
|
|
typ: "user",
|
|
editorService: "svc",
|
|
editorUser: "hodor",
|
|
resourceOwner: "org",
|
|
latestSequence: 5,
|
|
Events: []*Event{&Event{
|
|
AggregateID: "hodor",
|
|
AggregateType: "user",
|
|
EditorService: "management",
|
|
EditorUser: "hodor",
|
|
ResourceOwner: "org",
|
|
Type: "born",
|
|
}},
|
|
}},
|
|
},
|
|
{
|
|
name: "validation ok",
|
|
wantErr: false,
|
|
fields: fields{aggregate: &Aggregate{
|
|
id: "aggID",
|
|
typ: "user",
|
|
version: "v1.0.0",
|
|
editorService: "svc",
|
|
editorUser: "hodor",
|
|
resourceOwner: "org",
|
|
latestSequence: 5,
|
|
Events: []*Event{&Event{
|
|
AggregateID: "hodor",
|
|
AggregateType: "user",
|
|
AggregateVersion: "v1.0.0",
|
|
EditorService: "management",
|
|
EditorUser: "hodor",
|
|
ResourceOwner: "org",
|
|
Type: "born",
|
|
}},
|
|
}},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := tt.fields.aggregate.Validate(); (err != nil) != tt.wantErr {
|
|
t.Errorf("Aggregate.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|