-
Notifications
You must be signed in to change notification settings - Fork 103
/
api.test.ts
103 lines (89 loc) · 3.35 KB
/
api.test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { AccountMock } from '@mocks/account.mock'
import '@mocks/crypto.mock'
import { MOCK_MNEMONIC, ProfileManagerMock } from '@mocks/profile-manager.mock'
import { get } from 'svelte/store'
import { generateRandomId } from '@core/utils'
import { destroyProfileManager } from '../actions'
import {
generateMnemonic,
setStrongholdPassword,
storeMnemonic,
verifyMnemonic,
backup,
restoreBackup,
createAccount,
} from '../api'
import { profileManager } from '../stores'
describe('File: api.test.ts', () => {
let profileManagerMock: ProfileManagerMock
let spy: jest.SpyInstance
const password = 'password'
beforeEach(() => {
const id = generateRandomId()
profileManagerMock = new ProfileManagerMock(id)
profileManager.set(profileManagerMock)
})
it('should setup the profile manager correctly', () => {
expect(profileManager).toBeDefined()
})
it('should destroy the profile manager correctly', () => {
destroyProfileManager()
expect(get(profileManager)).toBeNull()
})
describe('Function: generateMnemonic', () => {
it('should execute generateMnemonic correctly', async () => {
spy = jest.spyOn(profileManagerMock, 'generateMnemonic')
const actual = await generateMnemonic()
expect(actual).toEqual(MOCK_MNEMONIC)
expect(spy).toHaveBeenCalledTimes(1)
spy.mockRestore()
})
})
describe('Function: setStrongholdPassword', () => {
it('should call setStrongholdPassword', async () => {
spy = jest.spyOn(profileManagerMock, 'setStrongholdPassword')
await setStrongholdPassword(password)
expect(spy).toBeCalledWith(password)
expect(spy).toBeCalledTimes(1)
spy.mockRestore()
})
})
describe('Function: storeMnemonic', () => {
it('should execute storeMnemonic', async () => {
spy = jest.spyOn(profileManagerMock, 'storeMnemonic')
await storeMnemonic(MOCK_MNEMONIC)
expect(spy).toBeCalledWith(MOCK_MNEMONIC)
expect(spy).toBeCalledTimes(1)
spy.mockRestore()
})
})
describe('Function: verifyMnemonic', () => {
it('should call verifyMnemonic', async () => {
spy = jest.spyOn(profileManagerMock, 'verifyMnemonic')
await verifyMnemonic(MOCK_MNEMONIC)
expect(spy).toBeCalledWith(MOCK_MNEMONIC)
expect(spy).toBeCalledTimes(1)
spy.mockRestore()
})
})
describe('Function: backup', () => {
it('should call backup', async () => {
spy = jest.spyOn(profileManagerMock, 'backup')
const destination = './destination'
await backup(destination, password)
expect(spy).toBeCalledWith(destination, password)
expect(spy).toBeCalledTimes(1)
spy.mockRestore()
})
})
describe('Function: restoreBackup', () => {
it('should call restoreBackup', async () => {
spy = jest.spyOn(profileManagerMock, 'restoreBackup')
const importFilePath = './backup.stronghold'
await restoreBackup(importFilePath, password)
expect(spy).toBeCalledWith(importFilePath, password)
expect(spy).toBeCalledTimes(1)
spy.mockRestore()
})
})
})