Skip to content

Commit

Permalink
Correct schema, do not enable download sort if it is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed May 7, 2024
1 parent d59bde0 commit fd2ca54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions plugins/download-data/tableau-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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 }
}
}

}
Expand Down
4 changes: 2 additions & 2 deletions plugins/download-data/tableau-fetcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ 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"))
expect(answer?.ranking).toStrictEqual(expected)
})
})

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
Expand Down

0 comments on commit fd2ca54

Please sign in to comment.