From 3532c61c991ebbcc80a2f9cfab2e553e288da0c6 Mon Sep 17 00:00:00 2001 From: Joao Andrade Date: Fri, 31 May 2024 17:34:39 +0100 Subject: [PATCH] fix: address tests in the context of suffixing blob/get capability --- packages/upload-api/src/types.ts | 6 ++- packages/upload-client/src/types.ts | 6 ++- packages/upload-client/test/blob.test.js | 48 ++++++++++++-------- packages/upload-client/test/helpers/mocks.js | 7 ++- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/packages/upload-api/src/types.ts b/packages/upload-api/src/types.ts index c74b3e887..55ef6730f 100644 --- a/packages/upload-api/src/types.ts +++ b/packages/upload-api/src/types.ts @@ -325,7 +325,11 @@ export interface Service extends StorefrontService, W3sService { add: ServiceMethod remove: ServiceMethod list: ServiceMethod - get: ServiceMethod + get: { + 0: { + 1: ServiceMethod + } + } } } plan: { diff --git a/packages/upload-client/src/types.ts b/packages/upload-client/src/types.ts index a93b8a9e3..5677a4339 100644 --- a/packages/upload-client/src/types.ts +++ b/packages/upload-client/src/types.ts @@ -159,7 +159,11 @@ export interface Service extends StorefrontService { add: ServiceMethod remove: ServiceMethod list: ServiceMethod - get: ServiceMethod + get: { + 0: { + 1: ServiceMethod + } + } } index: { add: ServiceMethod diff --git a/packages/upload-client/test/blob.test.js b/packages/upload-client/test/blob.test.js index dd606946c..437c89c45 100644 --- a/packages/upload-client/test/blob.test.js +++ b/packages/upload-client/test/blob.test.js @@ -753,20 +753,24 @@ describe('Blob.get', () => { const service = mockService({ space: { blob: { - get: provide(BlobCapabilities.get, ({ invocation }) => { - assert.equal(invocation.issuer.did(), agent.did()) - assert.equal(invocation.capabilities.length, 1) - const invCap = invocation.capabilities[0] - assert.equal(invCap.can, BlobCapabilities.get.can) - assert.equal(invCap.with, space.did()) - assert.equal(String(invCap.nb?.digest), bytesHash.bytes) - return { - ok: { - cause: invocation.link(), - blob: { digest: bytesHash.bytes, size: bytes.length }, - }, - } - }), + get: { + 0: { + 1: provide(BlobCapabilities.get, ({ invocation }) => { + assert.equal(invocation.issuer.did(), agent.did()) + assert.equal(invocation.capabilities.length, 1) + const invCap = invocation.capabilities[0] + assert.equal(invCap.can, BlobCapabilities.get.can) + assert.equal(invCap.with, space.did()) + assert.equal(String(invCap.nb?.digest), bytesHash.bytes) + return { + ok: { + cause: invocation.link(), + blob: { digest: bytesHash.bytes, size: bytes.length }, + }, + } + }), + }, + }, }, }, }) @@ -789,8 +793,8 @@ describe('Blob.get', () => { { connection } ) - assert(service.space.blob.get.called) - assert.equal(service.space.blob.get.callCount, 1) + assert(service.space.blob.get[0][1].called) + assert.equal(service.space.blob.get[0][1].callCount, 1) assert(result.ok) assert.deepEqual(result.ok.blob.digest, bytesHash.bytes) @@ -814,9 +818,13 @@ describe('Blob.get', () => { const service = mockService({ space: { blob: { - get: provide(BlobCapabilities.get, () => { - throw new Server.Failure('boom') - }), + get: { + 0: { + 1: provide(BlobCapabilities.get, () => { + throw new Server.Failure('boom') + }), + }, + }, }, }, }) @@ -839,7 +847,7 @@ describe('Blob.get', () => { bytesHash, { connection } ), - { message: 'failed space/blob/get invocation' } + { message: 'failed space/blob/get/0/1 invocation' } ) }) }) diff --git a/packages/upload-client/test/helpers/mocks.js b/packages/upload-client/test/helpers/mocks.js index 381185e3a..e8530ccdd 100644 --- a/packages/upload-client/test/helpers/mocks.js +++ b/packages/upload-client/test/helpers/mocks.js @@ -18,6 +18,7 @@ const notImplemented = () => { * }>} impl */ export function mockService(impl) { + const get = impl.space?.blob?.get return { ucan: { conclude: withCallCount(impl.ucan?.conclude ?? notImplemented), @@ -27,7 +28,11 @@ export function mockService(impl) { add: withCallCount(impl.space?.blob?.add ?? notImplemented), list: withCallCount(impl.space?.blob?.list ?? notImplemented), remove: withCallCount(impl.space?.blob?.remove ?? notImplemented), - get: withCallCount(impl.space?.blob?.get ?? notImplemented), + get: { + 0: { + 1: withCallCount(get ? get[0][1] : notImplemented), + }, + }, }, index: { add: withCallCount(impl.space?.index?.add ?? notImplemented),