mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-18 22:07:32 +00:00
6e105f662e
* init for views (spooler, handler) * init for views (spooler, handler) * start view in management * granted project * implement granted project view * search granted projects * fix search column * update all projects on project change * search roles * filter org * project members * project grant members * fix tests * application view * project grant search * mock * test appendevents * test appendevents * Update internal/view/query.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/eventstore/spooler/spooler.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/view/query.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * merge request changes * Update internal/project/repository/view/model/application.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * merge request changes * Project view sql (#92) * sql and configs * error handling * sql start in eventstore * on error handling, config * read user on members * Update internal/project/repository/view/application_view.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/granted_project.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * return caos errors * Update internal/project/repository/view/model/granted_project_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_grant_member.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_grant_member_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_member.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_member_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_role.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_role_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * converter fix Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Silvan <silvan.reusser@gmail.com>
101 lines
4.2 KiB
Go
101 lines
4.2 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/project/model"
|
|
es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
|
"testing"
|
|
)
|
|
|
|
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", Sequence: 1, Type: es_model.ApplicationAdded, Data: mockAppData(&es_model.Application{Name: "AppName"})},
|
|
app: &ApplicationView{},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
{
|
|
name: "append changed app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationChanged, Data: mockAppData(&es_model.Application{Name: "AppNameChanged"})},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppNameChanged", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
{
|
|
name: "append deactivate app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationDeactivated},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_INACTIVE)},
|
|
},
|
|
{
|
|
name: "append reactivate app event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.ApplicationReactivated},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_INACTIVE)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
{
|
|
name: "append added oidc config event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.OIDCConfigAdded, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientID"})},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientID", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
{
|
|
name: "append changed oidc config event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: es_model.OIDCConfigAdded, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientIDChanged"})},
|
|
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", OIDCClientID: "clientID", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientIDChanged", State: int32(model.APPSTATE_ACTIVE)},
|
|
},
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|