package usecase_test

import (
	"context"
	"testing"

	"github.com/google/go-cmp/cmp"

	"source.toby3d.me/toby3d/home/internal/domain"
	"source.toby3d.me/toby3d/home/internal/server/usecase"
	"source.toby3d.me/toby3d/home/internal/site/repository/stub"
)

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

	testSite := domain.TestSite(t)

	actual, err := usecase.NewServerUseCase(stub.NewStubSiteRepository(testSite, nil)).
		Do(context.Background(), testSite.Language)
	if err != nil {
		t.Fatal(err)
	}

	expect := &domain.Server{
		Headers: []domain.Header{{
			Path: "/**",
			Values: map[string]string{
				"Link": `<https://test.auth.app/>; rel="indieauth-metadata", ` +
					`<https://test.pub.app/>; rel="micropub"`,
				"X-Koroko": "Ya-ha-ha!",
			},
		}, {
			Path: "/foo/bar",
			Values: map[string]string{
				"X-Testing": `sample-text`,
			},
		}},
		Redirects: []domain.Redirect{{
			From:   "/foo/bar",
			To:     "/bar/foo",
			Status: 302,
			Force:  false,
		}, {
			From:   "/foo",
			To:     "https://test.redirect.site/",
			Status: 301,
			Force:  true,
		}},
	}
	if diff := cmp.Diff(actual, expect); diff != "" {
		t.Error(diff)
	}
}
