Files
standardnotes-app-web/packages/snjs/mocha/vaults/contacts.test.js
Karol Sójko eb062220d6 chore: fix endpoints and properties used in shared vaults to match the server (#2370)
* chore: upgrade @standardnotes/domain-core

* chore: enable vault tests by default

* chore: fix asymmetric messages paths

* chore: fix message property from user_uuid to recipient_uuid

* chore: fix server response properties for messages and notifications

* chore: fix user_uuid to recipient_uuid in resend all message use case

* chore: use notification payload and type from domain-core

* chore: fix non existent uuid in conflicts tests

* chore: use shared vault user permission from domain-core

* chore: enable all e2e tests

* chore: upgrade domain-core

* chore: mark failing tests as skipped

* chore: skip test

* chore: fix recipient_uuid in specs

* chore: skip test

* chore: skip test

* chore: skip test

* chore: skip test

* chore: fix remove unused var and unskip test

* Revert "chore: skip test"

This reverts commit 26bb876cf55e2c4fa9eeea56f73b3c2917a26f5c.

* chore: unskip passing tests

* chore: skip test

* chore: skip test

* fix: handle invite creation error

* chore: skip tests

* fix: disable vault tests to merge the PR

* chore: unskip asymmetric messages tests
2023-07-27 15:43:45 +02:00

107 lines
3.5 KiB
JavaScript

import * as Factory from '../lib/factory.js'
import * as Collaboration from '../lib/Collaboration.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('contacts', function () {
this.timeout(Factory.TwentySecondTimeout)
let context
afterEach(async function () {
await context.deinit()
localStorage.clear()
})
beforeEach(async function () {
localStorage.clear()
context = await Factory.createAppContextWithRealCrypto()
await context.launch()
await context.register()
})
it('should create contact', async () => {
const contact = await context.contacts.createOrEditTrustedContact({
name: 'John Doe',
publicKey: 'my_public_key',
signingPublicKey: 'my_signing_public_key',
contactUuid: '123',
})
expect(contact).to.not.be.undefined
expect(contact.name).to.equal('John Doe')
expect(contact.publicKeySet.encryption).to.equal('my_public_key')
expect(contact.publicKeySet.signing).to.equal('my_signing_public_key')
expect(contact.contactUuid).to.equal('123')
})
it('should create self contact on registration', async () => {
const selfContact = context.contacts.getSelfContact()
expect(selfContact).to.not.be.undefined
expect(selfContact.publicKeySet.encryption).to.equal(context.publicKey)
expect(selfContact.publicKeySet.signing).to.equal(context.signingPublicKey)
})
it('should create self contact on sign in if it does not exist', async () => {
let selfContact = context.contacts.getSelfContact()
await context.mutator.setItemToBeDeleted(selfContact)
await context.sync()
await context.signout()
await context.signIn()
selfContact = context.contacts.getSelfContact()
expect(selfContact).to.not.be.undefined
})
it('should update self contact on password change', async () => {
const selfContact = context.contacts.getSelfContact()
await context.changePassword('new_password')
const updatedSelfContact = context.contacts.getSelfContact()
expect(updatedSelfContact.publicKeySet.encryption).to.not.equal(selfContact.publicKeySet.encryption)
expect(updatedSelfContact.publicKeySet.signing).to.not.equal(selfContact.publicKeySet.signing)
expect(updatedSelfContact.publicKeySet.encryption).to.equal(context.publicKey)
expect(updatedSelfContact.publicKeySet.signing).to.equal(context.signingPublicKey)
})
it('should update self contact reference when changed', async () => {
const selfContact = context.contacts.getSelfContact()
await context.mutator.changeItem(selfContact, (mutator) => {
mutator.name = 'New Name'
})
const updatedSelfContact = context.contacts.getSelfContact()
expect(updatedSelfContact.name).to.equal('New Name')
})
it('should not be able to delete self contact', async () => {
const selfContact = context.contacts.getSelfContact()
await Factory.expectThrowsAsync(() => context.contacts.deleteContact(selfContact), 'Cannot delete self')
})
it('should not be able to delete a trusted contact if it belongs to a vault I administer', async () => {
const { contact, deinitContactContext } = await Collaboration.createSharedVaultWithAcceptedInvite(context)
const result = await context.contacts.deleteContact(contact)
expect(result.isFailed()).to.be.true
expect(result.getError()).to.equal('Cannot delete contact that belongs to an owned vault')
await deinitContactContext()
})
it.skip('should be able to refresh a contact using a collaborationID that includes full chain of previous public keys', async () => {
})
})