From ba80989fdf26b5527f6cc92a7370107d304d2e22 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 16 Nov 2023 06:52:42 +0300 Subject: [PATCH 1/2] chore: create a test case --- packages/w3up-client/test/account.test.js | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/w3up-client/test/account.test.js b/packages/w3up-client/test/account.test.js index 9336b682c..dcde14e91 100644 --- a/packages/w3up-client/test/account.test.js +++ b/packages/w3up-client/test/account.test.js @@ -228,6 +228,37 @@ export const testAccount = { assert.deepEqual(client.currentSpace()?.did(), space.did()) }, + + 'skip redundant logins': async ( + assert, + { client, mail, grantAccess, plansStorage } + ) => { + const email = 'alice@web.mail' + const sessions = [] + for (const _ of Array(3)) { + const login = Account.login(client, email) + // do not grant access right away so we end up with distinct sessions + await new Promise((resolve) => setTimeout(resolve, 1000)) + await grantAccess(await mail.take()) + const account = Result.try(await login) + sessions.push(account) + } + + // we create temporary account sessions and then save them to avoid + // login idempotence. + for (const session of sessions) { + Result.try(await session.save()) + } + + const account = Object.values(client.accounts())[0] + assert.equal(account.proofs.length, 6, 'should have 6 proofs') + + // setup a billing for this account + plansStorage.set(account.did(), client.agent.connection.id.did()) + + const space = await client.createSpace('test') + account.provision(space.did()) + }, } Test.test({ Account: testAccount }) From 6ac6af2c47a55325481625d9cdfcae55d3c5c412 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 16 Nov 2023 06:56:45 +0300 Subject: [PATCH 2/2] chore: make test more configurable --- packages/w3up-client/test/account.test.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/w3up-client/test/account.test.js b/packages/w3up-client/test/account.test.js index dcde14e91..2c4e57d13 100644 --- a/packages/w3up-client/test/account.test.js +++ b/packages/w3up-client/test/account.test.js @@ -229,13 +229,14 @@ export const testAccount = { assert.deepEqual(client.currentSpace()?.did(), space.did()) }, - 'skip redundant logins': async ( + 'only redundant logins': async ( assert, { client, mail, grantAccess, plansStorage } ) => { const email = 'alice@web.mail' const sessions = [] - for (const _ of Array(3)) { + const pairs = 2 + for (const _ of Array(pairs)) { const login = Account.login(client, email) // do not grant access right away so we end up with distinct sessions await new Promise((resolve) => setTimeout(resolve, 1000)) @@ -251,7 +252,11 @@ export const testAccount = { } const account = Object.values(client.accounts())[0] - assert.equal(account.proofs.length, 6, 'should have 6 proofs') + assert.equal( + account.proofs.length, + pairs * 2, + `should have ${pairs * 2} proofs` + ) // setup a billing for this account plansStorage.set(account.did(), client.agent.connection.id.did())