Skip to content

Commit 831be2e

Browse files
committed
Fix failing unit test on GitHub Action
1 parent adb8e28 commit 831be2e

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/components/CallToAction/Download/index.astro

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,31 @@ const descriptionId = `${id}-description`
5757
// Construct the download landing page URL
5858
const downloadUrl = `/downloads/${normalizedResource}`
5959
const downloadEntries = await getCollection('downloads')
60+
61+
const matchesDownloadResource = (
62+
download: (typeof downloadEntries)[number],
63+
expectedResource: string
64+
) => {
65+
const normalizedDownloadId = download.id.replace(/\\/g, '/')
66+
67+
if (normalizedDownloadId === expectedResource) {
68+
return true
69+
}
70+
71+
if (normalizedDownloadId.replace(/\/download$/, '') === expectedResource) {
72+
return true
73+
}
74+
75+
if (normalizedDownloadId.split('/')[0] === expectedResource) {
76+
return true
77+
}
78+
79+
const normalizedFilePath = download.filePath?.replace(/\\/g, '/')
80+
return normalizedFilePath?.includes(`/${expectedResource}/download.`) ?? false
81+
}
82+
6083
const matchedDownloadEntry = downloadEntries.find(
61-
download => download.id.replace(/\/download$/, '') === normalizedResource
84+
download => matchesDownloadResource(download, normalizedResource)
6285
)
6386
const directDownloadFileName = matchedDownloadEntry?.data.fileName?.trim()
6487
const directDownloadUrl = directDownloadFileName

0 commit comments

Comments
 (0)