test: Add unit and integration tests for API and storage
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
97
backend/internal/api/mocks_test.go
Normal file
97
backend/internal/api/mocks_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"training-tracker/internal/models"
|
||||
)
|
||||
|
||||
// mockExerciseRepo is a mock implementation of ExerciseRepository for testing
|
||||
type mockExerciseRepo struct {
|
||||
exercises []models.Exercise
|
||||
exercise *models.Exercise
|
||||
err error
|
||||
deleteErr error
|
||||
}
|
||||
|
||||
func (m *mockExerciseRepo) List(ctx context.Context) ([]models.Exercise, error) {
|
||||
return m.exercises, m.err
|
||||
}
|
||||
|
||||
func (m *mockExerciseRepo) GetByID(ctx context.Context, id int64) (*models.Exercise, error) {
|
||||
return m.exercise, m.err
|
||||
}
|
||||
|
||||
func (m *mockExerciseRepo) Create(ctx context.Context, req *models.CreateExerciseRequest) (*models.Exercise, error) {
|
||||
return m.exercise, m.err
|
||||
}
|
||||
|
||||
func (m *mockExerciseRepo) Update(ctx context.Context, id int64, req *models.CreateExerciseRequest) (*models.Exercise, error) {
|
||||
return m.exercise, m.err
|
||||
}
|
||||
|
||||
func (m *mockExerciseRepo) Delete(ctx context.Context, id int64) error {
|
||||
return m.deleteErr
|
||||
}
|
||||
|
||||
// mockPlanRepo is a mock implementation of PlanRepository for testing
|
||||
type mockPlanRepo struct {
|
||||
plans []models.TrainingPlan
|
||||
plan *models.TrainingPlan
|
||||
err error
|
||||
deleteErr error
|
||||
}
|
||||
|
||||
func (m *mockPlanRepo) List(ctx context.Context) ([]models.TrainingPlan, error) {
|
||||
return m.plans, m.err
|
||||
}
|
||||
|
||||
func (m *mockPlanRepo) GetByID(ctx context.Context, id int64) (*models.TrainingPlan, error) {
|
||||
return m.plan, m.err
|
||||
}
|
||||
|
||||
func (m *mockPlanRepo) Create(ctx context.Context, req *models.CreatePlanRequest) (*models.TrainingPlan, error) {
|
||||
return m.plan, m.err
|
||||
}
|
||||
|
||||
func (m *mockPlanRepo) Update(ctx context.Context, id int64, req *models.CreatePlanRequest) (*models.TrainingPlan, error) {
|
||||
return m.plan, m.err
|
||||
}
|
||||
|
||||
func (m *mockPlanRepo) Delete(ctx context.Context, id int64) error {
|
||||
return m.deleteErr
|
||||
}
|
||||
|
||||
// mockSessionRepo is a mock implementation of SessionRepository for testing
|
||||
type mockSessionRepo struct {
|
||||
sessions []models.Session
|
||||
session *models.Session
|
||||
entry *models.SessionEntry
|
||||
err error
|
||||
deleteErr error
|
||||
entryErr error
|
||||
}
|
||||
|
||||
func (m *mockSessionRepo) List(ctx context.Context) ([]models.Session, error) {
|
||||
return m.sessions, m.err
|
||||
}
|
||||
|
||||
func (m *mockSessionRepo) GetByID(ctx context.Context, id int64) (*models.Session, error) {
|
||||
return m.session, m.err
|
||||
}
|
||||
|
||||
func (m *mockSessionRepo) Create(ctx context.Context, req *models.CreateSessionRequest) (*models.Session, error) {
|
||||
return m.session, m.err
|
||||
}
|
||||
|
||||
func (m *mockSessionRepo) Update(ctx context.Context, id int64, req *models.CreateSessionRequest) (*models.Session, error) {
|
||||
return m.session, m.err
|
||||
}
|
||||
|
||||
func (m *mockSessionRepo) Delete(ctx context.Context, id int64) error {
|
||||
return m.deleteErr
|
||||
}
|
||||
|
||||
func (m *mockSessionRepo) AddEntry(ctx context.Context, sessionID int64, req *models.CreateSessionEntryRequest) (*models.SessionEntry, error) {
|
||||
return m.entry, m.entryErr
|
||||
}
|
||||
Reference in New Issue
Block a user