Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Nov 6, 2024
2 parents eb79808 + 670b1d6 commit c760934
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 87 deletions.
22 changes: 11 additions & 11 deletions src/frontend/src/tests/icp/validation/ic-token.validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ import {
isNotIcToken,
isNotIcTokenCanistersStrict
} from '$icp/validation/ic-token.validation';
import { validIcToken } from '$tests/mocks/ic-tokens.mock';
import { validToken } from '$tests/mocks/tokens.mock';
import { mockValidIcToken } from '$tests/mocks/ic-tokens.mock';
import { mockValidToken } from '$tests/mocks/tokens.mock';

describe('ic-token.validation', () => {
const validIcTokenWithIndex: IcToken = {
...validIcToken,
...mockValidIcToken,
indexCanisterId: IC_CKBTC_INDEX_CANISTER_ID
};

describe('isIcToken', () => {
it('should return true for a valid IcToken', () => {
expect(isIcToken(validIcToken)).toBe(true);
expect(isIcToken(mockValidIcToken)).toBe(true);
});

it('should return false for an invalid IcToken', () => {
expect(isIcToken(validToken)).toBe(false);
expect(isIcToken(mockValidToken)).toBe(false);
});
});

describe('isNotIcToken', () => {
it('should return false for a valid IcToken', () => {
expect(isNotIcToken(validIcToken)).toBe(false);
expect(isNotIcToken(mockValidIcToken)).toBe(false);
});

it('should return true for an invalid IcToken', () => {
expect(isNotIcToken(validToken)).toBe(true);
expect(isNotIcToken(mockValidToken)).toBe(true);
});
});

Expand All @@ -41,11 +41,11 @@ describe('ic-token.validation', () => {
});

it('should return false for a valid IcToken without strict canisters fields', () => {
expect(isIcTokenCanistersStrict(validIcToken)).toBe(false);
expect(isIcTokenCanistersStrict(mockValidIcToken)).toBe(false);
});

it('should return false for a token type casted to IcToken', () => {
expect(isIcTokenCanistersStrict(validToken as IcToken)).toBe(false);
expect(isIcTokenCanistersStrict(mockValidToken as IcToken)).toBe(false);
});
});

Expand All @@ -55,11 +55,11 @@ describe('ic-token.validation', () => {
});

it('should return true for a valid IcToken without strict canisters fields', () => {
expect(isNotIcTokenCanistersStrict(validIcToken)).toBe(true);
expect(isNotIcTokenCanistersStrict(mockValidIcToken)).toBe(true);
});

it('should return true for a token type casted to IcToken', () => {
expect(isNotIcTokenCanistersStrict(validToken as IcToken)).toBe(true);
expect(isNotIcTokenCanistersStrict(mockValidToken as IcToken)).toBe(true);
});
});
});
42 changes: 31 additions & 11 deletions src/frontend/src/tests/lib/utils/token.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
sumTokenBalances,
sumUsdBalances
} from '$lib/utils/token.utils';
import { $balances, bn1, bn2, bn3 } from '$tests/mocks/balances.mock';
import { $exchanges } from '$tests/mocks/exchanges.mock';
import { bn1, bn2, bn3, mockBalances } from '$tests/mocks/balances.mock';
import { mockExchanges } from '$tests/mocks/exchanges.mock';
import { BigNumber } from 'alchemy-sdk';
import type { MockedFunction } from 'vitest';

Expand Down Expand Up @@ -103,25 +103,37 @@ describe('calculateTokenUsdBalance', () => {
});

it('should correctly calculate USD balance for the token', () => {
const result = calculateTokenUsdBalance({ token: ETHEREUM_TOKEN, $balances, $exchanges });
const result = calculateTokenUsdBalance({
token: ETHEREUM_TOKEN,
$balances: mockBalances,
$exchanges: mockExchanges
});
expect(result).toEqual(bn3.toNumber());
});

it('should return undefined if exchange rate is not available', () => {
const result = calculateTokenUsdBalance({ token: ICP_TOKEN, $balances, $exchanges: {} });
const result = calculateTokenUsdBalance({
token: ICP_TOKEN,
$balances: mockBalances,
$exchanges: {}
});
expect(result).toEqual(undefined);
});

it('should return 0 if balances store is not available', () => {
const result = calculateTokenUsdBalance({ token: ETHEREUM_TOKEN, $balances: {}, $exchanges });
const result = calculateTokenUsdBalance({
token: ETHEREUM_TOKEN,
$balances: {},
$exchanges: mockExchanges
});
expect(result).toEqual(0);
});

it('should return 0 if balances store is undefined', () => {
const result = calculateTokenUsdBalance({
token: ETHEREUM_TOKEN,
$balances: undefined,
$exchanges
$exchanges: mockExchanges
});
expect(result).toEqual(0);
});
Expand All @@ -139,7 +151,11 @@ describe('mapTokenUi', () => {
});

it('should return an object TokenUi with the correct values', () => {
const result = mapTokenUi({ token: ETHEREUM_TOKEN, $balances, $exchanges });
const result = mapTokenUi({
token: ETHEREUM_TOKEN,
$balances: mockBalances,
$exchanges: mockExchanges
});
expect(result).toEqual({
...ETHEREUM_TOKEN,
balance: bn3,
Expand All @@ -148,7 +164,7 @@ describe('mapTokenUi', () => {
});

it('should return an object TokenUi with undefined usdBalance if exchange rate is not available', () => {
const result = mapTokenUi({ token: ETHEREUM_TOKEN, $balances, $exchanges: {} });
const result = mapTokenUi({ token: ETHEREUM_TOKEN, $balances: mockBalances, $exchanges: {} });
expect(result).toEqual({
...ETHEREUM_TOKEN,
balance: bn3,
Expand All @@ -157,7 +173,11 @@ describe('mapTokenUi', () => {
});

it('should return an object TokenUi with undefined balance if balances store is not initiated', () => {
const result = mapTokenUi({ token: ETHEREUM_TOKEN, $balances: undefined, $exchanges });
const result = mapTokenUi({
token: ETHEREUM_TOKEN,
$balances: undefined,
$exchanges: mockExchanges
});
expect(result).toEqual({
...ETHEREUM_TOKEN,
balance: undefined,
Expand All @@ -166,7 +186,7 @@ describe('mapTokenUi', () => {
});

it('should return an object TokenUi with undefined balance if balances store is not available', () => {
const result = mapTokenUi({ token: ETHEREUM_TOKEN, $balances: {}, $exchanges });
const result = mapTokenUi({ token: ETHEREUM_TOKEN, $balances: {}, $exchanges: mockExchanges });
expect(result).toEqual({
...ETHEREUM_TOKEN,
balance: undefined,
Expand All @@ -178,7 +198,7 @@ describe('mapTokenUi', () => {
const result = mapTokenUi({
token: ETHEREUM_TOKEN,
$balances: { [ETHEREUM_TOKEN.id]: null },
$exchanges
$exchanges: mockExchanges
});
expect(result).toEqual({
...ETHEREUM_TOKEN,
Expand Down
Loading

0 comments on commit c760934

Please sign in to comment.