Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 16, 2024
1 parent 2988a9b commit 870af09
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/w3up-client/src/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ export class AccountPlan {
* or when the abort signal is aborted.
*
* @param {object} [options]
* @param {number} [options.interval=1000] - The polling interval in milliseconds (default is 1000ms).
* @param {number} [options.timeout=900000] - The maximum time to wait in milliseconds before throwing a timeout error (default is 15 minutes).
* @param {number} [options.interval] - The polling interval in milliseconds (default is 1000ms).
* @param {number} [options.timeout] - The maximum time to wait in milliseconds before throwing a timeout error (default is 15 minutes).
* @param {AbortSignal} [options.signal] - An optional AbortSignal to cancel the waiting process.
* @returns {Promise<import('@web3-storage/access').PlanGetSuccess>} - Resolves once a payment plan is selected within the timeout.
* @throws {Error} - Throws an error if there is an issue retrieving the payment plan or if the timeout is exceeded.
Expand Down
8 changes: 7 additions & 1 deletion packages/w3up-client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export class Client extends Base {
* In addition, it authorizes the listed Gateway Services to serve content from the created space.
* It is done by delegating the `space/content/serve/*` capability to the Gateway Service.
* User can skip the Gateway authorization by setting the `skipGatewayAuthorization` option to `true`.
* If no gateways are specified or the `skipGatewayAuthorization` flag is not set, the client will automatically grant access
* to the Storacha Gateway by default (https://freewaying.dag.haus/).
*
* @typedef {import('./types.js').ConnectionView<import('./types.js').ContentServeService>} ConnectionView
*
Expand Down Expand Up @@ -315,12 +317,14 @@ export class Client extends Base {
id: {
did: () =>
/** @type {`did:${string}:${string}`} */ (
/* c8 ignore next - default prod gateway id is not used in tests */
process.env.DEFAULT_GATEWAY_ID ?? 'did:web:w3s.link'
),
},
codec: CAR.outbound,
channel: HTTP.open({
url: new URL(
/* c8 ignore next - default prod gateway url is not used in tests */
process.env.DEFAULT_GATEWAY_URL ?? 'https://freeway.dag.haus'
),
}),
Expand Down Expand Up @@ -627,7 +631,9 @@ export const authorizeContentServe = async (
/* c8 ignore next 8 - can't mock this error */
if (verificationResult.out.error) {
throw new Error(
`failed to publish delegation for audience ${options.audience}: ${verificationResult.out.error.message}`,
`failed to publish delegation for audience ${audience.did()}: ${
verificationResult.out.error.message
}`,
{
cause: verificationResult.out.error,
}
Expand Down
1 change: 0 additions & 1 deletion packages/w3up-client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ export const testClient = {
},
'should authorize the Storacha Gateway Service when no Gateway Services are provided':
async (assert, { mail, grantAccess, connection }) => {
Test
// Step 1: Create a client for Alice and login
const aliceClient = new Client(
await AgentData.create({
Expand Down
21 changes: 11 additions & 10 deletions packages/w3up-client/test/helpers/gateway-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ const server = createServer(async (req, res) => {
if (req.method === 'OPTIONS') return res.end()

if (req.method === 'POST') {
console.time('Service Setup')
const service = getContentServeMockService()
const server = createUcantoServer(gateway, service)
console.timeEnd('Service Setup')

console.time('Collect Request Body')
const bodyBuffer = Buffer.concat(await collect(req))
console.timeEnd('Collect Request Body')

console.time('Server Request')
const reqHeaders = /** @type {Record<string, string>} */ (
Object.fromEntries(Object.entries(req.headers))
)

const { headers, body, status } = await server.request({
body: new Uint8Array(
bodyBuffer.buffer,
bodyBuffer.byteOffset,
bodyBuffer.byteLength
),
headers: /** @type {Record<string, string>} */ (
Object.fromEntries(Object.entries(req.headers))
),
headers: reqHeaders,
})
console.timeEnd('Server Request')
return new Response(body, { headers, status: status ?? 200 })

for (const [key, value] of Object.entries(headers)) {
res.setHeader(key, value)
}
res.writeHead(status ?? 200)
res.end(body)
}
res.end()
})
Expand Down
2 changes: 1 addition & 1 deletion packages/w3up-client/test/mocks/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getContentServeMockService(result = { ok: {} }) {
return {
access: {
delegate: Server.provide(AccessCaps.Access.delegate, async (data) => {
console.log('Access Caps Delegate', data)
// console.log('Access Caps Delegate', data)
return result
}),
},
Expand Down

0 comments on commit 870af09

Please sign in to comment.