1 import { type WasmApiWalletAccount, WasmScriptType } from '@proton/andromeda';
2 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
3 import { getTestStore } from '@proton/redux-shared-store/test';
5 import { apiWalletsData } from '../../tests/fixtures';
6 import type { IWasmApiWalletData } from '../../types';
10 walletAccountCreation,
11 walletAccountDeletion,
16 } from './apiWalletsData';
18 describe('apiWalletsData', () => {
19 const setup = (data: IWasmApiWalletData[] = apiWalletsData) => {
20 const extraThunkArguments = {
22 return { Domains: [{ ID: '1' }] };
24 } as unknown as ProtonThunkArguments;
27 reducer: { ...apiWalletsDataReducer } as any,
29 api_wallets_data: { value: data, error: undefined },
35 describe('wallet creation', () => {
36 it('should add a wallet to the store', () => {
37 const { store } = setup([]);
38 store.dispatch(walletCreation(apiWalletsData[0]));
39 expect(selectApiWalletsData(store.getState()).value).toStrictEqual([apiWalletsData[0]]);
43 describe('wallet deletion', () => {
44 it('should remove a wallet from the store', () => {
45 const { store } = setup(apiWalletsData);
46 store.dispatch(walletDeletion({ walletID: apiWalletsData[1].Wallet.ID }));
47 expect(selectApiWalletsData(store.getState()).value).toStrictEqual([apiWalletsData[0], apiWalletsData[2]]);
51 describe('wallet name update', () => {
52 it('should update the name of the wallet in the store', () => {
53 const name = 'My super wallet';
54 const { store } = setup(apiWalletsData);
55 store.dispatch(walletUpdate({ walletID: apiWalletsData[1].Wallet.ID, update: { Name: name } }));
56 expect(selectApiWalletsData(store.getState()).value).toStrictEqual([
58 { ...apiWalletsData[1], Wallet: { ...apiWalletsData[1].Wallet, Name: name } },
64 describe('wallet account creation', () => {
65 it('should push a new wallet account in the store', () => {
66 const { store } = setup(apiWalletsData);
68 const account: WasmApiWalletAccount = {
69 WalletID: apiWalletsData[1].Wallet.ID,
72 Label: 'Account test 1',
73 ScriptType: WasmScriptType.NativeSegwit,
74 DerivationPath: "m/84'/0'/0'",
81 store.dispatch(walletAccountCreation(account));
83 expect(selectApiWalletsData(store.getState()).value?.[1].WalletAccounts).toStrictEqual([
84 ...apiWalletsData[1].WalletAccounts,
90 describe('wallet account deletion', () => {
91 it('should push a new wallet account in the store', () => {
92 const { store } = setup(apiWalletsData);
95 walletAccountDeletion({
96 walletID: apiWalletsData[1].Wallet.ID,
97 walletAccountID: apiWalletsData[1].WalletAccounts[0].ID,
101 expect(selectApiWalletsData(store.getState()).value?.[1].WalletAccounts).toStrictEqual([
102 apiWalletsData[1].WalletAccounts[1],
107 describe('wallet account update', () => {
108 it('should push a new wallet account in the store', () => {
109 const { store } = setup(apiWalletsData);
111 const account: WasmApiWalletAccount = {
112 ...apiWalletsData[1].WalletAccounts[0],
113 Label: 'A new test label',
115 Addresses: [{ ID: '00098', Email: 'test@test.com' }],
119 walletAccountUpdate({ walletID: account.WalletID, walletAccountID: account.ID, update: account })
122 expect(selectApiWalletsData(store.getState()).value?.[1].WalletAccounts).toStrictEqual([
124 apiWalletsData[1].WalletAccounts[1],