diff --git a/service/account_test.go b/service/account_test.go new file mode 100644 index 00000000..7ebbc1ce --- /dev/null +++ b/service/account_test.go @@ -0,0 +1,42 @@ +package service + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/ybkuroki/go-webapp-sample/model" + "github.com/ybkuroki/go-webapp-sample/test" +) + +func TestAuthenticateByUsernameAndPassword_Success(t *testing.T) { + container := test.PrepareForServiceTest() + + service := NewAccountService(container) + result, account := service.AuthenticateByUsernameAndPassword("test", "test") + + a := model.Account{} + data, _ := a.FindByName(container.GetRepository(), "test") + + assert.Equal(t, data, account) + assert.Equal(t, true, result) +} + +func TestAuthenticateByUsernameAndPassword_EntityNotFound(t *testing.T) { + container := test.PrepareForServiceTest() + + service := NewAccountService(container) + result, account := service.AuthenticateByUsernameAndPassword("abcde", "abcde") + + assert.Equal(t, (*model.Account)(nil), account) + assert.Equal(t, false, result) +} + +func TestAuthenticateByUsernameAndPassword_AuthenticationFailure(t *testing.T) { + container := test.PrepareForServiceTest() + + service := NewAccountService(container) + result, account := service.AuthenticateByUsernameAndPassword("test", "abcde") + + assert.Equal(t, (*model.Account)(nil), account) + assert.Equal(t, false, result) +} diff --git a/service/category_test.go b/service/category_test.go new file mode 100644 index 00000000..588314b8 --- /dev/null +++ b/service/category_test.go @@ -0,0 +1,17 @@ +package service + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/ybkuroki/go-webapp-sample/test" +) + +func TestFindAllCategories_Success(t *testing.T) { + container := test.PrepareForServiceTest() + + service := NewCategoryService(container) + result := service.FindAllCategories() + + assert.Equal(t, 3, len(*result)) +} diff --git a/service/format_test.go b/service/format_test.go new file mode 100644 index 00000000..f4d4510f --- /dev/null +++ b/service/format_test.go @@ -0,0 +1,17 @@ +package service + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/ybkuroki/go-webapp-sample/test" +) + +func TestFindAllFormats_Success(t *testing.T) { + container := test.PrepareForServiceTest() + + service := NewFormatService(container) + result := service.FindAllFormats() + + assert.Equal(t, 2, len(*result)) +}