package http_test

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"source.toby3d.me/toby3d/home/internal/common"
	"source.toby3d.me/toby3d/home/internal/domain"
	delivery "source.toby3d.me/toby3d/home/internal/entry/delivery/http"
	entryucase "source.toby3d.me/toby3d/home/internal/entry/usecase"
	siteucase "source.toby3d.me/toby3d/home/internal/site/usecase"
	"source.toby3d.me/toby3d/home/internal/testutil"
	themeucase "source.toby3d.me/toby3d/home/internal/theme/usecase"
)

func TestHandler_ServeHTTP(t *testing.T) {
	t.Parallel()

	testEntry := domain.TestEntry(t)

	for name, path := range map[string]string{
		"person": "/",
		"note":   testEntry.File.Path(),
	} {
		name, path := name, path

		t.Run(name, func(t *testing.T) {
			t.Parallel()

			req := httptest.NewRequest(http.MethodGet, "https://example.com/"+path, nil)
			req.Header.Set(common.HeaderAccept, common.MIMEApplicationLdJSONProfile)

			w := httptest.NewRecorder()

			delivery.NewHandler(
				siteucase.NewStubSiteUseCase(domain.TestSite(t), nil),
				entryucase.NewStubEntryUseCase(domain.TestEntry(t), nil),
				themeucase.NewDummyThemeUseCase(),
			).ServeHTTP(w, req)
			testutil.GoldenEqual(t, w.Result().Body)
		})
	}
}
