|
1 | 1 | import chalk from 'chalk' |
2 | 2 | import inquirer from 'inquirer' |
3 | | -import { describeCommand, invokeTestCli } from '../utility' |
4 | 3 | import { createKeyValue } from '../../src/utils/text' |
| 4 | +import { describeCommand, invokeTestCli } from '../utility' |
| 5 | +import { getStampOption } from '../utility/stamp' |
| 6 | + |
| 7 | +describeCommand('Postage stamp prompt', ({ consoleMessages, getNthLastMessage }) => { |
| 8 | + describe('Price estimation', () => { |
| 9 | + it('stamp buy should prompt for price confirmation', async () => { |
| 10 | + jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: false }) |
| 11 | + await invokeTestCli(['stamp', 'buy', '--depth', '24', '--amount', '596046400']) |
| 12 | + expect(consoleMessages[0]).toBe(createKeyValue('Estimated cost', '0.9999999198822400 xBZZ')) |
| 13 | + expect(consoleMessages[1]).toBe(createKeyValue('Estimated capacity', '40.084 GB')) |
| 14 | + expect(consoleMessages[2]).toBe(createKeyValue('Estimated TTL', '34 hours')) |
| 15 | + expect(inquirer.prompt).toHaveBeenCalledWith({ |
| 16 | + message: 'Confirm the purchase', |
| 17 | + name: 'value', |
| 18 | + prefix: chalk.bold.cyan('?'), |
| 19 | + type: 'confirm', |
| 20 | + }) |
| 21 | + }) |
| 22 | + }) |
5 | 23 |
|
6 | | -describeCommand('Postage stamp price estimation prompt', ({ consoleMessages }) => { |
7 | | - it('stamp buy should prompt for price confirmation', async () => { |
8 | | - jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: false }) |
9 | | - await invokeTestCli(['stamp', 'buy', '--depth', '24', '--amount', '596046400']) |
10 | | - expect(consoleMessages[0]).toBe(createKeyValue('Estimated cost', '0.9999999198822400 xBZZ')) |
11 | | - expect(consoleMessages[1]).toBe(createKeyValue('Estimated capacity', '40.084 GB')) |
12 | | - expect(consoleMessages[2]).toBe(createKeyValue('Estimated TTL', '34 hours')) |
13 | | - expect(inquirer.prompt).toHaveBeenCalledWith({ |
14 | | - message: 'Confirm the purchase', |
15 | | - name: 'value', |
16 | | - prefix: chalk.bold.cyan('?'), |
17 | | - type: 'confirm', |
| 24 | + describe('Rename postage stamp', () => { |
| 25 | + it('should prompt for new name', async () => { |
| 26 | + jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'new-stamp-name' }) |
| 27 | + await invokeTestCli(['stamp', 'rename', ...getStampOption()]) |
| 28 | + expect(getNthLastMessage(2)).toContain( |
| 29 | + `Postage stamp ${getStampOption()[1]} has been successfully renamed to 'new-stamp-name'`, |
| 30 | + ) |
| 31 | + expect(inquirer.prompt).toHaveBeenCalledWith({ |
| 32 | + message: 'Please provide a new label for the postage stamp:', |
| 33 | + name: 'value', |
| 34 | + prefix: chalk.bold.cyan('?'), |
| 35 | + }) |
18 | 36 | }) |
19 | 37 | }) |
20 | 38 | }) |
0 commit comments