Skip to content

Commit

Permalink
feat: unit test csv
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Aug 23, 2024
1 parent baef086 commit e88e754
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
22 changes: 21 additions & 1 deletion test/command/call.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 <URI>', 'The URI of an AElf node. Eg: http://127.0.0.1:8000');
commander.option('-a, --account <account>', 'The address of AElf wallet');
commander.option('-p, --password <password>', 'The password of encrypted keyStore');
commander.option(
'-d, --datadir <directory>',
`The directory that contains the AElf related files. Default to be ${userHomeDir}/aelf`
);
commander.option('-c, --csv <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.', [
Expand Down
2 changes: 0 additions & 2 deletions test/command/proposal.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
3 changes: 3 additions & 0 deletions test/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
symbol,"owner
"
ELF,GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk

0 comments on commit e88e754

Please sign in to comment.