Skip to content

Commit

Permalink
chore: add test for deep traversal filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Feb 8, 2024
1 parent 03e9835 commit e7e24da
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/verified-fetch/test/content-type-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { CID } from 'multiformats/cid'
describe('content-type-parser', () => {
let helia: Helia
let cid: CID
let dirCid: CID
let verifiedFetch: VerifiedFetch

beforeEach(async () => {
Expand All @@ -21,10 +20,6 @@ describe('content-type-parser', () => {
cid = await fs.addByteStream((async function * () {
yield uint8ArrayFromString('H4sICIlTHVIACw', 'base64')
})())

const dir = await fs.addDirectory()
const index = await fs.addBytes(uint8ArrayFromString('<html><body>Hello world</body></html>'))
dirCid = await fs.cp(index, dir, 'index.html')
})

afterEach(async () => {
Expand Down Expand Up @@ -60,6 +55,11 @@ describe('content-type-parser', () => {
})

it('is passed a filename if it is available', async () => {
const fs = unixfs(helia)
const dir = await fs.addDirectory()
const index = await fs.addBytes(uint8ArrayFromString('<html><body>Hello world</body></html>'))
const dirCid = await fs.cp(index, dir, 'index.html')

verifiedFetch = new VerifiedFetch({
helia
}, {
Expand All @@ -69,6 +69,22 @@ describe('content-type-parser', () => {
expect(resp.headers.get('content-type')).to.equal('index.html')
})

it('is passed a filename from a deep traversal if it is available', async () => {
const fs = unixfs(helia)
const deepDirCid = await fs.addFile({
path: 'foo/bar/a-file.html',
content: uint8ArrayFromString('<html><body>Hello world</body></html>')
})

verifiedFetch = new VerifiedFetch({
helia
}, {
contentTypeParser: async (data, fileName) => fileName
})
const resp = await verifiedFetch.fetch(`ipfs://${deepDirCid}/foo/bar/a-file.html`)
expect(resp.headers.get('content-type')).to.equal('a-file.html')
})

it('sets content type if contentTypeParser is passed', async () => {
verifiedFetch = new VerifiedFetch({
helia
Expand Down

0 comments on commit e7e24da

Please sign in to comment.