-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_test.ts
53 lines (48 loc) · 1.97 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { CAREncoderStream, createFileEncoderStream } from 'ipfs-car'
import { CID } from 'multiformats'
import { describe, it } from '@std/testing/bdd'
import { getObject, uploadCar } from './mod.ts'
import { assertEquals } from '@std/assert/equals'
import { assertStringIncludes } from '@std/assert/string-includes'
import { toBlob } from '@std/streams/to-blob'
const placeholderCID = CID.parse('bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi')
describe('getObject', () => {
it('should return a response of a file', async () => {
const res = await getObject({
bucketName: 'filebase-upload-tests',
token: Deno.env.get('FILEBASE_TOKEN')!,
filename: 'hello.txt',
})
assertEquals(await res.text(), 'Hello world')
assertEquals(
res.headers.get('x-amz-meta-cid'),
'QmNRCQWfgze6AbBCaT1rkrkV5tJ2aP4oTNPb5JZcXYywve',
)
})
it('should accept custom `apiUrl`', async () => {
try {
await getObject({
bucketName: 'filebase-upload-tests',
token: Deno.env.get('FILEBASE_TOKEN')!,
filename: 'hello.txt',
apiUrl: 'stauro.dev',
})
} catch (error) {
if ((error as Error).cause) {
assertStringIncludes(((error as Error).cause as URL).hostname, 'filebase-upload-tests.stauro.dev')
} else assertStringIncludes((error as Error).message, 'filebase-upload-tests.stauro.dev')
}
})
})
describe('uploadCar', { sanitizeResources: false }, () => {
it(
'should upload a CAR file and emit a CID from response headers',
async () => {
const stream = createFileEncoderStream(new Blob(['Hello ipfs-car!']))
.pipeThrough(new CAREncoderStream([placeholderCID]))
const file = new File([await toBlob(stream)], 'file.car')
const res = await uploadCar({ bucketName: 'filebase-upload-tests', token: Deno.env.get('FILEBASE_TOKEN')!, file })
assertEquals(res.headers.get('x-amz-meta-cid'), 'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi')
},
)
})