Skip to content

Commit

Permalink
fix: address tests in the context of suffixing blob/get capability
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosa committed May 31, 2024
1 parent 0030e0c commit 3532c61
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
6 changes: 5 additions & 1 deletion packages/upload-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ export interface Service extends StorefrontService, W3sService {
add: ServiceMethod<BlobAdd, BlobAddSuccess, BlobAddFailure>
remove: ServiceMethod<BlobRemove, BlobRemoveSuccess, BlobRemoveFailure>
list: ServiceMethod<BlobList, BlobListSuccess, BlobListFailure>
get: ServiceMethod<BlobGet, BlobGetSuccess, BlobGetFailure>
get: {
0: {
1: ServiceMethod<BlobGet, BlobGetSuccess, BlobGetFailure>
}
}
}
}
plan: {
Expand Down
6 changes: 5 additions & 1 deletion packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ export interface Service extends StorefrontService {
add: ServiceMethod<BlobAdd, BlobAddSuccess, BlobAddFailure>
remove: ServiceMethod<BlobRemove, BlobRemoveSuccess, BlobRemoveFailure>
list: ServiceMethod<BlobList, BlobListSuccess, BlobListFailure>
get: ServiceMethod<BlobGet, BlobGetSuccess, BlobGetFailure>
get: {
0: {
1: ServiceMethod<BlobGet, BlobGetSuccess, BlobGetFailure>
}
}
}
index: {
add: ServiceMethod<IndexAdd, IndexAddSuccess, IndexAddFailure>
Expand Down
48 changes: 28 additions & 20 deletions packages/upload-client/test/blob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
}
}),
},
},
},
},
})
Expand All @@ -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)
Expand All @@ -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')
}),
},
},
},
},
})
Expand All @@ -839,7 +847,7 @@ describe('Blob.get', () => {
bytesHash,
{ connection }
),
{ message: 'failed space/blob/get invocation' }
{ message: 'failed space/blob/get/0/1 invocation' }
)
})
})
7 changes: 6 additions & 1 deletion packages/upload-client/test/helpers/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 3532c61

Please sign in to comment.