Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ybkuroki committed Dec 26, 2021
1 parent eb0668d commit 7c2252d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
42 changes: 42 additions & 0 deletions service/account_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions service/category_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
17 changes: 17 additions & 0 deletions service/format_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 7c2252d

Please sign in to comment.