diff --git a/jest.config.unit.js b/jest.config.unit.js index 2c94f4b1b..c3f994e02 100644 --- a/jest.config.unit.js +++ b/jest.config.unit.js @@ -5,10 +5,16 @@ module.exports = { rootDir: './', moduleFileExtensions: ['js'], - testMatch: ['**/src/js/**/*.test.(js)'], + testMatch: ['**/src/js/**/*.test.js'], testPathIgnorePatterns: ['/node_modules/', '/src/js/device/_old/'], coverageDirectory: './coverage/', collectCoverage: true, + collectCoverageFrom: [ + '/src/js/**', + '!**/constants/**', + '!**/__tests__/**', + '!**/__fixtures__/**', + ], modulePathIgnorePatterns: ['node_modules'], setupFiles: ['./tests/jest.setup.js'], transform: { diff --git a/src/js/core/methods/__fixtures__/params.js b/src/js/core/methods/__fixtures__/params.js new file mode 100644 index 000000000..2e336907a --- /dev/null +++ b/src/js/core/methods/__fixtures__/params.js @@ -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: [], +}; diff --git a/src/js/core/methods/__tests__/params.test.js b/src/js/core/methods/__tests__/params.test.js new file mode 100644 index 000000000..bb015f75e --- /dev/null +++ b/src/js/core/methods/__tests__/params.test.js @@ -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); + } + }); + }); + }); +});