From fd2ca5444d35e1a2811af7f88ed091e6341dcfa2 Mon Sep 17 00:00:00 2001 From: Holly Cummins Date: Tue, 7 May 2024 12:23:10 +0100 Subject: [PATCH] Correct schema, do not enable download sort if it is broken --- plugins/download-data/tableau-fetcher.js | 12 +++++++++--- plugins/download-data/tableau-fetcher.test.js | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/download-data/tableau-fetcher.js b/plugins/download-data/tableau-fetcher.js index 0fb41a282b7b..7236ae86bafd 100644 --- a/plugins/download-data/tableau-fetcher.js +++ b/plugins/download-data/tableau-fetcher.js @@ -94,7 +94,7 @@ const getMostRecentData = async () => { const withDates = json .map(entry => { return { - groupId: entry["GroupId"], + groupId: entry["Group Id"], artifactId: entry["data.artifactId"], month: entry["Month of Data.Date"], downloads: convertToNumber(entry["Data.Timeline"]) @@ -116,9 +116,15 @@ const getMostRecentData = async () => { artifactId: entry.artifactId, rank: i + 1 } - }) + }).filter(e => e.groupId !== undefined && e.artifactId !== undefined && e.rank !== undefined) - return { date: mostRecentDate, ranking } + if (onlyMostRecentDownloads.length !== ranking.length) { + console.warn((onlyMostRecentDownloads.length - ranking.length), " download data entries had undefined entries, dropping them. Has the schema changed?") + } + // Only return download data if we have a non-zero amount + if (ranking.length > 1) { + return { date: mostRecentDate, ranking } + } } } diff --git a/plugins/download-data/tableau-fetcher.test.js b/plugins/download-data/tableau-fetcher.test.js index 98f2716f3aa8..502ea9cf005b 100644 --- a/plugins/download-data/tableau-fetcher.test.js +++ b/plugins/download-data/tableau-fetcher.test.js @@ -60,7 +60,7 @@ describe("the tableau data fetcher", () => { axios.post.mockResolvedValueOnce({ data: { credentials: { token, site: { id } } } }) axios.get.mockResolvedValueOnce({ data: { views: { view: [{ id: "view-id" }] } } }) - axios.get.mockResolvedValueOnce({ data: "GroupId,data.artifactId,Month of Data.Date,Year of Data.Date,Data.Timeline\nquarkus-soso,-1,2023,19\n" + mockTableauOutput + "\nquarkus-whatever,whenever,2023,19\n" }) + axios.get.mockResolvedValueOnce({ data: "Group Id,data.artifactId,Month of Data.Date,Year of Data.Date,Data.Timeline\nquarkus-soso,-1,2023,19\n" + mockTableauOutput + "\nquarkus-whatever,whenever,2023,19\n" }) const answer = await fetcher.getMostRecentData() expect(answer?.date).toStrictEqual(new Date("December 2023")) @@ -68,7 +68,7 @@ describe("the tableau data fetcher", () => { }) }) -const mockTableauOutput = `GroupId,data.artifactId,Month of Data.Date,Year of Data.Date,Data.Timeline +const mockTableauOutput = `Group Id,data.artifactId,Month of Data.Date,Year of Data.Date,Data.Timeline thing,quarkus-soso,May 2023,2023,19 thing,quarkus-soso,October 2023,2023,21 thing,quarkus-soso,November 2022,2022,23