|
1 | 1 | import { Command } from 'commander'; |
2 | | -import path from 'path'; |
3 | 2 | import AElf from 'aelf-sdk'; |
4 | 3 | import inquirer from 'inquirer'; |
5 | 4 | import { CallCommand } from '../../src/command'; |
@@ -196,3 +195,64 @@ describe('CallCommand', () => { |
196 | 195 | inquirer.prompt = backup; |
197 | 196 | }); |
198 | 197 | }); |
| 198 | + |
| 199 | +describe('run call method when only account is provided', () => { |
| 200 | + let callCommand; |
| 201 | + let mockCommander; |
| 202 | + let mockOraInstance; |
| 203 | + let mockInquirer; |
| 204 | + let getWallet; |
| 205 | + let AElf; |
| 206 | + beforeEach(() => { |
| 207 | + jest.resetModules(); |
| 208 | + jest.mock('inquirer'); |
| 209 | + jest.mock('../../src/utils/wallet.js'); |
| 210 | + jest.mock('aelf-sdk'); |
| 211 | + mockInquirer = require('inquirer'); |
| 212 | + mockOraInstance = { |
| 213 | + start: jest.fn(), |
| 214 | + succeed: jest.fn(), |
| 215 | + fail: jest.fn() |
| 216 | + }; |
| 217 | + getWallet = require('../../src/utils/wallet.js').getWallet; |
| 218 | + AElf = require('aelf-sdk'); |
| 219 | + mockCommander = { |
| 220 | + name: 'call', |
| 221 | + opts: jest.fn(() => ({ |
| 222 | + account, |
| 223 | + endpoint: endPoint, |
| 224 | + datadir: dataDir, |
| 225 | + password: null |
| 226 | + })) |
| 227 | + }; |
| 228 | + |
| 229 | + callCommand = new CallCommand(sampleRc, 'call', 'Test description', [], [], []); |
| 230 | + callCommand.oraInstance = mockOraInstance; |
| 231 | + }); |
| 232 | + afterEach(() => { |
| 233 | + jest.resetAllMocks(); |
| 234 | + }); |
| 235 | + test('should prompt for password when only account is provided', async () => { |
| 236 | + // Mock getWallet to ensure it's called correctly |
| 237 | + getWallet.mockReturnValueOnce({ |
| 238 | + address: 'testAddress' |
| 239 | + }); |
| 240 | + |
| 241 | + // Mock AElf instance creation |
| 242 | + AElf.providers.HttpProvider.mockImplementation(() => ({ |
| 243 | + send: jest.fn() |
| 244 | + })); |
| 245 | + inquirer.prompt = jest.fn(); |
| 246 | + // Run the method |
| 247 | + await callCommand.run(mockCommander); |
| 248 | + // Assertions |
| 249 | + expect(inquirer.prompt).toHaveBeenCalledWith( |
| 250 | + expect.objectContaining({ |
| 251 | + type: 'password', |
| 252 | + name: 'password', |
| 253 | + message: 'Please enter your password:', |
| 254 | + mask: '*' |
| 255 | + }) |
| 256 | + ); |
| 257 | + }); |
| 258 | +}); |
0 commit comments