chore: add e2e coverage for shared vault creation limitations (#2395)

This commit is contained in:
Karol Sójko
2023-08-08 09:41:16 +02:00
committed by GitHub
parent 4ca0e89fcd
commit 99b155cbf1
3 changed files with 75 additions and 1 deletions

View File

@@ -35,7 +35,7 @@ export class CreateSharedVault {
const serverResult = await this.sharedVaultServer.createSharedVault()
if (isErrorResponse(serverResult)) {
return ClientDisplayableError.FromString(`Failed to create shared vault ${JSON.stringify(serverResult)}`)
return ClientDisplayableError.FromString(`Failed to create shared vault: ${serverResult.data.error?.message}`)
}
const serverVaultHash = serverResult.data.sharedVault

View File

@@ -20,5 +20,6 @@ export const VaultTests = {
'vaults/permissions.test.js',
'vaults/key-rotation.test.js',
'vaults/files.test.js',
'vaults/limits.test.js',
],
}

View File

@@ -0,0 +1,73 @@
import * as Factory from '../lib/factory.js'
import * as Collaboration from '../lib/Collaboration.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('shared vault limits', function () {
this.timeout(Factory.TwentySecondTimeout)
let context
beforeEach(async function () {
localStorage.clear()
context = await Factory.createVaultsContextWithRealCrypto()
await context.launch()
await context.register()
})
afterEach(async function () {
await context.deinit()
localStorage.clear()
sinon.restore()
})
describe('free users', () => {
it('should not allow creating vaults over the limit', async () => {
const firstSharedVault = await Collaboration.createSharedVault(context)
expect(firstSharedVault).to.not.be.null
let caughtError = null
try {
await Collaboration.createSharedVault(context)
} catch (error) {
caughtError = error
}
expect(caughtError.message).to.equal('Failed to create shared vault: You have reached the limit of shared vaults for your account.')
})
})
describe('plus users', () => {
it('should not allow creating vaults over the limit', async () => {
context.activatePaidSubscriptionForUser({ subscriptionPlanName: 'PLUS_PLAN' })
for (let i = 0; i < 3; i++) {
const vault = await Collaboration.createSharedVault(context)
expect(vault).to.not.be.null
}
let caughtError = null
try {
await Collaboration.createSharedVault(context)
} catch (error) {
caughtError = error
}
expect(caughtError.message).to.equal('Failed to create shared vault: You have reached the limit of shared vaults for your account.')
})
})
describe('pro users', () => {
it('should allow creating vaults without limit', async () => {
context.activatePaidSubscriptionForUser()
for (let i = 0; i < 10; i++) {
const vault = await Collaboration.createSharedVault(context)
expect(vault).to.not.be.null
}
})
})
})