Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/cashMethods.test.js
import { fromSmallestDenomination, formatBalance } from '@utils/cashMethods'; | import { | ||||
fromSmallestDenomination, | |||||
formatBalance, | |||||
batchArray, | |||||
flattenBatchedHydratedUtxos, | |||||
} from '@utils/cashMethods'; | |||||
import { | |||||
unbatchedArray, | |||||
arrayBatchedByThree, | |||||
} from '../__mocks__/mockBatchedArrays'; | |||||
import { | |||||
originalFinal, | |||||
batchedFinal, | |||||
unflattenedHydrateUtxosResponse, | |||||
flattenedHydrateUtxosResponse, | |||||
} from '../__mocks__/flattenBatchedHydratedUtxosMocks'; | |||||
describe('Correctly executes cash utility functions', () => { | describe('Correctly executes cash utility functions', () => { | ||||
it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { | it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { | ||||
expect(fromSmallestDenomination(1, 2)).toBe(0.01); | expect(fromSmallestDenomination(1, 2)).toBe(0.01); | ||||
}); | }); | ||||
it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { | it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { | ||||
expect(fromSmallestDenomination(1000000012345678, 2)).toBe( | expect(fromSmallestDenomination(1000000012345678, 2)).toBe( | ||||
10000000123456.78, | 10000000123456.78, | ||||
Show All 22 Lines | it(`formatBalance handles an input of 0`, () => { | ||||
expect(formatBalance('0')).toBe('0'); | expect(formatBalance('0')).toBe('0'); | ||||
}); | }); | ||||
it(`formatBalance handles an input of undefined`, () => { | it(`formatBalance handles an input of undefined`, () => { | ||||
expect(formatBalance(undefined)).toBe(undefined); | expect(formatBalance(undefined)).toBe(undefined); | ||||
}); | }); | ||||
it(`formatBalance handles an input of null`, () => { | it(`formatBalance handles an input of null`, () => { | ||||
expect(formatBalance(null)).toBe(null); | expect(formatBalance(null)).toBe(null); | ||||
}); | }); | ||||
it(`Correctly converts an array of length 10 to an array of 4 arrays, each with max length 3`, () => { | |||||
expect(batchArray(unbatchedArray, 3)).toStrictEqual( | |||||
arrayBatchedByThree, | |||||
); | |||||
}); | |||||
it(`If array length is less than batch size, return original array as first and only element of new array`, () => { | |||||
expect(batchArray(unbatchedArray, 20)).toStrictEqual([unbatchedArray]); | |||||
}); | |||||
it(`Flattens hydrateUtxos from Promise.all() response into array that can be parsed by getSlpBalancesAndUtxos`, () => { | |||||
expect( | |||||
flattenBatchedHydratedUtxos(unflattenedHydrateUtxosResponse), | |||||
).toStrictEqual(flattenedHydrateUtxosResponse); | |||||
}); | |||||
}); | }); |