package router_test

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

	"galaxy/model/rest"

	"github.com/stretchr/testify/assert"
)

const apiBanishPath = "/api/v1/admin/race/banish"

func TestBanishHappyPath(t *testing.T) {
	r := setupRouter()

	w := httptest.NewRecorder()
	req, _ := http.NewRequest(http.MethodPost, apiBanishPath, asBody(rest.BanishRequest{RaceName: "Aelinari"}))
	r.ServeHTTP(w, req)

	assert.Equal(t, http.StatusNoContent, w.Code, w.Body)
	assert.Empty(t, w.Body.String())
}

func TestBanishValidation(t *testing.T) {
	r := setupRouter()

	for _, tc := range []struct {
		description string
		body        any
	}{
		{"missing race_name", struct{}{}},
		{"empty race_name", rest.BanishRequest{RaceName: ""}},
		{"blank race_name", rest.BanishRequest{RaceName: "    "}},
	} {
		t.Run(tc.description, func(t *testing.T) {
			w := httptest.NewRecorder()
			req, _ := http.NewRequest(http.MethodPost, apiBanishPath, asBody(tc.body))
			r.ServeHTTP(w, req)

			assert.Equal(t, http.StatusBadRequest, w.Code, w.Body)
		})
	}
}
