mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-19 22:37:35 +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>
214 lines
5.5 KiB
Go
214 lines
5.5 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/project/model"
|
|
"testing"
|
|
)
|
|
|
|
func TestProjectChanges(t *testing.T) {
|
|
type args struct {
|
|
existing *Project
|
|
new *Project
|
|
}
|
|
type res struct {
|
|
changesLen int
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
res res
|
|
}{
|
|
{
|
|
name: "project name changes",
|
|
args: args{
|
|
existing: &Project{Name: "Name"},
|
|
new: &Project{Name: "NameChanged"},
|
|
},
|
|
res: res{
|
|
changesLen: 1,
|
|
},
|
|
},
|
|
{
|
|
name: "no changes",
|
|
args: args{
|
|
existing: &Project{Name: "Name"},
|
|
new: &Project{Name: "Name"},
|
|
},
|
|
res: res{
|
|
changesLen: 0,
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
changes := tt.args.existing.Changes(tt.args.new)
|
|
if len(changes) != tt.res.changesLen {
|
|
t.Errorf("got wrong changes len: expected: %v, actual: %v ", tt.res.changesLen, len(changes))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestProjectFromEvents(t *testing.T) {
|
|
type args struct {
|
|
event []*es_models.Event
|
|
project *Project
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *Project
|
|
}{
|
|
{
|
|
name: "project from events, ok",
|
|
args: args{
|
|
event: []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
|
},
|
|
project: &Project{Name: "ProjectName"},
|
|
},
|
|
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE), Name: "ProjectName"},
|
|
},
|
|
{
|
|
name: "project from events, nil project",
|
|
args: args{
|
|
event: []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
|
},
|
|
project: nil,
|
|
},
|
|
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE)},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.args.project != nil {
|
|
data, _ := json.Marshal(tt.args.project)
|
|
tt.args.event[0].Data = data
|
|
}
|
|
result, _ := ProjectFromEvents(tt.args.project, tt.args.event...)
|
|
if result.Name != tt.result.Name {
|
|
t.Errorf("got wrong result name: expected: %v, actual: %v ", tt.result.Name, result.Name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendEvent(t *testing.T) {
|
|
type args struct {
|
|
event *es_models.Event
|
|
project *Project
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *Project
|
|
}{
|
|
{
|
|
name: "append added event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
|
project: &Project{Name: "ProjectName"},
|
|
},
|
|
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE), Name: "ProjectName"},
|
|
},
|
|
{
|
|
name: "append change event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectChanged},
|
|
project: &Project{Name: "ProjectName"},
|
|
},
|
|
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE), Name: "ProjectName"},
|
|
},
|
|
{
|
|
name: "append deactivate event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectDeactivated},
|
|
},
|
|
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_INACTIVE)},
|
|
},
|
|
{
|
|
name: "append reactivate event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectReactivated},
|
|
},
|
|
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.PROJECTSTATE_ACTIVE)},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.args.project != nil {
|
|
data, _ := json.Marshal(tt.args.project)
|
|
tt.args.event.Data = data
|
|
}
|
|
result := new(Project)
|
|
result.AppendEvent(tt.args.event)
|
|
if result.State != tt.result.State {
|
|
t.Errorf("got wrong result state: expected: %v, actual: %v ", tt.result.State, result.State)
|
|
}
|
|
if result.Name != tt.result.Name {
|
|
t.Errorf("got wrong result name: expected: %v, actual: %v ", tt.result.Name, result.Name)
|
|
}
|
|
if result.ObjectRoot.AggregateID != tt.result.ObjectRoot.AggregateID {
|
|
t.Errorf("got wrong result id: expected: %v, actual: %v ", tt.result.ObjectRoot.AggregateID, result.ObjectRoot.AggregateID)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendDeactivatedEvent(t *testing.T) {
|
|
type args struct {
|
|
project *Project
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *Project
|
|
}{
|
|
{
|
|
name: "append reactivate event",
|
|
args: args{
|
|
project: &Project{},
|
|
},
|
|
result: &Project{State: int32(model.PROJECTSTATE_INACTIVE)},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.args.project.appendDeactivatedEvent()
|
|
if tt.args.project.State != tt.result.State {
|
|
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result, tt.args.project)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendReactivatedEvent(t *testing.T) {
|
|
type args struct {
|
|
project *Project
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *Project
|
|
}{
|
|
{
|
|
name: "append reactivate event",
|
|
args: args{
|
|
project: &Project{},
|
|
},
|
|
result: &Project{State: int32(model.PROJECTSTATE_ACTIVE)},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.args.project.appendReactivatedEvent()
|
|
if tt.args.project.State != tt.result.State {
|
|
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result, tt.args.project)
|
|
}
|
|
})
|
|
}
|
|
}
|