2020-04-07 11:23:04 +00:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-04-20 13:16:33 +00:00
|
|
|
mock_cache "github.com/caos/zitadel/internal/cache/mock"
|
2020-04-07 11:23:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/mock"
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
"github.com/caos/zitadel/internal/project/model"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
)
|
|
|
|
|
2020-04-20 13:16:33 +00:00
|
|
|
func GetMockCache(ctrl *gomock.Controller) *ProjectCache {
|
|
|
|
mockCache := mock_cache.NewMockCache(ctrl)
|
|
|
|
mockCache.EXPECT().Get(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
|
|
|
mockCache.EXPECT().Set(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
|
|
|
return &ProjectCache{projectCache: mockCache}
|
|
|
|
}
|
|
|
|
|
2020-04-07 11:23:04 +00:00
|
|
|
func GetMockProjectByIDOK(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
data, _ := json.Marshal(Project{Name: "Name"})
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockProjectByIDNoEvents(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
events := []*es_models.Event{}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProject(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-15 15:11:42 +00:00
|
|
|
data, _ := json.Marshal(Project{Name: "Name"})
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateInactiveProject(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
data, _ := json.Marshal(Project{Name: "Name"})
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 2, Type: model.ProjectDeactivated, Data: data},
|
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithMember(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
data, _ := json.Marshal(Project{Name: "Name"})
|
|
|
|
memberData, _ := json.Marshal(ProjectMember{UserID: "UserID", Roles: []string{"Role"}})
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectMemberAdded, Data: memberData},
|
|
|
|
}
|
2020-04-07 11:23:04 +00:00
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
2020-04-15 15:11:42 +00:00
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
2020-04-07 11:23:04 +00:00
|
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
2020-04-15 15:11:42 +00:00
|
|
|
|
|
|
|
func GetMockManipulateProjectNoEvents(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
events := []*es_models.Event{}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockProjectMemberByIDsOK(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
projectData, _ := json.Marshal(Project{Name: "Name"})
|
|
|
|
memberData, _ := json.Marshal(ProjectMember{UserID: "UserID", Roles: []string{"Role"}})
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: projectData},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectMemberAdded, Data: memberData},
|
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
2020-04-20 13:16:33 +00:00
|
|
|
return &ProjectEventstore{Eventstore: mockEs, projectCache: GetMockCache(ctrl)}
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|