diff --git a/packages/upload-api/package.json b/packages/upload-api/package.json index c19fa9217..6036ecc7f 100644 --- a/packages/upload-api/package.json +++ b/packages/upload-api/package.json @@ -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": { diff --git a/packages/upload-api/test/access-authorize.js b/packages/upload-api/test/access-authorize.js index 6eab52e70..9351aa75c 100644 --- a/packages/upload-api/test/access-authorize.js +++ b/packages/upload-api/test/access-authorize.js @@ -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, [ diff --git a/packages/upload-api/test/store.js b/packages/upload-api/test/store.js index 2c2b65d5e..abfcad735 100644 --- a/packages/upload-api/test/store.js +++ b/packages/upload-api/test/store.js @@ -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( @@ -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(), } @@ -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) @@ -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(), } diff --git a/packages/upload-api/test/upload.js b/packages/upload-api/test/upload.js index d8885a848..389e1b2e6 100644 --- a/packages/upload-api/test/upload.js +++ b/packages/upload-api/test/upload.js @@ -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) @@ -91,8 +92,8 @@ export const test = { } assert.deepEqual( - uploadAdd.out.ok, - { root, shards: [] }, + uploadAdd.out.ok.shards, + [], 'Should have an empty shards array' ) @@ -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 ( @@ -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(), } ) @@ -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) } },