Skip to content

Commit

Permalink
start testing providerAdd handler
Browse files Browse the repository at this point in the history
  • Loading branch information
gobengo committed Feb 28, 2023
1 parent 25c4e0e commit da6adb6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/access-api/src/service/provider-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import * as Ucanto from '@ucanto/interface'
export function createProviderAddHandler() {
/** @type {ProviderAddHandler} */
return async (invocation) => {
return {}
return {
error: true,
name: 'NotImplemented',
message: 'Provider add not implemented yet',
}
}
}
8 changes: 2 additions & 6 deletions packages/access-api/test/provider-add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for (const handlerVariant of /** @type {const} */ ([
.invoke({
issuer,
audience: await handlerVariant.audience,
with: issuer.did(),
with: `did:mailto:example.com:foo`,
nb: {
consumer: space.did(),
provider: 'did:web:web3.storage:providers:w3up-alpha',
Expand All @@ -52,11 +52,7 @@ for (const handlerVariant of /** @type {const} */ ([
.delegate()
)
warnOnErrorResult(result)
assert.notDeepEqual(
result.error,
true,
'provider/add result should not be error'
)
assert.deepEqual('name' in result && result.name, 'NotImplemented')
})
})
}
4 changes: 3 additions & 1 deletion packages/capabilities/src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export const StorageProvider = literal(
'did:web:web3.storage:providers:w3up-alpha'
)

export const AccountDID = DID.match({ method: 'mailto' })

/**
* Capability can be invoked by an agent to add a provider to a space.
*/
export const add = base.derive({
to: capability({
can: 'provider/add',
with: DID,
with: AccountDID,
nb: {
provider: StorageProvider,
consumer: URI.match({ protocol: 'did:' }),
Expand Down
3 changes: 3 additions & 0 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export type AccessSession = InferInvokedCapability<typeof AccessCaps.session>
// Provider
export type Provider = InferInvokedCapability<typeof provider.provider>
export type ProviderAdd = InferInvokedCapability<typeof provider.add>
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ProviderAddSuccess {}
export type ProviderAddFailure = Ucanto.Failure

// Space
export type Space = InferInvokedCapability<typeof space>
Expand Down

0 comments on commit da6adb6

Please sign in to comment.