core/internal/adapter/repository_test.go
Dawid Wysokiński 9d5987f74c
All checks were successful
ci/woodpecker/push/govulncheck Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/tag/release Pipeline was successful
ci/woodpecker/tag/deployment Pipeline was successful
ci/woodpecker/cron/govulncheck Pipeline was successful
feat: new endpoint GET /api/v2/versions/{versionCode}/servers/{serverKey}/snapshots (#52)
Reviewed-on: #52
2024-05-13 05:12:05 +00:00

131 lines
5.2 KiB
Go

package adapter_test
import (
"context"
"os"
"testing"
"time"
"gitea.dwysokinski.me/twhelp/core/internal/adapter"
"gitea.dwysokinski.me/twhelp/core/internal/bun/buntest"
"gitea.dwysokinski.me/twhelp/core/internal/domain"
"github.com/uptrace/bun"
)
type versionRepository interface {
List(ctx context.Context, params domain.ListVersionsParams) (domain.ListVersionsResult, error)
}
type serverRepository interface {
CreateOrUpdate(ctx context.Context, params ...domain.CreateServerParams) error
List(ctx context.Context, params domain.ListServersParams) (domain.ListServersResult, error)
Update(ctx context.Context, key string, params domain.UpdateServerParams) error
}
type tribeRepository interface {
CreateOrUpdate(ctx context.Context, params ...domain.CreateTribeParams) error
UpdateDominance(ctx context.Context, serverKey string, numPlayerVillages int) error
List(ctx context.Context, params domain.ListTribesParams) (domain.ListTribesResult, error)
Count(ctx context.Context, params domain.CountTribesParams) (int, error)
Delete(ctx context.Context, serverKey string, ids ...int) error
}
type playerRepository interface {
CreateOrUpdate(ctx context.Context, params ...domain.CreatePlayerParams) error
List(ctx context.Context, params domain.ListPlayersParams) (domain.ListPlayersResult, error)
ListWithRelations(ctx context.Context, params domain.ListPlayersParams) (domain.ListPlayersWithRelationsResult, error)
Count(ctx context.Context, params domain.CountPlayersParams) (int, error)
Delete(ctx context.Context, serverKey string, ids ...int) error
}
type villageRepository interface {
CreateOrUpdate(ctx context.Context, params ...domain.CreateVillageParams) error
List(ctx context.Context, params domain.ListVillagesParams) (domain.ListVillagesResult, error)
ListWithRelations(
ctx context.Context,
params domain.ListVillagesParams,
) (domain.ListVillagesWithRelationsResult, error)
Delete(ctx context.Context, serverKey string, ids ...int) error
}
type ennoblementRepository interface {
Create(ctx context.Context, params ...domain.CreateEnnoblementParams) error
List(ctx context.Context, params domain.ListEnnoblementsParams) (domain.ListEnnoblementsResult, error)
ListWithRelations(
ctx context.Context,
params domain.ListEnnoblementsParams,
) (domain.ListEnnoblementsWithRelationsResult, error)
Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error
}
type tribeChangeRepository interface {
Create(ctx context.Context, params ...domain.CreateTribeChangeParams) error
List(ctx context.Context, params domain.ListTribeChangesParams) (domain.ListTribeChangesResult, error)
ListWithRelations(
ctx context.Context,
params domain.ListTribeChangesParams,
) (domain.ListTribeChangesWithRelationsResult, error)
}
type serverSnapshotRepository interface {
Create(ctx context.Context, params ...domain.CreateServerSnapshotParams) error
List(ctx context.Context, params domain.ListServerSnapshotsParams) (domain.ListServerSnapshotsResult, error)
ListWithRelations(
ctx context.Context,
params domain.ListServerSnapshotsParams,
) (domain.ListServerSnapshotsWithRelationsResult, error)
Delete(ctx context.Context, serverKey string, dateLTE time.Time) error
}
type tribeSnapshotRepository interface {
Create(ctx context.Context, params ...domain.CreateTribeSnapshotParams) error
List(ctx context.Context, params domain.ListTribeSnapshotsParams) (domain.ListTribeSnapshotsResult, error)
ListWithRelations(
ctx context.Context,
params domain.ListTribeSnapshotsParams,
) (domain.ListTribeSnapshotsWithRelationsResult, error)
Delete(ctx context.Context, serverKey string, dateLTE time.Time) error
}
type playerSnapshotRepository interface {
Create(ctx context.Context, params ...domain.CreatePlayerSnapshotParams) error
List(ctx context.Context, params domain.ListPlayerSnapshotsParams) (domain.ListPlayerSnapshotsResult, error)
ListWithRelations(
ctx context.Context,
params domain.ListPlayerSnapshotsParams,
) (domain.ListPlayerSnapshotsWithRelationsResult, error)
Delete(ctx context.Context, serverKey string, dateLTE time.Time) error
}
type repositories struct {
version versionRepository
server serverRepository
tribe tribeRepository
player playerRepository
village villageRepository
ennoblement ennoblementRepository
tribeChange tribeChangeRepository
serverSnapshot serverSnapshotRepository
tribeSnapshot tribeSnapshotRepository
playerSnapshot playerSnapshotRepository
}
func newBunDBRepositories(tb testing.TB, bunDB *bun.DB) repositories {
tb.Helper()
buntest.NewFixture(bunDB).Load(tb, context.Background(), os.DirFS("testdata"), "fixture.yml")
return repositories{
version: adapter.NewVersionBunRepository(bunDB),
server: adapter.NewServerBunRepository(bunDB),
tribe: adapter.NewTribeBunRepository(bunDB),
player: adapter.NewPlayerBunRepository(bunDB),
village: adapter.NewVillageBunRepository(bunDB),
ennoblement: adapter.NewEnnoblementBunRepository(bunDB),
tribeChange: adapter.NewTribeChangeBunRepository(bunDB),
serverSnapshot: adapter.NewServerSnapshotBunRepository(bunDB),
tribeSnapshot: adapter.NewTribeSnapshotBunRepository(bunDB),
playerSnapshot: adapter.NewPlayerSnapshotBunRepository(bunDB),
}
}