Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
@@ -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
}
})
})
})