Skip to content

Commit

Permalink
Adds mocks to tests different layers. Refs #1 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ariel17 committed Mar 7, 2023
1 parent 0cb4996 commit d7de0be
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/clients/football_mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package clients

import (
"github.com/stretchr/testify/mock"
)

type MockAPIClient struct {
mock.Mock
}

func (m *MockAPIClient) GetLeagueByCode(code string) (*League, error) {
args := m.Called(code)
league, ok := args.Get(0).(*League)
if !ok {
return nil, args.Error(1)
}
return league, args.Error(1)
}

func (m *MockAPIClient) GetTeamsByLeagueCode(code string) ([]Team, error) {
args := m.Called(code)
teams, ok := args.Get(0).([]Team)
if !ok {
return nil, args.Error(1)
}
return teams, args.Error(1)
}

func (m *MockAPIClient) GetTeamByID(id int64) (*Team, error) {
args := m.Called(id)
team, ok := args.Get(0).(*Team)
if !ok {
return nil, args.Error(1)
}
return team, args.Error(1)
}

func (m *MockAPIClient) GetPersonByID(id int64) (*Person, error) {
args := m.Called(id)
person, ok := args.Get(0).(*Person)
if !ok {
return nil, args.Error(1)
}
return person, args.Error(1)
}
66 changes: 66 additions & 0 deletions pkg/repositories/repository_mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package repositories

import (
"github.com/stretchr/testify/mock"

"github.com/ariel17/be-challenge-arios/pkg/models"
)

type MockRepository struct {
mock.Mock
}

func (m *MockRepository) Connect() error {
args := m.Called()
return args.Error(0)
}

func (m *MockRepository) Close() error {
args := m.Called()
return args.Error(0)
}

func (m *MockRepository) GetStatus() error {
args := m.Called()
return args.Error(0)
}

func (m *MockRepository) AddPerson(person models.Person) error {
args := m.Called(person)
return args.Error(0)
}

func (m *MockRepository) AddTeam(team models.Team) error {
args := m.Called(team)
return args.Error(0)
}

func (m *MockRepository) AddCompetition(competition models.Competition) error {
args := m.Called(competition)
return args.Error(0)
}

func (m *MockRepository) AddTeamToCompetition(team models.Team, competition models.Competition) error {
args := m.Called(team, competition)
return args.Error(0)
}

func (m *MockRepository) AddPersonToTeam(person models.Person, team models.Team) error {
args := m.Called(person, team)
return args.Error(0)
}

func (m *MockRepository) GetTeamByTLA(tla string) (*models.Team, error) {
args := m.Called(tla)
return args.Get(0).(*models.Team), args.Error(1)
}

func (m *MockRepository) GetPersonsByCompetitionCode(code string) ([]models.Person, error) {
args := m.Called(code)
return args.Get(0).([]models.Person), args.Error(1)
}

func (m *MockRepository) GetPersonsByTeamTLA(tla string) ([]models.Person, error) {
args := m.Called(tla)
return args.Get(0).([]models.Person), args.Error(1)
}
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions pkg/services/mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package services

import (
"github.com/stretchr/testify/mock"
)

type MockImporterService struct {
mock.Mock
}

func (m *MockImporterService) ImportDataByCompetitionCode(code string) error {
args := m.Called(code)
return args.Error(0)
}

type MockStatusService struct {
mock.Mock
}

// GetStatus checks the application's health and returns and object describing
// it.
func (m *MockStatusService) GetStatus() Status {
args := m.Called()
return args.Get(0).(Status)
}

0 comments on commit d7de0be

Please sign in to comment.