From 6ffc1f4ce418956e9b6460aa60bcbe1f8070d027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Wysoki=C5=84ski?= Date: Wed, 6 Mar 2024 08:16:29 +0100 Subject: [PATCH] feat: api - /api/v2/versions/{versionCode}/servers/{serverKey}/villages - add one more test --- .../port/handler_http_api_village_test.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/port/handler_http_api_village_test.go b/internal/port/handler_http_api_village_test.go index 7a235b4..7cb2630 100644 --- a/internal/port/handler_http_api_village_test.go +++ b/internal/port/handler_http_api_village_test.go @@ -340,6 +340,44 @@ func TestListVillages(t *testing.T) { }, body) }, }, + { + name: "ERR: len(coords) > 200", + reqModifier: func(t *testing.T, req *http.Request) { + t.Helper() + q := req.URL.Query() + for range 201 { + q.Add("coords", gofakeit.LetterN(50)) + } + req.URL.RawQuery = q.Encode() + }, + assertResp: func(t *testing.T, req *http.Request, resp *http.Response) { + t.Helper() + + assert.Equal(t, http.StatusBadRequest, resp.StatusCode) + + // body + body := decodeJSON[apimodel.ErrorResponse](t, resp.Body) + domainErr := domain.LenOutOfRangeError{ + Min: 0, + Max: 200, + Current: len(req.URL.Query()["coords"]), + } + assert.Equal(t, apimodel.ErrorResponse{ + Errors: []apimodel.Error{ + { + Code: domainErr.Code(), + Message: domainErr.Error(), + Params: map[string]any{ + "current": float64(domainErr.Current), + "max": float64(domainErr.Max), + "min": float64(domainErr.Min), + }, + Path: []string{"$query", "coords"}, + }, + }, + }, body) + }, + }, { name: "ERR: invalid coords string", reqModifier: func(t *testing.T, req *http.Request) {