Skip to content

Commit

Permalink
fix: make plan/get return value is typed properly (#1029)
Browse files Browse the repository at this point in the history
set up the service with expected types
  • Loading branch information
travis authored Oct 27, 2023
1 parent f6828ec commit 075e341
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/access-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import type {
UCANRevoke,
UCANRevokeSuccess,
UCANRevokeFailure,
PlanGet,
PlanGetSuccess,
PlanGetFailure,
} from '@web3-storage/capabilities/types'
import type { SetRequired } from 'type-fest'
import { Driver } from './drivers/types.js'
Expand Down Expand Up @@ -86,6 +89,9 @@ export interface Service {
ucan: {
revoke: ServiceMethod<UCANRevoke, UCANRevokeSuccess, UCANRevokeFailure>
}
plan: {
get: ServiceMethod<PlanGet, PlanGetSuccess, PlanGetFailure>
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/access-client/test/agent-use-cases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ describe('authorizeWaitAndClaim', async function () {
describe('getAccountPlan', async function () {
const accountWithAPlan = 'did:mailto:example.com:i-have-a-plan'
const accountWithoutAPlan = 'did:mailto:example.com:i-have-no-plan'

const product = 'did:web:test.web3.storage'
/** @type {Record<Ucanto.DID, {product: Ucanto.DID, updatedAt: string}>} */
const plans = {
[accountWithAPlan]: {
product: 'did:web:test.web3.storage',
product,
updatedAt: new Date().toISOString(),
},
}
Expand Down Expand Up @@ -242,6 +242,7 @@ describe('getAccountPlan', async function () {
it('should succeed for accounts with plans', async function () {
const result = await getAccountPlan(agent, accountWithAPlan)
assert(result.ok)
assert.equal(result.ok.product, product)
})

it('should fail for accounts without a plan', async function () {
Expand Down

0 comments on commit 075e341

Please sign in to comment.