-
-
Notifications
You must be signed in to change notification settings - Fork 393
/
ProcessAcceptedVaultInvite.spec.ts
63 lines (53 loc) · 2.35 KB
/
ProcessAcceptedVaultInvite.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { CreateOrEditContact } from './../../Contacts/UseCase/CreateOrEditContact'
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
import { ProcessAcceptedVaultInvite } from './ProcessAcceptedVaultInvite'
import { SyncServiceInterface } from '../../Sync/SyncServiceInterface'
import { ContentType } from '@standardnotes/domain-core'
import {
AsymmetricMessagePayloadType,
AsymmetricMessageSharedVaultInvite,
KeySystemRootKeyContent,
} from '@standardnotes/models'
describe('ProcessAcceptedVaultInvite', () => {
let mutator: jest.Mocked<MutatorClientInterface>
let sync: jest.Mocked<SyncServiceInterface>
let createOrEditContact: jest.Mocked<CreateOrEditContact>
beforeEach(() => {
mutator = {} as jest.Mocked<MutatorClientInterface>
mutator.createItem = jest.fn()
sync = {} as jest.Mocked<SyncServiceInterface>
sync.sync = jest.fn()
createOrEditContact = {} as jest.Mocked<CreateOrEditContact>
createOrEditContact.execute = jest.fn()
})
it('should create root key before creating vault listing so that propagated vault listings do not appear as locked', async () => {
const handleTrustedSharedVaultInviteMessage = new ProcessAcceptedVaultInvite(mutator, sync, createOrEditContact)
createOrEditContact
const testMessage = {
type: AsymmetricMessagePayloadType.SharedVaultInvite,
data: {
recipientUuid: 'test-recipient-uuid',
rootKey: {
systemIdentifier: 'test-system-identifier',
} as jest.Mocked<KeySystemRootKeyContent>,
metadata: {
name: 'test-name',
iconString: 'safe-square',
fileBytesUsed: 0,
designatedSurvivor: null,
},
trustedContacts: [],
},
} as jest.Mocked<AsymmetricMessageSharedVaultInvite>
const sharedVaultUuid = 'test-shared-vault-uuid'
const senderUuid = 'test-sender-uuid'
await handleTrustedSharedVaultInviteMessage.execute(testMessage, sharedVaultUuid, senderUuid)
const keySystemRootKeyCallIndex = mutator.createItem.mock.calls.findIndex(
([contentType]) => contentType === ContentType.TYPES.KeySystemRootKey,
)
const vaultListingCallIndex = mutator.createItem.mock.calls.findIndex(
([contentType]) => contentType === ContentType.TYPES.VaultListing,
)
expect(keySystemRootKeyCallIndex).toBeLessThan(vaultListingCallIndex)
})
})