Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

[WIP] tests: add methods params unit tests #782

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion jest.config.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
module.exports = {
rootDir: './',
moduleFileExtensions: ['js'],
testMatch: ['**/src/js/**/*.test.(js)'],
testMatch: ['**/src/js/**/*.test.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/src/js/device/_old/'],
coverageDirectory: './coverage/',
collectCoverage: true,
collectCoverageFrom: [
'<rootDir>/src/js/**',
'!**/constants/**',
'!**/__tests__/**',
'!**/__fixtures__/**',
],
modulePathIgnorePatterns: ['node_modules'],
setupFiles: ['./tests/jest.setup.js'],
transform: {
Expand Down
91 changes: 91 additions & 0 deletions src/js/core/methods/__fixtures__/params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
export const fixtures = {
applySettings: [
{
description: 'language param invalid type',
params: { language: 1 },
error: 'Parameter "language" has invalid type. "string" expected.',
},
{
description: 'success',
params: { language: 'en' },
},
],
applyFlags: [
{
description: 'missing flags param',
params: { foo: 1 },
error: 'Parameter "flags" is missing.',
},
{
description: 'flags param invalid type',
params: { flags: '1' },
error: 'Parameter "flags" has invalid type. "number" expected.',
},
{
description: 'success',
params: { flags: 1 },
},
],
backupDevice: [],
binanceGetAddress: [],
binanceGetPublicKey: [],
binanceSignTransaction: [],
blockchainDisconnect: [],
blockchainEstimateFee: [],
blockchainGetAccountBalanceHistory: [],
blockchainGetCurrentFiatRates: [],
blockchainGetFiatRatesForTimestamps: [],
blockchainGetTransactions: [],
blockchainSetCustomBackend: [],
blockchainSubscribe: [],
blockchainSubscribeFiatRates: [],
blockchainUnsubscribe: [],
blockchainUnsubscribeFiatRates: [],
cardanoGetAddress: [],
cardanoGetPublicKey: [],
cardanoSignTransaction: [],
changePin: [],
cipherKeyValue: [],
composeTransaction: [],
customMessage: [],
debugLinkDecision: [],
debugLinkGetState: [],
eosGetPublicKey: [],
eosSignTransaction: [],
ethereumGetAddress: [],
ethereumGetPublicKey: [],
ethereumSignMessage: [],
ethereumSignTransaction: [],
ethereumVerifyMessage: [],
firmwareUpdate: [],
getAccountInfo: [],
getAddress: [],
getCoinInfo: [],
getDeviceState: [],
getFeatures: [],
getPublicKey: [],
getSettings: [],
liskGetAddress: [],
liskGetPublicKey: [],
liskSignMessage: [],
liskSignTransaction: [],
liskVerifyMessage: [],
loadDevice: [],
nemGetAddress: [],
nemSignTransaction: [],
pushTransaction: [],
recoveryDevice: [],
requestLogin: [],
resetDevice: [],
rippleGetAddress: [],
rippleSignTransaction: [],
signMessage: [],
signTransaction: [],
stellarGetAddress: [],
stellarSignTransaction: [],
tezosGetAddress: [],
tezosGetPublicKey: [],
tezosSignTransaction: [],
verifyMessage: [],
wipeDevice: [],
};
30 changes: 30 additions & 0 deletions src/js/core/methods/__tests__/params.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { find } from '../index';
import { fixtures } from '../__fixtures__/params';
import coinsJSON from '../../../../data/coins.json';
import { parseCoinsJson } from '../../../data/CoinInfo';

describe('core/methods params validation', () => {
beforeAll(() => {
parseCoinsJson(coinsJSON);
});
Object.keys(fixtures).forEach(key => {
fixtures[key].forEach(f => {
it(`${key}: ${f.description}`, () => {
try {
const method = find({
id: 0,
payload: {
method: key,
...f.params,
},
});
method.device = {
unavailableCapabilities: {},
};
} catch (error) {
expect(error.message).toBe(f.error);
}
});
});
});
});