e2e: exercise the report endpoint in tracker resource test
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é <emile@getprobo.com>
This commit is contained in:
@@ -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!) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user