Skip to content

Commit

Permalink
chore: add e2e coverage for shared vault creation limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsojko committed Aug 8, 2023
1 parent 4ca0e89 commit ab5552c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/snjs/mocha/TestRegistry/VaultTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export const VaultTests = {
'vaults/permissions.test.js',
'vaults/key-rotation.test.js',
'vaults/files.test.js',
'vaults/limits.test.js',
],
}
73 changes: 73 additions & 0 deletions packages/snjs/mocha/vaults/limits.test.js
Original file line number Diff line number Diff line change
@@ -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
}
})
})
})

0 comments on commit ab5552c

Please sign in to comment.