forked from kodekloudhub/go-webapp-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_test.go
43 lines (31 loc) · 1.17 KB
/
account_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package controller
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/ybkuroki/go-webapp-sample/model"
"github.com/ybkuroki/go-webapp-sample/test"
)
func TestGetLoginStatus(t *testing.T) {
router, container := test.Prepare()
account := NewAccountController(container)
router.GET(APIAccountLoginStatus, func(c echo.Context) error { return account.GetLoginStatus(c) })
req := httptest.NewRequest("GET", APIAccountLoginStatus, nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
assert.Equal(t, http.StatusOK, rec.Code)
assert.JSONEq(t, "true", rec.Body.String())
}
func TestGetLoginAccount(t *testing.T) {
router, container := test.Prepare()
account := NewAccountController(container)
router.GET(APIAccountLoginAccount, func(c echo.Context) error { return account.GetLoginAccount(c) })
req := httptest.NewRequest("GET", APIAccountLoginAccount, nil)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, req)
entity := model.NewAccountWithPlainPassword("test", "test", 1)
assert.Equal(t, http.StatusOK, rec.Code)
assert.JSONEq(t, test.ConvertToString(entity), rec.Body.String())
}