2020-11-08 14:46:12 +03:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/muety/wakapi/mocks"
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AliasServiceTestSuite struct {
|
|
|
|
suite.Suite
|
2020-11-14 14:30:45 +03:00
|
|
|
TestUserId string
|
|
|
|
AliasRepository *mocks.AliasRepositoryMock
|
2020-11-08 14:46:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AliasServiceTestSuite) SetupSuite() {
|
|
|
|
suite.TestUserId = "johndoe@example.org"
|
|
|
|
|
|
|
|
aliases := []*models.Alias{
|
|
|
|
{
|
|
|
|
Type: models.SummaryProject,
|
|
|
|
UserID: suite.TestUserId,
|
|
|
|
Key: "wakapi",
|
|
|
|
Value: "wakapi-mobile",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasRepoMock := new(mocks.AliasRepositoryMock)
|
|
|
|
aliasRepoMock.On("GetByUser", suite.TestUserId).Return(aliases, nil)
|
|
|
|
aliasRepoMock.On("GetByUser", mock.AnythingOfType("string")).Return([]*models.Alias{}, assert.AnError)
|
|
|
|
|
2020-11-14 14:30:45 +03:00
|
|
|
suite.AliasRepository = aliasRepoMock
|
2020-11-08 14:46:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAliasServiceTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(AliasServiceTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AliasServiceTestSuite) TestAliasService_GetAliasOrDefault() {
|
2020-11-14 14:30:45 +03:00
|
|
|
sut := NewAliasService(suite.AliasRepository)
|
2020-11-08 14:46:12 +03:00
|
|
|
|
|
|
|
result1, err1 := sut.GetAliasOrDefault(suite.TestUserId, models.SummaryProject, "wakapi-mobile")
|
|
|
|
result2, err2 := sut.GetAliasOrDefault(suite.TestUserId, models.SummaryProject, "wakapi")
|
|
|
|
result3, err3 := sut.GetAliasOrDefault(suite.TestUserId, models.SummaryProject, "anchr")
|
|
|
|
|
|
|
|
assert.Equal(suite.T(), "wakapi", result1)
|
|
|
|
assert.Nil(suite.T(), err1)
|
|
|
|
assert.Equal(suite.T(), "wakapi", result2)
|
|
|
|
assert.Nil(suite.T(), err2)
|
|
|
|
assert.Equal(suite.T(), "anchr", result3)
|
|
|
|
assert.Nil(suite.T(), err3)
|
|
|
|
}
|