From 733b793991d63dce078789152745c30f56104a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Mon, 11 May 2026 14:19:22 +0400 Subject: [PATCH] e2e: exercise the report endpoint in tracker resource test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous test seeded tracker resources directly via the GraphQL `CreateTrackerResource` mutation, which doesn't go through the public `/report` handler. Switching the seeding to `ReportDetectedResources` covers the end-to-end path -- payload decoding, validation, and the new upsert -- so the listing assert is now grounded in the same write path that real clients use. Signed-off-by: Émile Ré --- e2e/console/tracker_resource_test.go | 4 +--- e2e/internal/factory/factory.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/e2e/console/tracker_resource_test.go b/e2e/console/tracker_resource_test.go index af68caf06..544393fe1 100644 --- a/e2e/console/tracker_resource_test.go +++ b/e2e/console/tracker_resource_test.go @@ -105,9 +105,7 @@ func TestTrackerResource_List(t *testing.T) { owner := testutil.NewClient(t, testutil.RoleOwner) bannerID := factory.CreateCookieBanner(owner) - categoryID := factory.CreateCookieCategory(owner, bannerID) - factory.CreateTrackerResource(owner, categoryID) - factory.CreateTrackerResource(owner, categoryID) + factory.ReportDetectedResources(owner, bannerID, 2) const query = ` query($id: ID!) { diff --git a/e2e/internal/factory/factory.go b/e2e/internal/factory/factory.go index caa715502..991944021 100644 --- a/e2e/internal/factory/factory.go +++ b/e2e/internal/factory/factory.go @@ -16,8 +16,11 @@ package factory import ( + "bytes" + "encoding/json" "fmt" "maps" + "net/http" "strings" "github.com/brianvoe/gofakeit/v7" @@ -1431,3 +1434,24 @@ func CreateTrackerResource(c *testutil.Client, categoryID string, attrs ...Attrs return result.CreateTrackerResource.TrackerResourceEdge.Node.ID } + +func ReportDetectedResources(c *testutil.Client, bannerID string, count int) { + c.T.Helper() + + resources := make([]map[string]string, 0, count) + for range count { + resources = append(resources, map[string]string{ + "url": fmt.Sprintf("https://%s.example.com/%s.js", strings.ToLower(gofakeit.LetterN(8)), gofakeit.LetterN(6)), + "resource_type": "script", + }) + } + + body, err := json.Marshal(map[string]any{"resources": resources}) + require.NoError(c.T, err, "cannot marshal report body") + + url := fmt.Sprintf("%s/api/cookie-banner/v1/%s/report", c.BaseURL(), bannerID) + resp, err := http.Post(url, "application/json", bytes.NewReader(body)) + require.NoError(c.T, err, "report detected resources request failed") + defer func() { _ = resp.Body.Close() }() + require.Equal(c.T, http.StatusNoContent, resp.StatusCode, "report detected resources unexpected status") +}