From e88e75423b627e0a1b327ceded8ae249e91df1f9 Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Fri, 23 Aug 2024 16:17:42 +0800 Subject: [PATCH] feat: unit test csv --- jest.config.js | 2 +- test/command/call.test.js | 22 +++++++++++++++++++++- test/command/proposal.test.js | 2 -- test/constants.js | 1 + test/test.csv | 3 +++ 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/test.csv diff --git a/jest.config.js b/jest.config.js index 58bb7d5..f8e3fac 100644 --- a/jest.config.js +++ b/jest.config.js @@ -146,7 +146,7 @@ export default { // The glob patterns Jest uses to detect test files testMatch: [ - // '**/test/utils/Logger.test.js' + // '**/test/command/proposal.test.js' '**/test/command/dappServer/socket-sign.test.js', '**/test/**/?(*.)+(spec|test).[jt]s?(x)' // "**/?(*.)+(spec|test).[tj]s?(x)" diff --git a/test/command/call.test.js b/test/command/call.test.js index e4e52af..dcfc744 100644 --- a/test/command/call.test.js +++ b/test/command/call.test.js @@ -7,7 +7,7 @@ import { callCommandUsages, callCommandParameters } from '../../src/utils/consta import { getContractInstance } from '../../src/utils/utils.js'; import { userHomeDir } from '../../src/utils/userHomeDir.js'; import { logger } from '../../src/utils/myLogger.js'; -import { endpoint as endPoint, account, password, dataDir } from '../constants.js'; +import { endpoint as endPoint, account, password, dataDir, csvDir } from '../constants.js'; const sampleRc = { getConfigs: jest.fn() }; jest.mock('../../src/utils/myLogger'); @@ -102,6 +102,26 @@ describe('CallCommand', () => { expect(logger.info).toHaveBeenCalled(); }); + test('should run with csv', async () => { + inquirer.prompt = questions => + Promise.resolve({ + symbol: 'ELF', + owner: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk' + }); + const commander = new Command(); + commander.option('-e, --endpoint ', 'The URI of an AElf node. Eg: http://127.0.0.1:8000'); + commander.option('-a, --account ', 'The address of AElf wallet'); + commander.option('-p, --password ', 'The password of encrypted keyStore'); + commander.option( + '-d, --datadir ', + `The directory that contains the AElf related files. Default to be ${userHomeDir}/aelf` + ); + commander.option('-c, --csv ', 'The location of the CSV file containing the parameters.'); + commander.parse([process.argv[0], '', 'call', '-e', endPoint, '-a', account, '-p', password, '-d', dataDir, '-c', csvDir]); + await callCommand.run(commander, 'AElf.ContractNames.Token', 'GetBalance'); + expect(logger.info).toHaveBeenCalled(); + }); + test('should run with invalid parameters', async () => { inquirer.prompt = backup; callCommand = new CallCommand(sampleRc, 'call', 'Call a read-only method on a contract.', [ diff --git a/test/command/proposal.test.js b/test/command/proposal.test.js index e1bf002..1703561 100644 --- a/test/command/proposal.test.js +++ b/test/command/proposal.test.js @@ -1,9 +1,7 @@ /* eslint-disable max-len */ import { Command } from 'commander'; -import path from 'path'; import inquirer from 'inquirer'; import AElf from 'aelf-sdk'; -import chalk from 'chalk'; import moment from 'moment'; import ProposalCommand from '../../src/command/proposal.js'; import { userHomeDir } from '../../src/utils/userHomeDir.js'; diff --git a/test/constants.js b/test/constants.js index 943dc4e..14f8e0e 100644 --- a/test/constants.js +++ b/test/constants.js @@ -4,3 +4,4 @@ export const endpoint = 'https://tdvw-test-node.aelf.io/'; export const account = 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk'; export const password = '1234*Qwer'; export const dataDir = path.resolve(__dirname, './dataDir/aelf'); +export const csvDir = path.resolve(__dirname, './test.csv'); diff --git a/test/test.csv b/test/test.csv new file mode 100644 index 0000000..d326ec4 --- /dev/null +++ b/test/test.csv @@ -0,0 +1,3 @@ +symbol,"owner +" +ELF,GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk