Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: re-enable upload-api tests #864

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"build": "tsc --build",
"check": "tsc --build",
"lint": "tsc --build",
"test": "mocha --bail --timeout 10s -n no-warnings -n experimental-vm-modules -n experimental-fetch test/**/*.spec.js",
"test": "mocha --bail --timeout 10s -n no-warnings -n experimental-vm-modules -n experimental-fetch 'test/**/*.spec.js'",
"test-watch": "pnpm build && mocha --bail --timeout 10s --watch --parallel -n no-warnings -n experimental-vm-modules -n experimental-fetch --watch-files src,test"
},
"dependencies": {
Expand Down
16 changes: 7 additions & 9 deletions packages/upload-api/test/access-authorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,13 @@ export const test = {
? delegations
: delegations.reverse()

assert.deepEqual(attestation.capabilities, [
{
can: 'ucan/attest',
with: service.did(),
nb: {
proof: authorization.cid,
},
},
])

assert.equal(attestation.capabilities[0].can, 'ucan/attest')
assert.equal(attestation.capabilities[0].with, service.did())
assert.equal(
/** @type {import('@ucanto/interface').Capability} */(attestation.capabilities[0]).nb.proof.toString(),
authorization.cid.toString()
)

assert.equal(authorization.issuer.did(), account.did())
assert.deepEqual(authorization.capabilities, [
Expand Down
12 changes: 6 additions & 6 deletions packages/upload-api/test/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const test = {

assert.equal(storeAdd.out.ok.status, 'upload')
assert.equal(storeAdd.out.ok.with, spaceDid)
assert.deepEqual(storeAdd.out.ok.link, link)
assert.deepEqual(storeAdd.out.ok.link.toString(), link.toString())

assert.equal(storeAdd.out.ok.headers?.['content-length'], String(size))
assert.deepEqual(
Expand Down Expand Up @@ -84,13 +84,13 @@ export const test = {
assert.deepEqual(
{
space: item.space,
link: item.link,
link: item.link.toString(),
size: item.size,
issuer: item.issuer,
},
{
space: spaceDid,
link,
link: link.toString(),
size: data.byteLength,
issuer: alice.did(),
}
Expand Down Expand Up @@ -243,7 +243,7 @@ export const test = {

assert.equal(storeAdd.out.ok.status, 'done')
assert.equal(storeAdd.out.ok.with, spaceDid)
assert.deepEqual(storeAdd.out.ok.link, link)
assert.deepEqual(storeAdd.out.ok.link.toString(), link.toString())
assert.equal(storeAdd.out.ok.url == null, true)

const item = await context.testStoreTable.get(spaceDid, link)
Expand All @@ -254,13 +254,13 @@ export const test = {
assert.deepEqual(
{
space: item.space,
link: item.link,
link: item.link.toString(),
size: item.size,
issuer: item.issuer,
},
{
space: spaceDid,
link,
link: link.toString(),
size: data.byteLength,
issuer: alice.did(),
}
Expand Down
30 changes: 13 additions & 17 deletions packages/upload-api/test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ export const test = {
throw new Error('invocation failed', { cause: uploadAdd })
}

assert.deepEqual(uploadAdd.out.ok, { root, shards })
assert.equal(uploadAdd.out.ok.root.toString(), root.toString())
assert.deepEqual(uploadAdd.out.ok.shards?.map(String).sort(), shards.map(String).sort())

const { results } = await context.uploadTable.list(spaceDid)
assert.deepEqual(results.length, 1)

const [item] = results
assert.deepEqual(item.root, root)
assert.deepEqual(item.shards, shards)
assert.deepEqual(item.root.toString(), root.toString())
assert.deepEqual(item.shards?.map(String).sort(), shards.map(String).sort())

const msAgo = Date.now() - new Date(item.insertedAt).getTime()
assert.equal(msAgo < 60_000, true)
Expand Down Expand Up @@ -91,8 +92,8 @@ export const test = {
}

assert.deepEqual(
uploadAdd.out.ok,
{ root, shards: [] },
uploadAdd.out.ok.shards,
[],
'Should have an empty shards array'
)

Expand Down Expand Up @@ -148,18 +149,13 @@ export const test = {
throw new Error('invocation failed', { cause: uploadAdd2 })
}

assert.deepEqual(uploadAdd2.out.ok.shards, shards)
assert.deepEqual(uploadAdd2.out.ok.shards?.map(String).sort(), shards.map(String).sort())

const { results } = await context.uploadTable.list(spaceDid)
assert.equal(results.length, 1)
const [upload] = results
assert.deepEqual(
{
root: upload.root,
shards: upload.shards?.map(String).sort(),
},
{ root, shards: shards.map(String).sort() }
)
assert.equal(upload.root.toString(), root.toString())
assert.deepEqual(upload.shards?.map(String).sort(), shards.map(String).sort())
},

'upload/add merges shards to an existing item with shards': async (
Expand Down Expand Up @@ -223,11 +219,11 @@ export const test = {
const [upload] = results
assert.deepEqual(
{
root: upload.root,
root: upload.root.toString(),
shards: upload.shards?.map(String).sort(),
},
{
root,
root: root.toString(),
shards: cars.map((car) => car.cid.toString()).sort(),
}
)
Expand Down Expand Up @@ -579,8 +575,8 @@ export const test = {
(x) => x.root.toString() === root.toString()
)

assert.deepEqual(item?.root, root)
assert.deepEqual(item?.shards, [car.cid])
assert.deepEqual(item?.root.toString(), root.toString())
assert.deepEqual(item?.shards?.map(String), [car.cid.toString()])
assert.deepEqual(item?.updatedAt, item?.insertedAt)
}
},
Expand Down
Loading