mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-25 09:07:48 +00:00
b5564572bc
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
103 lines
4.2 KiB
Go
103 lines
4.2 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
"github.com/zitadel/zitadel/internal/project/model"
|
|
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
|
|
"github.com/zitadel/zitadel/internal/repository/project"
|
|
)
|
|
|
|
func mockAppData(app *es_model.Application) []byte {
|
|
data, _ := json.Marshal(app)
|
|
return data
|
|
}
|
|
|
|
func mockOIDCConfigData(config *es_model.OIDCConfig) []byte {
|
|
data, _ := json.Marshal(config)
|
|
return data
|
|
}
|
|
|
|
func TestApplicationAppendEvent(t *testing.T) {
|
|
type args struct {
|
|
event *es_models.Event
|
|
app *ApplicationView
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *ApplicationView
|
|
}{
|
|
{
|
|
name: "append added app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationAddedType, Data: mockAppData(&es_model.Application{Name: "AppName"})},
|
|
app: &ApplicationView{},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
|
|
},
|
|
{
|
|
name: "append changed app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationChangedType, Data: mockAppData(&es_model.Application{Name: "AppNameChanged"})},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppNameChanged", State: int32(model.AppStateActive)},
|
|
},
|
|
{
|
|
name: "append deactivate app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationDeactivatedType},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateInactive)},
|
|
},
|
|
{
|
|
name: "append reactivate app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationReactivatedType},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateInactive)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
|
|
},
|
|
{
|
|
name: "append added oidc config event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.OIDCConfigAddedType, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientID"})},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientID", State: int32(model.AppStateActive)},
|
|
},
|
|
{
|
|
name: "append changed oidc config event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.OIDCConfigAddedType, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientIDChanged"})},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", OIDCClientID: "clientID", State: int32(model.AppStateActive)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientIDChanged", State: int32(model.AppStateActive)},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.args.app.AppendEvent(tt.args.event)
|
|
if tt.args.app.ProjectID != tt.result.ProjectID {
|
|
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.app.ProjectID)
|
|
}
|
|
if tt.args.app.Name != tt.result.Name {
|
|
t.Errorf("got wrong result name: expected: %v, actual: %v ", tt.result.Name, tt.args.app.Name)
|
|
}
|
|
if tt.args.app.State != tt.result.State {
|
|
t.Errorf("got wrong result state: expected: %v, actual: %v ", tt.result.State, tt.args.app.State)
|
|
}
|
|
if tt.args.app.IsOIDC != tt.result.IsOIDC {
|
|
t.Errorf("got wrong result IsOIDC: expected: %v, actual: %v ", tt.result.IsOIDC, tt.args.app.IsOIDC)
|
|
}
|
|
if tt.args.app.OIDCClientID != tt.result.OIDCClientID {
|
|
t.Errorf("got wrong result OIDCClientID: expected: %v, actual: %v ", tt.result.OIDCClientID, tt.args.app.OIDCClientID)
|
|
}
|
|
})
|
|
}
|
|
}
|