Skip to content

Commit 8e33019

Browse files
committed
test(web-extension): use behaviour subject to update store state between assertions
1 parent 271064a commit 8e33019

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/web-extension/test/walletManager/WalletRepository.test.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
WalletRepositoryDependencies,
1212
WalletType
1313
} from '../../src';
14+
import { BehaviorSubject, firstValueFrom, of } from 'rxjs';
1415
import { Cardano, Serialization } from '@cardano-sdk/core';
1516
import { Hash28ByteBase16 } from '@cardano-sdk/crypto';
1617
import { KeyPurpose, KeyRole } from '@cardano-sdk/key-management';
17-
import { firstValueFrom, of } from 'rxjs';
1818
import { logger } from '@cardano-sdk/util-dev';
1919
import pick from 'lodash/pick';
2020

@@ -210,6 +210,9 @@ describe('WalletRepository', () => {
210210
});
211211

212212
it('allows creating 1852 and 1854 purpose account with the same index', async () => {
213+
const storeSubject = new BehaviorSubject([storedLedgerWallet]);
214+
store.observeAll.mockReturnValue(storeSubject.asObservable());
215+
213216
const standardAccountProps = createAccount(
214217
0,
215218
storedLedgerWallet.accounts[storedLedgerWallet.accounts.length - 1].accountIndex + 1,
@@ -220,14 +223,14 @@ describe('WalletRepository', () => {
220223
walletId: storedLedgerWallet.walletId
221224
};
222225

223-
const multiSigAccountProps2 = createAccount(
226+
const multiSigAccountProps = createAccount(
224227
0,
225228
storedLedgerWallet.accounts[storedLedgerWallet.accounts.length - 1].accountIndex + 1,
226229
KeyPurpose.MULTI_SIG
227230
);
228231

229232
const multiSigProps = {
230-
...multiSigAccountProps2,
233+
...multiSigAccountProps,
231234
walletId: storedLedgerWallet.walletId
232235
};
233236

@@ -239,11 +242,18 @@ describe('WalletRepository', () => {
239242
}
240243
]);
241244

245+
storeSubject.next([
246+
{
247+
...storedLedgerWallet,
248+
accounts: [...storedLedgerWallet.accounts, standardAccountProps]
249+
}
250+
]);
251+
242252
await expect(repository.addAccount(multiSigProps)).resolves.toEqual(multiSigProps);
243253
expect(store.setAll).toBeCalledWith([
244254
{
245255
...storedLedgerWallet,
246-
accounts: [...storedLedgerWallet.accounts, multiSigAccountProps2]
256+
accounts: [...storedLedgerWallet.accounts, standardAccountProps, multiSigAccountProps]
247257
}
248258
]);
249259
});
@@ -333,7 +343,8 @@ describe('WalletRepository', () => {
333343
});
334344

335345
it('does not update 1852 account metadata when updating 1854 account', async () => {
336-
const newAccount = createAccount(0, 1, KeyPurpose.MULTI_SIG);
346+
const storedAccount = storedLedgerWallet.accounts[0];
347+
const newAccount = createAccount(0, storedAccount.accountIndex, KeyPurpose.MULTI_SIG);
337348
const accounts = [storedLedgerWallet.accounts[0], newAccount];
338349
store.observeAll.mockReturnValueOnce(of([{ ...storedLedgerWallet, accounts }]));
339350

0 commit comments

Comments
 (0)