Skip to content

Commit 19c238b

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

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

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

+18-32
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,9 @@ describe('WalletRepository', () => {
191191
});
192192

193193
describe('addAccount', () => {
194+
const accountIndex = storedLedgerWallet.accounts[storedLedgerWallet.accounts.length - 1].accountIndex + 1;
194195
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);
199197
const props = {
200198
...accountProps,
201199
walletId: storedLedgerWallet.walletId
@@ -213,41 +211,28 @@ describe('WalletRepository', () => {
213211
const storeSubject = new BehaviorSubject([storedLedgerWallet]);
214212
store.observeAll.mockReturnValue(storeSubject.asObservable());
215213

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);
221215
const standardProps = {
222216
...standardAccountProps,
223217
walletId: storedLedgerWallet.walletId
224218
};
219+
const walletWithStandardAccount = [
220+
{
221+
...storedLedgerWallet,
222+
accounts: [...storedLedgerWallet.accounts, standardAccountProps]
223+
}
224+
];
225225

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);
232227
const multiSigProps = {
233228
...multiSigAccountProps,
234229
walletId: storedLedgerWallet.walletId
235230
};
236231

237232
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);
244234

245-
storeSubject.next([
246-
{
247-
...storedLedgerWallet,
248-
accounts: [...storedLedgerWallet.accounts, standardAccountProps]
249-
}
250-
]);
235+
storeSubject.next(walletWithStandardAccount);
251236

252237
await expect(repository.addAccount(multiSigProps)).resolves.toEqual(multiSigProps);
253238
expect(store.setAll).toBeCalledWith([
@@ -345,7 +330,7 @@ describe('WalletRepository', () => {
345330
it('does not update 1852 account metadata when updating 1854 account', async () => {
346331
const storedAccount = storedLedgerWallet.accounts[0];
347332
const newAccount = createAccount(0, storedAccount.accountIndex, KeyPurpose.MULTI_SIG);
348-
const accounts = [storedLedgerWallet.accounts[0], newAccount];
333+
const accounts = [storedAccount, newAccount];
349334
store.observeAll.mockReturnValueOnce(of([{ ...storedLedgerWallet, accounts }]));
350335

351336
const props: UpdateAccountMetadataProps<WalletMetadata> = {
@@ -360,7 +345,7 @@ describe('WalletRepository', () => {
360345
{
361346
...storedLedgerWallet,
362347
accounts: [
363-
storedLedgerWallet.accounts[0],
348+
storedAccount,
364349
{
365350
...newAccount,
366351
metadata: newMetadata
@@ -425,8 +410,9 @@ describe('WalletRepository', () => {
425410
});
426411

427412
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];
430416
store.observeAll.mockReturnValueOnce(of([{ ...storedLedgerWallet, accounts }]));
431417

432418
const props = {
@@ -438,7 +424,7 @@ describe('WalletRepository', () => {
438424
expect(store.setAll).toBeCalledWith([
439425
{
440426
...storedLedgerWallet,
441-
accounts: [storedLedgerWallet.accounts[0]]
427+
accounts: [storedAccount]
442428
}
443429
]);
444430
});

0 commit comments

Comments
 (0)