From 0b9ad7f2af135508d98ad39e6c314b640b9ecb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20B=C3=A9k=C3=A9si?= Date: Wed, 8 Jul 2026 14:10:56 +0200 Subject: [PATCH 1/2] feat: rename command for stamp --- src/command/stamp/index.ts | 3 ++- src/command/stamp/rename.ts | 33 ++++++++++++++++++++++++++++++++ test/prompt/stamp-prompt.spec.ts | 18 ++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/command/stamp/rename.ts diff --git a/src/command/stamp/index.ts b/src/command/stamp/index.ts index f38e0f1c..2896c0dc 100644 --- a/src/command/stamp/index.ts +++ b/src/command/stamp/index.ts @@ -4,6 +4,7 @@ import { Create } from './create' import { Dilute } from './dilute' import { Extend } from './extend' import { List } from './list' +import { Rename } from './rename' import { Show } from './show' import { Topup } from './topup' @@ -12,5 +13,5 @@ export class Stamp implements GroupCommand { public readonly description = 'Buy, list and show postage stamps' - public subCommandClasses = [List, Create, Extend, Buy, Show, Dilute, Topup] + public subCommandClasses = [List, Create, Extend, Buy, Show, Dilute, Topup, Rename] } diff --git a/src/command/stamp/rename.ts b/src/command/stamp/rename.ts new file mode 100644 index 00000000..e0b6794b --- /dev/null +++ b/src/command/stamp/rename.ts @@ -0,0 +1,33 @@ +import { Argument, LeafCommand, Option } from 'furious-commander' +import { pickStamp } from '../../service/stamp' +import { stampProperties } from '../../utils/option' +import { StampCommand } from './stamp-command' + +export class Rename extends StampCommand implements LeafCommand { + public readonly name = 'rename' + + public readonly description = 'Rename a postage stamp' + + @Argument({ key: 'label', description: 'New label for the postage stamp' }) + public label!: string + + @Option(stampProperties) + public stamp!: string + + public async run(): Promise { + super.init() + + if (!this.stamp) { + this.stamp = await pickStamp(this.bee, this.console) + } + + if (!this.label) { + this.label = await this.console.askForValue('Please provide a new label for the postage stamp:') + } + + await this.bee.updatePostageBatchLabel(this.stamp, this.label) + + this.console.log(`Postage stamp ${this.stamp} has been successfully renamed to '${this.label}'`) + this.console.log(`Check it later with swarm-cli stamp show ${this.stamp}`) + } +} diff --git a/test/prompt/stamp-prompt.spec.ts b/test/prompt/stamp-prompt.spec.ts index e4641c85..84e908ca 100644 --- a/test/prompt/stamp-prompt.spec.ts +++ b/test/prompt/stamp-prompt.spec.ts @@ -1,7 +1,8 @@ import chalk from 'chalk' import inquirer from 'inquirer' -import { describeCommand, invokeTestCli } from '../utility' import { createKeyValue } from '../../src/utils/text' +import { describeCommand, invokeTestCli } from '../utility' +import { getStampOption } from '../utility/stamp' describeCommand('Postage stamp price estimation prompt', ({ consoleMessages }) => { it('stamp buy should prompt for price confirmation', async () => { @@ -18,3 +19,18 @@ describeCommand('Postage stamp price estimation prompt', ({ consoleMessages }) = }) }) }) + +describeCommand('Rename postage stamp prompt', ({ getNthLastMessage }) => { + it('stamp rename should prompt for new name', async () => { + jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'new-stamp-name' }) + await invokeTestCli(['stamp', 'rename', ...getStampOption()]) + expect(getNthLastMessage(2)).toContain( + `Postage stamp ${getStampOption()[1]} has been successfully renamed to 'new-stamp-name'`, + ) + expect(inquirer.prompt).toHaveBeenCalledWith({ + message: 'Please provide a new label for the postage stamp:', + name: 'value', + prefix: chalk.bold.cyan('?'), + }) + }) +}) From 01bd178b545b599e93a7c51d9cbf38926ac282d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20B=C3=A9k=C3=A9si?= Date: Wed, 8 Jul 2026 14:23:26 +0200 Subject: [PATCH 2/2] fix: specs --- src/command/stamp/rename.ts | 2 +- test/prompt/stamp-prompt.spec.ts | 50 +++++++++++++++++--------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/command/stamp/rename.ts b/src/command/stamp/rename.ts index e0b6794b..5434f8f8 100644 --- a/src/command/stamp/rename.ts +++ b/src/command/stamp/rename.ts @@ -6,7 +6,7 @@ import { StampCommand } from './stamp-command' export class Rename extends StampCommand implements LeafCommand { public readonly name = 'rename' - public readonly description = 'Rename a postage stamp' + public readonly description = 'Update the label of a postage stamp' @Argument({ key: 'label', description: 'New label for the postage stamp' }) public label!: string diff --git a/test/prompt/stamp-prompt.spec.ts b/test/prompt/stamp-prompt.spec.ts index 84e908ca..836d1b49 100644 --- a/test/prompt/stamp-prompt.spec.ts +++ b/test/prompt/stamp-prompt.spec.ts @@ -4,33 +4,35 @@ import { createKeyValue } from '../../src/utils/text' import { describeCommand, invokeTestCli } from '../utility' import { getStampOption } from '../utility/stamp' -describeCommand('Postage stamp price estimation prompt', ({ consoleMessages }) => { - it('stamp buy should prompt for price confirmation', async () => { - jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: false }) - await invokeTestCli(['stamp', 'buy', '--depth', '24', '--amount', '596046400']) - expect(consoleMessages[0]).toBe(createKeyValue('Estimated cost', '0.9999999198822400 xBZZ')) - expect(consoleMessages[1]).toBe(createKeyValue('Estimated capacity', '40.084 GB')) - expect(consoleMessages[2]).toBe(createKeyValue('Estimated TTL', '34 hours')) - expect(inquirer.prompt).toHaveBeenCalledWith({ - message: 'Confirm the purchase', - name: 'value', - prefix: chalk.bold.cyan('?'), - type: 'confirm', +describeCommand('Postage stamp prompt', ({ consoleMessages, getNthLastMessage }) => { + describe('Price estimation', () => { + it('stamp buy should prompt for price confirmation', async () => { + jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: false }) + await invokeTestCli(['stamp', 'buy', '--depth', '24', '--amount', '596046400']) + expect(consoleMessages[0]).toBe(createKeyValue('Estimated cost', '0.9999999198822400 xBZZ')) + expect(consoleMessages[1]).toBe(createKeyValue('Estimated capacity', '40.084 GB')) + expect(consoleMessages[2]).toBe(createKeyValue('Estimated TTL', '34 hours')) + expect(inquirer.prompt).toHaveBeenCalledWith({ + message: 'Confirm the purchase', + name: 'value', + prefix: chalk.bold.cyan('?'), + type: 'confirm', + }) }) }) -}) -describeCommand('Rename postage stamp prompt', ({ getNthLastMessage }) => { - it('stamp rename should prompt for new name', async () => { - jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'new-stamp-name' }) - await invokeTestCli(['stamp', 'rename', ...getStampOption()]) - expect(getNthLastMessage(2)).toContain( - `Postage stamp ${getStampOption()[1]} has been successfully renamed to 'new-stamp-name'`, - ) - expect(inquirer.prompt).toHaveBeenCalledWith({ - message: 'Please provide a new label for the postage stamp:', - name: 'value', - prefix: chalk.bold.cyan('?'), + describe('Rename postage stamp', () => { + it('should prompt for new name', async () => { + jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'new-stamp-name' }) + await invokeTestCli(['stamp', 'rename', ...getStampOption()]) + expect(getNthLastMessage(2)).toContain( + `Postage stamp ${getStampOption()[1]} has been successfully renamed to 'new-stamp-name'`, + ) + expect(inquirer.prompt).toHaveBeenCalledWith({ + message: 'Please provide a new label for the postage stamp:', + name: 'value', + prefix: chalk.bold.cyan('?'), + }) }) }) })