Skip to content

Commit

Permalink
fix: load receipt fixtures correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosa committed Jun 3, 2024
1 parent 9b53536 commit 89711ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
12 changes: 6 additions & 6 deletions packages/upload-client/test/helpers/receipts-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ const server = createServer(async (req, res) => {
const taskCid = req.url?.split('/')[1] ?? ''
if (taskCid === 'unavailable') {
res.writeHead(404)
return res.end()
res.end()
} else if (taskCid === 'failed') {
const body = await generateReceipt((await randomCAR(128)).cid.toString())
res.writeHead(200)
return res.end(body)
res.end(body)
} else {
const body = await generateReceipt(taskCid)
res.writeHead(200)
res.end(body)
}

const body = await generateReceipt(taskCid)
res.writeHead(200)
res.end(body)
})

server.listen(port, () => console.log(`Listening on :${port}`))
Expand Down
31 changes: 11 additions & 20 deletions packages/w3up-client/test/helpers/receipts-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,23 @@ import { randomCAR } from './random.js'
const port = process.env.PORT ?? 9201
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const fixtureName = process.env.FIXTURE_NAME || 'workflow.car'
const fixtureContent = fs.readFileSync(
path.resolve(`${__dirname}`, '..', 'fixtures', fixtureName)
)

const server = createServer(async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', '*')
res.setHeader('Access-Control-Allow-Headers', '*')

const taskID = req.url?.split('/')[1] ?? ''
if (taskID === 'unavailable') {
res.writeHead(404)
return res.end()
} else if (
taskID === 'bafyreibo6nqtvp67daj7dkmeb5c2n6bg5bunxdmxq3lghtp3pmjtzpzfma'
const taskCid = req.url?.split('/')[1] ?? ''
if (
taskCid === 'bafyreibo6nqtvp67daj7dkmeb5c2n6bg5bunxdmxq3lghtp3pmjtzpzfma'
) {
return fs.readFile(
path.resolve(`${__dirname}`, '..', 'fixtures', fixtureName),
(error, content) => {
if (error) {
res.writeHead(500)
res.end()
}
res.writeHead(200, {
'Content-disposition': 'attachment; filename=' + fixtureName,
})
res.end(content)
}
)
res.writeHead(200, {
'Content-disposition': 'attachment; filename=' + fixtureName,
})
return res.end(fixtureContent)
}

const issuer = await Signer.generate()
Expand All @@ -58,7 +49,7 @@ const server = createServer(async (req, res) => {
fx: {
fork: [locationClaim],
},
ran: parseLink(taskID),
ran: parseLink(taskCid),
result: {
ok: {
site: locationClaim.link(),
Expand Down

0 comments on commit 89711ea

Please sign in to comment.