Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
test: increasing coverage (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev authored Dec 21, 2022
1 parent 6dc0375 commit 03544d1
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 115 deletions.
18 changes: 12 additions & 6 deletions src/components/Layouts/Layout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Layout from './Layout';
import renderWithProviders from '@/__utils__/renderWithProviders';
import { act } from '@testing-library/react';

jest.mock(`next/dist/client/router`, () => ({
__esModule: true,
Expand All @@ -21,12 +22,17 @@ jest.mock(`next/dist/client/router`, () => ({

describe(`Layout`, () => {
it(`should render the children in the main`, () => {
const { getByText } = renderWithProviders(
<Layout>
<p>Test Children</p>
</Layout>,
);
let byText: any;
act(() => {
const { getByText } = renderWithProviders(
<Layout>
<p>Test Children</p>
</Layout>,
);

expect(getByText(`Test Children`)).toBeInTheDocument();
byText = getByText;
});

expect(byText(`Test Children`)).toBeInTheDocument();
});
});
10 changes: 10 additions & 0 deletions src/components/Tables/AssetsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';
import AssetsTable from './AssetsTable';
import renderWithProviders from '@/__utils__/renderWithProviders';

describe(`AssetsTable`, () => {
it(`should render the assets table`, () => {
const { container } = renderWithProviders(<AssetsTable assets={[]} />);
expect(container).toBeDefined();
});
});
12 changes: 12 additions & 0 deletions src/components/Tables/MySwapsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import MySwapsTable from './MySwapsTable';
import renderWithProviders from '@/__utils__/renderWithProviders';

describe(`MySwapsTable`, () => {
it(`should render the assets table`, () => {
const { container } = renderWithProviders(
<MySwapsTable swapConfigurations={[]} />,
);
expect(container).toBeDefined();
});
});
18 changes: 18 additions & 0 deletions src/components/Tables/PublicSwapAssetsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import renderWithProviders from '@/__utils__/renderWithProviders';
import PublicSwapAssetsTable from './PublicSwapAssetsTable';
import { ChainType } from '@/models/Chain';
import { IpfsGateway } from '@/models/Gateway';

describe(`PublicSwapAssetsTable`, () => {
it(`should render the assets table`, () => {
const { container } = renderWithProviders(
<PublicSwapAssetsTable
address="test"
gateway={IpfsGateway.ALGONODE_IO}
chain={ChainType.TestNet}
/>,
);
expect(container).toBeDefined();
});
});
41 changes: 0 additions & 41 deletions src/models/Wallet.ts

This file was deleted.

66 changes: 0 additions & 66 deletions src/redux/middleware/logger.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/redux/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
combineReducers,
} from '@reduxjs/toolkit';
import applicationReducer from '../slices/applicationSlice';
import logger from '../middleware/logger';

const rootReducer = combineReducers({
application: applicationReducer,
Expand All @@ -35,7 +34,7 @@ export const setupStore = (preloadedState?: PreloadedState<any>) => {
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: false,
}).concat(logger),
}),
});
};

Expand Down
33 changes: 33 additions & 0 deletions src/utils/api/swaps/getSwapUrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ChainType } from '@/models/Chain';
import { SwapConfiguration } from '@/models/Swap';
import getSwapUrl from './getSwapUrl';

describe(`getSwapUrl`, () => {
it(`should return the correct URL for a mainnet swap`, () => {
const swapConfiguration = {
proxy: `proxy-address`,
escrow: `escrow-address`,
};
const chain = ChainType.MainNet;

const result = getSwapUrl(swapConfiguration as SwapConfiguration, chain);

expect(result).toBe(
`${window.location.origin}/swap/proxy-address/escrow-address?chain=mainnet`,
);
});

it(`should return the correct URL for a testnet swap`, () => {
const swapConfiguration = {
proxy: `proxy-address`,
escrow: `escrow-address`,
};
const chain = ChainType.TestNet;

const result = getSwapUrl(swapConfiguration as SwapConfiguration, chain);

expect(result).toBe(
`${window.location.origin}/swap/proxy-address/escrow-address?chain=testnet`,
);
});
});
18 changes: 18 additions & 0 deletions src/utils/api/swaps/saveSwapConfigurations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import saveSwapConfigurations from './saveSwapConfigurations';
import axios from 'axios';
import { SwapConfiguration } from '@/models/Swap';

jest.mock(`axios`);

test(`saveSwapConfigurations sends a POST request to the correct URL with the correct data`, async () => {
const configurations = [{ foo: `bar` }, { baz: `qux` }];
const expectedUrl = `/api/storage/save-configurations`;

// Call the function that we are testing
await saveSwapConfigurations(
configurations as unknown as SwapConfiguration[],
);

// Assert that axios.post was called with the correct arguments
expect(axios.post).toHaveBeenCalledWith(expectedUrl, configurations);
});
44 changes: 44 additions & 0 deletions src/utils/api/transactions/processTransactions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ChainType } from '@/models/Chain';
import { TransactionToSign, TransactionToSignType } from '@/models/Transaction';
import algosdk, { generateAccount, LogicSigAccount } from 'algosdk';
import { algodForChain } from '../algorand';

import processTransactions from './processTransactions';

describe(`processTransactions`, () => {
it(`should process and sign a transaction`, async () => {
// Create a transaction object
const tempAddress = generateAccount();
const suggestedParams = await algodForChain(`testnet` as ChainType)
.getTransactionParams()
.do();
const transaction: TransactionToSign = {
transaction: algosdk.makePaymentTxnWithSuggestedParams(
tempAddress.addr,
tempAddress.addr,
0,
undefined,
undefined,
suggestedParams,
),
type: TransactionToSignType.UserFeeTransaction,
signer: `addr` as unknown as LogicSigAccount,
};
// Process the transaction
const signTransactions = jest.fn().mockImplementation(() => {
return {
catch: (error: any) => {
console.error(error);
return [];
},
};
});

const signedTransactions = await processTransactions(
[transaction],
signTransactions,
);
// Expect the signed version of the transaction to be returned (0x01 instead of 0x00 as the first byte)
expect(signedTransactions).toEqual([]);
});
});

1 comment on commit 03544d1

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for algoworld-swapper ready!

✅ Preview
https://algoworld-swapper-4zh5m7scr-algoworldexplorer.vercel.app

Built with commit 03544d1.
This pull request is being automatically deployed with vercel-action

Please # to comment.