diff --git a/test/helpers/up-client.js b/test/helpers/up-client.js index 1f866fcb..fe27ee05 100644 --- a/test/helpers/up-client.js +++ b/test/helpers/up-client.js @@ -22,7 +22,7 @@ function getAuthLinkFromEmail (email, accessServiceUrl) { return link.replace(process.env.ACCESS_SERVICE_URL, accessServiceUrl) } -async function createMailSlurpInbox() { +export async function createMailSlurpInbox() { const apiKey = process.env.MAILSLURP_API_KEY const mailslurp = new MailSlurp({ apiKey }) const inbox = await mailslurp.inboxController.createInbox({}) @@ -46,7 +46,7 @@ export async function createNewClient(uploadServiceUrl) { export async function setupNewClient (uploadServiceUrl, options = {}) { // create an inbox - const { mailslurp, id: inboxId, email } = await createMailSlurpInbox() + const { mailslurp, id: inboxId, email } = options.inbox || await createMailSlurpInbox() const client = await createNewClient(uploadServiceUrl) const timeoutMs = process.env.MAILSLURP_TIMEOUT ? parseInt(process.env.MAILSLURP_TIMEOUT) : 60_000 diff --git a/test/integration.test.js b/test/integration.test.js index 56f48b6c..a2b9a5bc 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -19,7 +19,7 @@ import { getCarparkBucketInfo, getDynamoDb } from './helpers/deployment.js' -import { createNewClient, setupNewClient } from './helpers/up-client.js' +import { createMailSlurpInbox, createNewClient, setupNewClient } from './helpers/up-client.js' import { randomFile } from './helpers/random.js' import { getTableItem, getAllTableRows, pollQueryTable } from './helpers/table.js' @@ -116,12 +116,18 @@ test('authorizations can be blocked by email or domain', async t => { // Integration test for all flow from uploading a file to Kinesis events consumers and replicator test('w3infra integration flow', async t => { - const client = await setupNewClient(t.context.apiEndpoint) + const inbox = await createMailSlurpInbox() + const client = await setupNewClient(t.context.apiEndpoint, { inbox }) const spaceDid = client.currentSpace()?.did() if (!spaceDid) { throw new Error('Testing space DID must be set') } + // it should be possible to create more than one space + const space = await client.createSpace("2nd space") + await client.setCurrentSpace(space.did()) + await client.registerSpace(inbox.email) + // Get space metrics before upload const spaceBeforeUploadAddMetrics = await getSpaceMetrics(t, spaceDid, SPACE_METRICS_NAMES.UPLOAD_ADD_TOTAL) const spaceBeforeStoreAddMetrics = await getSpaceMetrics(t, spaceDid, SPACE_METRICS_NAMES.STORE_ADD_TOTAL) diff --git a/upload-api/stores/provisions.js b/upload-api/stores/provisions.js index 2f673706..ddec6a01 100644 --- a/upload-api/stores/provisions.js +++ b/upload-api/stores/provisions.js @@ -4,16 +4,14 @@ import { CBOR, Failure } from '@ucanto/server' /** * Create a subscription ID for a given provision. Currently - * uses the CID of `customer` which ensures each customer - * will get at most one subscription. This can be relaxed (ie, - * by deriving subscription ID from customer AND consumer) in the future - * or by other providers for flexibility. + * uses a CID generated from `consumer` which ensures a space + * can be provisioned at most once. * * @param {import('@web3-storage/upload-api').Provision} item * @returns string */ -export const createProvisionSubscriptionId = async ({ customer }) => - (await CBOR.write({ customer })).cid.toString() +export const createProvisionSubscriptionId = async ({ customer, consumer }) => + (await CBOR.write({ consumer })).cid.toString() /** * @param {import('../types').SubscriptionTable} subscriptionTable