From aa99920afb60f144c9122f0b2c358f2512f78ec5 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Wed, 20 Nov 2024 14:27:39 +0100 Subject: [PATCH] Accept optional siteID in upload --- .changeset/itchy-pens-return.md | 7 +++++++ docs/review/api/alfa-test-utils.api.md | 2 ++ packages/alfa-test-utils/src/report/sip.ts | 15 ++++++++++----- packages/alfa-test-utils/test/report/sip.spec.tsx | 12 ++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .changeset/itchy-pens-return.md diff --git a/.changeset/itchy-pens-return.md b/.changeset/itchy-pens-return.md new file mode 100644 index 00000000..9228a064 --- /dev/null +++ b/.changeset/itchy-pens-return.md @@ -0,0 +1,7 @@ +--- +"@siteimprove/alfa-test-utils": minor +--- + +**Added:** `SIP.upload` now accepts an optional `siteID` parameter. + +This should be the site ID of your site in the Siteimprove Intelligence Platform. It can be use to group tests by site and generate more accurate metadata and aggregates. diff --git a/docs/review/api/alfa-test-utils.api.md b/docs/review/api/alfa-test-utils.api.md index 41aa6510..498c8eec 100644 --- a/docs/review/api/alfa-test-utils.api.md +++ b/docs/review/api/alfa-test-utils.api.md @@ -254,6 +254,7 @@ export namespace SIP { CantTell: number; Durations: RuleDurations; }>; + SiteId?: string; TestName?: string; Version: `${number}.${number}.${number}`; } @@ -272,6 +273,7 @@ export namespace SIP { includeGitInfo?: boolean; pageTitle?: string | ((page: Page) => string); pageURL?: string | ((page: Page) => string); + siteID?: string; testName?: string | ((git: CommitInformation) => string); userName?: string; } diff --git a/packages/alfa-test-utils/src/report/sip.ts b/packages/alfa-test-utils/src/report/sip.ts index f09ebaf7..4658556a 100644 --- a/packages/alfa-test-utils/src/report/sip.ts +++ b/packages/alfa-test-utils/src/report/sip.ts @@ -95,6 +95,11 @@ export namespace SIP { */ apiKey?: string; + /** + * The site ID in the Siteimprove Intelligence Platform. + */ + siteID?: string; + /** * The URL of the page, or a function to build it from the audited page. * Defaults to the URL used to scrape the page. @@ -150,11 +155,10 @@ export namespace SIP { */ Version: `${number}.${number}.${number}`; - // Ignored for now. - // /** - // * The site ID to which the page belongs in the Siteimprove Intelligence Platform. - // */ - // SiteId?: string; + /** + * The site ID to which the page belongs in the Siteimprove Intelligence Platform. + */ + SiteId?: string; /** * Information about the latest git commit @@ -254,6 +258,7 @@ export namespace SIP { const result: Payload = { RequestTimestamp: timestamp, Version: audit.alfaVersion, + SiteId: options.siteID, PageUrl, PageTitle, TestName, diff --git a/packages/alfa-test-utils/test/report/sip.spec.tsx b/packages/alfa-test-utils/test/report/sip.spec.tsx index cc4ce9d4..4a56975c 100644 --- a/packages/alfa-test-utils/test/report/sip.spec.tsx +++ b/packages/alfa-test-utils/test/report/sip.spec.tsx @@ -162,6 +162,18 @@ test("S3.axiosConfig() creates an axios config", (t) => { }); }); +test("Metadata.payload() uses site ID if provided", async (t) => { + const actual = await Metadata.payload( + makeAudit(), + { siteID: "12345" }, + timestamp + ); + t.notEqual(actual.CommitInformation, undefined); + delete actual.CommitInformation; + + t.deepEqual(actual, makePayload({ SiteId: "12345" })); +}); + test("Metadata.payload() uses test name if provided", async (t) => { const actual = await Metadata.payload( makeAudit(),