2020-04-07 11:23:04 +00:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-06-15 14:50:09 +00:00
|
|
|
|
2020-08-07 11:49:57 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
|
2020-04-20 13:16:33 +00:00
|
|
|
mock_cache "github.com/caos/zitadel/internal/cache/mock"
|
2020-04-21 15:00:32 +00:00
|
|
|
"github.com/caos/zitadel/internal/crypto"
|
2020-04-07 11:23:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/mock"
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
2020-05-28 11:28:36 +00:00
|
|
|
"github.com/caos/zitadel/internal/id"
|
2020-04-23 05:54:40 +00:00
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
|
|
"github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
2020-06-15 14:50:09 +00:00
|
|
|
repo_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
2020-04-07 11:23:04 +00:00
|
|
|
)
|
|
|
|
|
2020-04-21 15:00:32 +00:00
|
|
|
func GetMockedEventstore(ctrl *gomock.Controller, mockEs *mock.MockEventstore) *ProjectEventstore {
|
|
|
|
return &ProjectEventstore{
|
|
|
|
Eventstore: mockEs,
|
|
|
|
projectCache: GetMockCache(ctrl),
|
|
|
|
idGenerator: GetSonyFlacke(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockedEventstoreWithPw(ctrl *gomock.Controller, mockEs *mock.MockEventstore) *ProjectEventstore {
|
|
|
|
return &ProjectEventstore{
|
|
|
|
Eventstore: mockEs,
|
|
|
|
projectCache: GetMockCache(ctrl),
|
|
|
|
idGenerator: GetSonyFlacke(),
|
|
|
|
pwGenerator: GetMockPwGenerator(ctrl),
|
|
|
|
}
|
|
|
|
}
|
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-05-28 11:28:36 +00:00
|
|
|
func GetSonyFlacke() id.Generator {
|
|
|
|
return id.SonyFlakeGenerator
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockPwGenerator(ctrl *gomock.Controller) crypto.Generator {
|
|
|
|
generator := crypto.NewMockGenerator(ctrl)
|
|
|
|
generator.EXPECT().Length().Return(uint(10))
|
|
|
|
generator.EXPECT().Runes().Return([]rune("abcdefghijklmnopqrstuvwxyz"))
|
|
|
|
generator.EXPECT().Alg().Return(crypto.NewBCrypt(10))
|
|
|
|
return generator
|
|
|
|
}
|
|
|
|
|
2020-04-07 11:23:04 +00:00
|
|
|
func GetMockProjectByIDOK(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
2020-04-07 11:23:04 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
2020-04-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
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-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProject(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
2020-04-15 15:11:42 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
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-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithPw(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
2020-04-21 15:00:32 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstoreWithPw(ctrl, mockEs)
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateInactiveProject(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
2020-04-15 15:11:42 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 2, Type: model.ProjectDeactivated, Data: data},
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
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-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithMember(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
memberData, _ := json.Marshal(model.ProjectMember{UserID: "UserID", Roles: []string{"Role"}})
|
2020-04-15 15:11:42 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectMemberAdded, Data: memberData},
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithRole(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
roleData, _ := json.Marshal(model.ProjectRole{Key: "Key", DisplayName: "DisplayName", Group: "Group"})
|
2020-04-21 15:00:32 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectRoleAdded, Data: roleData},
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
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-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
2020-08-07 11:49:57 +00:00
|
|
|
func GetMockManipulateProjectWithOIDCApp(ctrl *gomock.Controller, authMethod proj_model.OIDCAuthMethodType) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
appData, _ := json.Marshal(model.Application{AppID: "AppID", Name: "Name"})
|
|
|
|
oidcData, _ := json.Marshal(model.OIDCConfig{
|
2020-08-07 11:49:57 +00:00
|
|
|
AppID: "AppID",
|
|
|
|
ResponseTypes: []int32{int32(proj_model.OIDCResponseTypeCode)},
|
|
|
|
GrantTypes: []int32{int32(proj_model.OIDCGrantTypeAuthorizationCode)},
|
|
|
|
AuthMethodType: int32(authMethod),
|
2020-04-21 15:00:32 +00:00
|
|
|
})
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ApplicationAdded, Data: appData},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.OIDCConfigAdded, Data: oidcData},
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstoreWithPw(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithSAMLApp(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
appData, _ := json.Marshal(model.Application{AppID: "AppID", Name: "Name"})
|
2020-04-21 15:00:32 +00:00
|
|
|
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ApplicationAdded, Data: appData},
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithGrant(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
grantData, _ := json.Marshal(model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID", RoleKeys: []string{"Key"}})
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantAdded, Data: grantData},
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithGrantExistingRole(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
roleData, _ := json.Marshal(model.ProjectRole{Key: "Key", DisplayName: "DisplayName", Group: "Group"})
|
|
|
|
roleData2, _ := json.Marshal(model.ProjectRole{Key: "KeyChanged", DisplayName: "DisplayName", Group: "Group"})
|
|
|
|
grantData, _ := json.Marshal(model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID", RoleKeys: []string{"Key"}})
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectRoleAdded, Data: roleData},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectRoleAdded, Data: roleData2},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantAdded, Data: grantData},
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockManipulateProjectWithGrantMember(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
data, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
grantData, _ := json.Marshal(model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantedOrgID", RoleKeys: []string{"Key"}})
|
|
|
|
memberData, _ := json.Marshal(model.ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"Role"}})
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: data},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantAdded, Data: grantData},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantMemberAdded, Data: memberData},
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
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-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockProjectMemberByIDsOK(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
projectData, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
memberData, _ := json.Marshal(model.ProjectMember{UserID: "UserID", Roles: []string{"Role"}})
|
2020-04-15 15:11:42 +00:00
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: projectData},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectMemberAdded, Data: memberData},
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockProjectAppsByIDsOK(ctrl *gomock.Controller) *ProjectEventstore {
|
2020-04-23 05:54:40 +00:00
|
|
|
projectData, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
appData, _ := json.Marshal(model.Application{AppID: "AppID", Name: "Name"})
|
|
|
|
oidcData, _ := json.Marshal(model.OIDCConfig{ClientID: "ClientID"})
|
|
|
|
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ProjectAdded, Data: projectData},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.ApplicationAdded, Data: appData},
|
|
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.OIDCConfigAdded, Data: oidcData},
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockProjectGrantByIDsOK(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
projectData, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
grantData, _ := json.Marshal(model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantID", RoleKeys: []string{"Key"}})
|
|
|
|
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: projectData},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantAdded, Data: grantData},
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockProjectGrantMemberByIDsOK(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
projectData, _ := json.Marshal(model.Project{Name: "Name"})
|
|
|
|
grantData, _ := json.Marshal(model.ProjectGrant{GrantID: "GrantID", GrantedOrgID: "GrantID", RoleKeys: []string{"Key"}})
|
|
|
|
memberData, _ := json.Marshal(model.ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"Role"}})
|
2020-04-21 15:00:32 +00:00
|
|
|
|
|
|
|
events := []*es_models.Event{
|
2020-05-11 10:16:29 +00:00
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectAdded, Data: projectData},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantAdded, Data: grantData},
|
|
|
|
&es_models.Event{AggregateID: "ID", Sequence: 1, Type: model.ProjectGrantMemberAdded, Data: memberData},
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
2020-04-21 15:00:32 +00:00
|
|
|
return GetMockedEventstore(ctrl, mockEs)
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
2020-06-15 14:50:09 +00:00
|
|
|
|
|
|
|
func GetMockChangesProjectOK(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
project := model.Project{
|
|
|
|
Name: "MusterProject",
|
|
|
|
}
|
|
|
|
data, err := json.Marshal(project)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
}
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "AggregateIDProject", Sequence: 1, AggregateType: repo_model.ProjectAggregate, Data: data},
|
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstoreComplexity(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockChangesProjectNoEvents(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
events := []*es_models.Event{}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstoreComplexity(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockedEventstoreComplexity(ctrl *gomock.Controller, mockEs *mock.MockEventstore) *ProjectEventstore {
|
|
|
|
return &ProjectEventstore{
|
|
|
|
Eventstore: mockEs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockChangesApplicationOK(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
app := model.Application{
|
|
|
|
Name: "MusterApp",
|
|
|
|
AppID: "AppId",
|
|
|
|
Type: 3,
|
|
|
|
}
|
|
|
|
data, err := json.Marshal(app)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
}
|
|
|
|
events := []*es_models.Event{
|
|
|
|
&es_models.Event{AggregateID: "AggregateIDApp", Type: "project.application.added", Sequence: 1, AggregateType: repo_model.ProjectAggregate, Data: data},
|
|
|
|
}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstoreComplexity(ctrl, mockEs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMockChangesApplicationNoEvents(ctrl *gomock.Controller) *ProjectEventstore {
|
|
|
|
events := []*es_models.Event{}
|
|
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
|
|
return GetMockedEventstoreComplexity(ctrl, mockEs)
|
|
|
|
}
|