Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make plan/get return value is typed properly #1029

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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