@@ -191,11 +191,9 @@ describe('WalletRepository', () => {
191
191
} ) ;
192
192
193
193
describe ( 'addAccount' , ( ) => {
194
+ const accountIndex = storedLedgerWallet . accounts [ storedLedgerWallet . accounts . length - 1 ] . accountIndex + 1 ;
194
195
it ( 'adds account to an existing wallet and returns AccountId that also contains walletId' , async ( ) => {
195
- const accountProps = createAccount (
196
- 0 ,
197
- storedLedgerWallet . accounts [ storedLedgerWallet . accounts . length - 1 ] . accountIndex + 1
198
- ) ;
196
+ const accountProps = createAccount ( 0 , accountIndex ) ;
199
197
const props = {
200
198
...accountProps ,
201
199
walletId : storedLedgerWallet . walletId
@@ -213,41 +211,28 @@ describe('WalletRepository', () => {
213
211
const storeSubject = new BehaviorSubject ( [ storedLedgerWallet ] ) ;
214
212
store . observeAll . mockReturnValue ( storeSubject . asObservable ( ) ) ;
215
213
216
- const standardAccountProps = createAccount (
217
- 0 ,
218
- storedLedgerWallet . accounts [ storedLedgerWallet . accounts . length - 1 ] . accountIndex + 1 ,
219
- KeyPurpose . STANDARD
220
- ) ;
214
+ const standardAccountProps = createAccount ( 0 , accountIndex , KeyPurpose . STANDARD ) ;
221
215
const standardProps = {
222
216
...standardAccountProps ,
223
217
walletId : storedLedgerWallet . walletId
224
218
} ;
219
+ const walletWithStandardAccount = [
220
+ {
221
+ ...storedLedgerWallet ,
222
+ accounts : [ ...storedLedgerWallet . accounts , standardAccountProps ]
223
+ }
224
+ ] ;
225
225
226
- const multiSigAccountProps = createAccount (
227
- 0 ,
228
- storedLedgerWallet . accounts [ storedLedgerWallet . accounts . length - 1 ] . accountIndex + 1 ,
229
- KeyPurpose . MULTI_SIG
230
- ) ;
231
-
226
+ const multiSigAccountProps = createAccount ( 0 , accountIndex , KeyPurpose . MULTI_SIG ) ;
232
227
const multiSigProps = {
233
228
...multiSigAccountProps ,
234
229
walletId : storedLedgerWallet . walletId
235
230
} ;
236
231
237
232
await expect ( repository . addAccount ( standardProps ) ) . resolves . toEqual ( standardProps ) ;
238
- expect ( store . setAll ) . toBeCalledWith ( [
239
- {
240
- ...storedLedgerWallet ,
241
- accounts : [ ...storedLedgerWallet . accounts , standardAccountProps ]
242
- }
243
- ] ) ;
233
+ expect ( store . setAll ) . toBeCalledWith ( walletWithStandardAccount ) ;
244
234
245
- storeSubject . next ( [
246
- {
247
- ...storedLedgerWallet ,
248
- accounts : [ ...storedLedgerWallet . accounts , standardAccountProps ]
249
- }
250
- ] ) ;
235
+ storeSubject . next ( walletWithStandardAccount ) ;
251
236
252
237
await expect ( repository . addAccount ( multiSigProps ) ) . resolves . toEqual ( multiSigProps ) ;
253
238
expect ( store . setAll ) . toBeCalledWith ( [
@@ -345,7 +330,7 @@ describe('WalletRepository', () => {
345
330
it ( 'does not update 1852 account metadata when updating 1854 account' , async ( ) => {
346
331
const storedAccount = storedLedgerWallet . accounts [ 0 ] ;
347
332
const newAccount = createAccount ( 0 , storedAccount . accountIndex , KeyPurpose . MULTI_SIG ) ;
348
- const accounts = [ storedLedgerWallet . accounts [ 0 ] , newAccount ] ;
333
+ const accounts = [ storedAccount , newAccount ] ;
349
334
store . observeAll . mockReturnValueOnce ( of ( [ { ...storedLedgerWallet , accounts } ] ) ) ;
350
335
351
336
const props : UpdateAccountMetadataProps < WalletMetadata > = {
@@ -360,7 +345,7 @@ describe('WalletRepository', () => {
360
345
{
361
346
...storedLedgerWallet ,
362
347
accounts : [
363
- storedLedgerWallet . accounts [ 0 ] ,
348
+ storedAccount ,
364
349
{
365
350
...newAccount ,
366
351
metadata : newMetadata
@@ -425,8 +410,9 @@ describe('WalletRepository', () => {
425
410
} ) ;
426
411
427
412
it ( 'does not remove 1852 account when removing 1854 account' , async ( ) => {
428
- const newAccount = createAccount ( 0 , 1 , KeyPurpose . MULTI_SIG ) ;
429
- const accounts = [ storedLedgerWallet . accounts [ 0 ] , newAccount ] ;
413
+ const storedAccount = storedLedgerWallet . accounts [ 0 ] ;
414
+ const newAccount = createAccount ( 0 , storedAccount . accountIndex , KeyPurpose . MULTI_SIG ) ;
415
+ const accounts = [ storedAccount , newAccount ] ;
430
416
store . observeAll . mockReturnValueOnce ( of ( [ { ...storedLedgerWallet , accounts } ] ) ) ;
431
417
432
418
const props = {
@@ -438,7 +424,7 @@ describe('WalletRepository', () => {
438
424
expect ( store . setAll ) . toBeCalledWith ( [
439
425
{
440
426
...storedLedgerWallet ,
441
- accounts : [ storedLedgerWallet . accounts [ 0 ] ]
427
+ accounts : [ storedAccount ]
442
428
}
443
429
] ) ;
444
430
} ) ;
0 commit comments