2021-12-29 21:08:09 +00:00
|
|
|
package http_test
|
|
|
|
|
|
|
|
import (
|
2023-01-14 21:27:37 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2021-12-29 21:08:09 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
"golang.org/x/text/message"
|
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
delivery "source.toby3d.me/toby3d/auth/internal/client/delivery/http"
|
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
|
|
|
"source.toby3d.me/toby3d/auth/internal/profile"
|
|
|
|
profilerepo "source.toby3d.me/toby3d/auth/internal/profile/repository/memory"
|
|
|
|
"source.toby3d.me/toby3d/auth/internal/session"
|
|
|
|
sessionrepo "source.toby3d.me/toby3d/auth/internal/session/repository/memory"
|
|
|
|
"source.toby3d.me/toby3d/auth/internal/token"
|
|
|
|
tokenrepo "source.toby3d.me/toby3d/auth/internal/token/repository/memory"
|
|
|
|
tokenucase "source.toby3d.me/toby3d/auth/internal/token/usecase"
|
2021-12-29 21:08:09 +00:00
|
|
|
)
|
|
|
|
|
2022-02-01 22:01:52 +00:00
|
|
|
type Dependencies struct {
|
2022-02-25 15:36:40 +00:00
|
|
|
profiles profile.Repository
|
2022-02-01 21:21:07 +00:00
|
|
|
client *domain.Client
|
|
|
|
config *domain.Config
|
|
|
|
matcher language.Matcher
|
|
|
|
sessions session.Repository
|
|
|
|
tokens token.Repository
|
|
|
|
tokenService token.UseCase
|
|
|
|
}
|
|
|
|
|
2021-12-29 21:08:09 +00:00
|
|
|
func TestRead(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2022-02-01 21:21:07 +00:00
|
|
|
deps := NewDependencies(t)
|
2023-01-14 21:27:37 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "https://app.example.com/", nil)
|
|
|
|
w := httptest.NewRecorder()
|
2022-01-13 20:49:08 +00:00
|
|
|
|
2023-01-14 21:27:37 +00:00
|
|
|
delivery.NewHandler(delivery.NewHandlerOptions{
|
|
|
|
Client: *deps.client,
|
|
|
|
Config: *deps.config,
|
2022-02-01 21:21:07 +00:00
|
|
|
Matcher: deps.matcher,
|
|
|
|
Tokens: deps.tokenService,
|
2023-08-05 02:50:16 +00:00
|
|
|
}).ServeHTTP(w, req)
|
2022-02-01 21:21:07 +00:00
|
|
|
|
2023-01-14 21:27:37 +00:00
|
|
|
if resp := w.Result(); resp.StatusCode != http.StatusOK {
|
|
|
|
t.Errorf("%s %s = %d, want %d", req.Method, req.RequestURI, resp.StatusCode, http.StatusOK)
|
2022-02-01 19:03:08 +00:00
|
|
|
}
|
2021-12-29 21:08:09 +00:00
|
|
|
}
|
2022-02-01 21:21:07 +00:00
|
|
|
|
2022-02-01 22:01:52 +00:00
|
|
|
func NewDependencies(tb testing.TB) Dependencies {
|
2022-02-01 21:21:07 +00:00
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
client := domain.TestClient(tb)
|
|
|
|
config := domain.TestConfig(tb)
|
|
|
|
matcher := language.NewMatcher(message.DefaultCatalog.Languages())
|
2023-01-14 21:27:37 +00:00
|
|
|
sessions := sessionrepo.NewMemorySessionRepository(*config)
|
|
|
|
tokens := tokenrepo.NewMemoryTokenRepository()
|
|
|
|
profiles := profilerepo.NewMemoryProfileRepository()
|
2022-02-25 15:36:40 +00:00
|
|
|
tokenService := tokenucase.NewTokenUseCase(tokenucase.Config{
|
|
|
|
Config: config,
|
|
|
|
Profiles: profiles,
|
|
|
|
Sessions: sessions,
|
|
|
|
Tokens: tokens,
|
|
|
|
})
|
2022-02-01 21:21:07 +00:00
|
|
|
|
2022-02-01 22:01:52 +00:00
|
|
|
return Dependencies{
|
2022-02-01 21:21:07 +00:00
|
|
|
client: client,
|
|
|
|
config: config,
|
|
|
|
matcher: matcher,
|
|
|
|
sessions: sessions,
|
2022-02-25 15:36:40 +00:00
|
|
|
profiles: profiles,
|
2022-02-01 21:21:07 +00:00
|
|
|
tokens: tokens,
|
|
|
|
tokenService: tokenService,
|
|
|
|
}
|
|
|
|
}
|