Skip to content

Commit

Permalink
test: add verified-fetch unit test for root directory redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Mar 25, 2024
1 parent ebdc2a6 commit 55619e3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/verified-fetch/test/verified-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,33 @@ describe('@helia/verifed-fetch', () => {
expect(ipfsResponse.url).to.equal(`ipfs://${res.cid}/foo`)
})

it('should return a 301 with a trailing slash when a root directory is requested without a trailing slash', async () => {
const finalRootFileContent = new Uint8Array([0x01, 0x02, 0x03])

const fs = unixfs(helia)
const res = await last(fs.addAll([{
path: '/index.html',
content: finalRootFileContent
}], {
wrapWithDirectory: true
}))

if (res == null) {
throw new Error('Import failed')
}

Check warning on line 176 in packages/verified-fetch/test/verified-fetch.spec.ts

View check run for this annotation

Codecov / codecov/patch

packages/verified-fetch/test/verified-fetch.spec.ts#L175-L176

Added lines #L175 - L176 were not covered by tests

const stat = await fs.stat(res.cid)
expect(stat.type).to.equal('directory')

const ipfsResponse = await verifiedFetch.fetch(`https://ipfs.local/ipfs/${res.cid}`, {
redirect: 'manual'
})
expect(ipfsResponse).to.be.ok()
expect(ipfsResponse.status).to.equal(301)
expect(ipfsResponse.headers.get('location')).to.equal(`https://ipfs.local/ipfs/${res.cid}/`)
expect(ipfsResponse.url).to.equal(`https://ipfs.local/ipfs/${res.cid}`)
})

it('should return a 301 with a trailing slash when a gateway directory is requested without a trailing slash', async () => {
const finalRootFileContent = new Uint8Array([0x01, 0x02, 0x03])

Expand Down

0 comments on commit 55619e3

Please sign in to comment.