refactor: move mocks and NotImplemented stubs out of domain package
- Move domain/mocks/ → adapters/mocks/ (update imports + mockery directives) - Extract NotImplementedOrganizationRepository + NotImplementedLearningCategory from domain/repository.go into adapters/not_implemented.go - Remove cerrors import from domain/repository.go (domain now has no dependency on internal/common/errors) - nullable stays in domain: used by entity structs and interface Params Addresses review comments #2 (domain deps) and #3 (mocks in domain) on PR #5.
This commit is contained in:
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/domain/mocks"
|
||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/adapters/mocks"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
42
internal/kurious/adapters/not_implemented.go
Normal file
42
internal/kurious/adapters/not_implemented.go
Normal file
@ -0,0 +1,42 @@
|
||||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||
)
|
||||
|
||||
type NotImplementedOrganizationRepository struct{}
|
||||
|
||||
func (NotImplementedOrganizationRepository) ListStats(
|
||||
context.Context,
|
||||
domain.ListOrganizationsParams,
|
||||
) ([]domain.OrganizationStat, error) {
|
||||
return nil, cerrors.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (NotImplementedOrganizationRepository) List(context.Context, domain.ListOrganizationsParams) ([]domain.Organization, error) {
|
||||
return nil, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedOrganizationRepository) Get(context.Context, domain.GetOrganizationParams) (domain.Organization, error) {
|
||||
return domain.Organization{}, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedOrganizationRepository) Create(context.Context, domain.CreateOrganizationParams) (domain.Organization, error) {
|
||||
return domain.Organization{}, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedOrganizationRepository) Delete(ctx context.Context, id string) error {
|
||||
return cerrors.ErrNotImplemented
|
||||
}
|
||||
|
||||
type NotImplementedLearningCategory struct{}
|
||||
|
||||
func (NotImplementedLearningCategory) Upsert(context.Context, domain.LearningCategory) error {
|
||||
return cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedLearningCategory) List(context.Context) ([]domain.LearningCategory, error) {
|
||||
return nil, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedLearningCategory) Get(context.Context, string) (domain.LearningCategory, error) {
|
||||
return domain.LearningCategory{}, cerrors.ErrNotImplemented
|
||||
}
|
||||
@ -110,11 +110,11 @@ func (conn *YDBConnection) Close() error {
|
||||
}
|
||||
|
||||
func (conn *YDBConnection) Organization() domain.OrganizationRepository {
|
||||
return domain.NotImplementedOrganizationRepository{}
|
||||
return NotImplementedOrganizationRepository{}
|
||||
}
|
||||
|
||||
func (conn *YDBConnection) LearningCategory() domain.LearningCategoryRepository {
|
||||
return domain.NotImplementedLearningCategory{}
|
||||
return NotImplementedLearningCategory{}
|
||||
}
|
||||
|
||||
func (conn *YDBConnection) CourseRepository() *ydbCourseRepository {
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/common/nullable"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/domain/mocks"
|
||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/adapters/mocks"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/domain/mocks"
|
||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/adapters/mocks"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
|
||||
"git.loyso.art/frx/kurious/internal/common/nullable"
|
||||
)
|
||||
|
||||
@ -81,7 +80,7 @@ type ListStatisticsResult struct {
|
||||
LearningTypeStatistics []StatisticUnit
|
||||
}
|
||||
|
||||
//go:generate mockery --name CourseRepository
|
||||
//go:generate mockery --name CourseRepository --output ../adapters/mocks
|
||||
type CourseRepository interface {
|
||||
// List courses by specifid parameters.
|
||||
List(context.Context, ListCoursesParams) (ListCoursesResult, error)
|
||||
@ -127,7 +126,7 @@ type ListOrganizationsParams struct {
|
||||
IDs []string
|
||||
}
|
||||
|
||||
//go:generate mockery --name OrganizationRepository
|
||||
//go:generate mockery --name OrganizationRepository --output ../adapters/mocks
|
||||
type OrganizationRepository interface {
|
||||
ListStats(context.Context, ListOrganizationsParams) ([]OrganizationStat, error)
|
||||
List(context.Context, ListOrganizationsParams) ([]Organization, error)
|
||||
@ -136,44 +135,10 @@ type OrganizationRepository interface {
|
||||
Delete(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
type NotImplementedOrganizationRepository struct{}
|
||||
|
||||
func (NotImplementedOrganizationRepository) ListStats(
|
||||
context.Context,
|
||||
ListOrganizationsParams,
|
||||
) ([]OrganizationStat, error) {
|
||||
return nil, cerrors.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (NotImplementedOrganizationRepository) List(context.Context, ListOrganizationsParams) ([]Organization, error) {
|
||||
return nil, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedOrganizationRepository) Get(context.Context, GetOrganizationParams) (Organization, error) {
|
||||
return Organization{}, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedOrganizationRepository) Create(context.Context, CreateOrganizationParams) (Organization, error) {
|
||||
return Organization{}, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedOrganizationRepository) Delete(ctx context.Context, id string) error {
|
||||
return cerrors.ErrNotImplemented
|
||||
}
|
||||
|
||||
//go:generate mockery --name LearningCategoryRepository
|
||||
//go:generate mockery --name LearningCategoryRepository --output ../adapters/mocks
|
||||
type LearningCategoryRepository interface {
|
||||
Upsert(context.Context, LearningCategory) error
|
||||
|
||||
List(context.Context) ([]LearningCategory, error)
|
||||
Get(context.Context, string) (LearningCategory, error)
|
||||
}
|
||||
|
||||
type NotImplementedLearningCategory struct{}
|
||||
|
||||
func (NotImplementedLearningCategory) Upsert(context.Context, LearningCategory) error {
|
||||
return cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedLearningCategory) List(context.Context) ([]LearningCategory, error) {
|
||||
return nil, cerrors.ErrNotImplemented
|
||||
}
|
||||
func (NotImplementedLearningCategory) Get(context.Context, string) (LearningCategory, error) {
|
||||
return LearningCategory{}, cerrors.ErrNotImplemented
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user