diff --git a/jest.config.ts b/jest.config.ts index 83b66806..b6be5d57 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -55,7 +55,7 @@ export default async (): Promise => { } return { - collectCoverage: true, + collectCoverage: process.env.SKIP_COVERAGE !== 'true', coverageDirectory: 'coverage', coverageReporters: ['lcov', 'json-summary'], collectCoverageFrom: ['src/**/*.ts'], diff --git a/package-lock.json b/package-lock.json index 49ce685c..a6c63f15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -93,7 +93,6 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.20.2.tgz", "integrity": "sha512-w7DbG8DtMrJcFOi4VrLm+8QM4az8Mo+PuLBKLp2zrYRCow8W/f9xiXm5sN53C8HksCyDQwCKha9JiDoIyPjT2g==", "dev": true, - "peer": true, "dependencies": { "@ampproject/remapping": "^2.1.0", "@babel/code-frame": "^7.18.6", @@ -2995,7 +2994,6 @@ "integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -3070,7 +3068,6 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.44.0.tgz", "integrity": "sha512-j5ULd7FmmekcyWeArx+i8x7sdRHzAtXTkmDPthE4amxZOWKFK7bomoJ4r7PJ8K7PoMzD16U8MmuZFAonr1ERvw==", "dev": true, - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "5.44.0", "@typescript-eslint/type-utils": "5.44.0", @@ -3104,7 +3101,6 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.44.0.tgz", "integrity": "sha512-H7LCqbZnKqkkgQHaKLGC6KUjt3pjJDx8ETDqmwncyb6PuoigYajyAwBGz08VU/l86dZWZgI4zm5k2VaKqayYyA==", "dev": true, - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "5.44.0", "@typescript-eslint/types": "5.44.0", @@ -3268,7 +3264,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==", "dev": true, - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3666,7 +3661,6 @@ "url": "https://tidelift.com/funding/github/npm/browserslist" } ], - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001400", "electron-to-chromium": "^1.4.251", @@ -4361,7 +4355,6 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.28.0.tgz", "integrity": "sha512-S27Di+EVyMxcHiwDrFzk8dJYAaD+/5SoWKxL1ri/71CRHsnJnRDPNt2Kzj24+MT9FDupf4aqqyqPrvI8MvQ4VQ==", "dev": true, - "peer": true, "dependencies": { "@eslint/eslintrc": "^1.3.3", "@humanwhocodes/config-array": "^0.11.6", @@ -5112,11 +5105,12 @@ } }, "node_modules/furious-commander": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/furious-commander/-/furious-commander-1.7.1.tgz", - "integrity": "sha512-EwgVMVU1y1JNpqMdBPezuJRFufGlTumTKKau1eEvOJ6AxYgNkdDiQxl+GD3PBZo6fJo5dpBf+0TohoSdA7oeug==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/furious-commander/-/furious-commander-1.8.0.tgz", + "integrity": "sha512-Hoxuw0UHdWVvsSVEtCxQD41/EUvzPxckdy7C+oGuh9IxH/SUJ31toVTl3u/WPF1iKp+sXGocoeth1QkySPz/xw==", + "license": "MIT", "dependencies": { - "madlad": "^1.2.1", + "madlad": "^1.5.0", "reflect-metadata": "^0.1.13" }, "engines": { @@ -6050,7 +6044,6 @@ "resolved": "https://registry.npmjs.org/jest/-/jest-29.3.1.tgz", "integrity": "sha512-6iWfL5DTT0Np6UYs/y5Niu7WIfNv/wRTtN5RSXt2DIEft3dx3zPuw/3WJQBCJfmEzvDiEKwoqMbGD9n49+qLSA==", "dev": true, - "peer": true, "dependencies": { "@jest/core": "^29.3.1", "@jest/types": "^29.3.1", @@ -7965,9 +7958,9 @@ } }, "node_modules/madlad": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/madlad/-/madlad-1.4.0.tgz", - "integrity": "sha512-VBHZEiDqIGaKeYRFphAMbhYga34pk+WeZ0hGqKwxZagtIxSuqeiZnr0PvNAvv7preQoIZfs7Nc5lJ1Tpw5Z2cg==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/madlad/-/madlad-1.5.0.tgz", + "integrity": "sha512-wvZkAV48esvLI7+ni4+5flCWtgO8MFY+l1LYOzoK3qA4O1IBQ6GntsGb/7jjNPr+O/zZfH5U52uuo7TY4sLf6A==", "license": "MIT" }, "node_modules/make-dir": { @@ -8626,7 +8619,6 @@ "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true, - "peer": true, "bin": { "prettier": "bin-prettier.js" }, @@ -9535,7 +9527,6 @@ "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", "dev": true, - "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -9633,7 +9624,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -9887,7 +9877,6 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "license": "MIT", - "peer": true, "engines": { "node": ">=10.0.0" }, diff --git a/src/command/cheque/deposit.ts b/src/command/cheque/deposit.ts index 39aef38d..a516354a 100644 --- a/src/command/cheque/deposit.ts +++ b/src/command/cheque/deposit.ts @@ -1,4 +1,6 @@ -import { Argument, LeafCommand } from 'furious-commander' +import { Argument, LeafCommand, Option } from 'furious-commander' +import { BZZ } from '@ethersphere/bee-js' +import { Context } from 'madlad' import { createKeyValue } from '../../utils/text' import { ChequeCommand } from './cheque-command' @@ -11,17 +13,48 @@ export class Deposit extends ChequeCommand implements LeafCommand { @Argument({ key: 'amount', - type: 'bigint', - description: 'Amount of tokens to deposit in PLUR', + description: 'Amount of tokens to deposit', + type: 'decimal-string', required: true, - minimum: BigInt(1), + validate: (value: unknown, context: Context): string[] => { + if (context.options.unit === 'bzz') { + const amount = parseFloat(value as string) + + if (isNaN(amount) || amount <= 0) { + return [`Invalid amount '${value}'. Amount must be a positive number.`] + } + } else { + try { + const amount = BigInt(value as string) + + if (amount <= BigInt(0)) { + return [`Invalid amount '${value}'. Amount must be a positive integer.`] + } + } catch (e) { + return [`Invalid amount '${value}'. Amount must be a positive integer.`] + } + } + + return [] + }, }) - public amount!: bigint + public amount!: string + + @Option({ + key: 'unit', + type: 'enum', + description: 'Unit of the amount', + enum: ['bzz', 'plur'], + default: 'bzz', + }) + public unit!: string public async run(): Promise { super.init() - const response = await this.bee.depositTokens(this.amount.toString()) + const amountBzz = this.unit === 'bzz' ? BZZ.fromDecimalString(this.amount) : BZZ.fromPLUR(this.amount) + + const response = await this.bee.depositBZZToChequebook(amountBzz) this.console.log(createKeyValue('Tx', response.toHex())) this.console.quiet(response.toHex()) } diff --git a/src/command/cheque/withdraw.ts b/src/command/cheque/withdraw.ts index 9878cc0b..ba91269c 100644 --- a/src/command/cheque/withdraw.ts +++ b/src/command/cheque/withdraw.ts @@ -1,4 +1,6 @@ -import { Argument, LeafCommand } from 'furious-commander' +import { Argument, LeafCommand, Option } from 'furious-commander' +import { BZZ } from '@ethersphere/bee-js' +import { Context } from 'madlad' import { createKeyValue } from '../../utils/text' import { ChequeCommand } from './cheque-command' @@ -11,17 +13,49 @@ export class Withdraw extends ChequeCommand implements LeafCommand { @Argument({ key: 'amount', - type: 'bigint', - description: 'Amount of tokens to withdraw in PLUR', + type: 'string', + description: 'Amount of tokens to withdraw', required: true, - minimum: BigInt(1), + validate: (value: unknown, context: Context): string[] => { + if (context.options.unit === 'bzz') { + const amount = parseFloat(value as string) + + if (isNaN(amount) || amount <= 0) { + return [`Invalid amount '${value}'. Amount must be a positive number.`] + } + } else { + try { + const amount = BigInt(value as string) + + if (amount <= BigInt(0)) { + return [`Invalid amount '${value}'. Amount must be a positive integer.`] + } + } catch (e) { + return [`Invalid amount '${value}'. Amount must be a positive integer.`] + } + } + + return [] + }, }) - public amount!: bigint + public amount!: string + + @Option({ + key: 'unit', + type: 'enum', + description: 'Unit of the amount', + enum: ['bzz', 'plur'], + default: 'bzz', + }) + public unit!: string public async run(): Promise { super.init() - const response = await this.bee.withdrawTokens(this.amount.toString()) + const amountBzz = this.unit === 'bzz' ? BZZ.fromDecimalString(this.amount) : BZZ.fromPLUR(this.amount) + + process.stderr.write(JSON.stringify(amountBzz) + '\n') + const response = await this.bee.withdrawBZZFromChequebook(amountBzz) this.console.log(createKeyValue('Tx', response.toHex())) this.console.quiet(response.toHex()) } diff --git a/src/command/root-command/command-config.ts b/src/command/root-command/command-config.ts index e7f71974..afd9ea5e 100644 --- a/src/command/root-command/command-config.ts +++ b/src/command/root-command/command-config.ts @@ -55,7 +55,7 @@ export class CommandConfig { } public getHistoryFilePath(): string { - return join(this.configFolderPath, 'upload-history.json') + return process.env.SWARM_CLI_HISTORY_FILE_PATH || join(this.configFolderPath, 'upload-history.json') } public setHistoryEnabled(enabled: boolean): void { diff --git a/src/config.ts b/src/config.ts index 1614f10a..13683d20 100644 --- a/src/config.ts +++ b/src/config.ts @@ -102,7 +102,7 @@ export const dev: IOption = { default: false, } -export const optionParameters: IOption[] = [ +export const optionParameters: IOption[] = [ beeApiUrl, configFolder, configFile, diff --git a/src/utils/text.ts b/src/utils/text.ts index ba0f90d6..5299cb39 100644 --- a/src/utils/text.ts +++ b/src/utils/text.ts @@ -17,6 +17,10 @@ export function warningText(string: string): string { return chalk.yellow(string) } +export function errorText(string: string): string { + return chalk.red(string) +} + export function deletePreviousLine(): void { process.stdout.write('\r' + goUpOneRow() + deleteWholeRow()) } diff --git a/test/command/cheque.spec.ts b/test/command/cheque.spec.ts index 1208d30d..4693c872 100644 --- a/test/command/cheque.spec.ts +++ b/test/command/cheque.spec.ts @@ -1,3 +1,4 @@ +import { Bee, BZZ, TransactionId } from '@ethersphere/bee-js' import { describeCommand, invokeTestCli } from '../utility' async function runCommandAndExpectError( @@ -13,79 +14,142 @@ async function runCommandAndExpectError( describeCommand( 'Test Cheque command', ({ consoleMessages, getNthLastMessage, getLastMessage }) => { - it('should print cheques', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli(['cheque', 'list']) - expect(getLastMessage()).toContain('Cheque Value:') - expect(getLastMessage()).toContain('0.0008944000000000 xBZZ') - }) + describe('list', () => { + beforeEach(() => { + process.env.BEE_API_URL = 'http://localhost:16337' + }) + it('should print cheques', async () => { + await invokeTestCli(['cheque', 'list']) + expect(getLastMessage()).toContain('Cheque Value:') + expect(getLastMessage()).toContain('0.0008944000000000 xBZZ') + }) - it('should not print cheques when --minimum is higher', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli(['cheque', 'list', '--minimum', '10000000000000000000']) - expect(getLastMessage()).toContain('No uncashed cheques found') - }) + it('should not print cheques when --minimum is higher', async () => { + await invokeTestCli(['cheque', 'list', '--minimum', '10000000000000000000']) + expect(getLastMessage()).toContain('No uncashed cheques found') + }) - it('should print cheques when --minimum is lower', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli(['cheque', 'list', '--minimum', '1000']) - expect(getLastMessage()).toContain('Cheque Value') + it('should print cheques when --minimum is lower', async () => { + await invokeTestCli(['cheque', 'list', '--minimum', '1000']) + expect(getLastMessage()).toContain('Cheque Value') + }) }) - it('should cashout all cheques', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli(['cheque', 'cashout', '--all']) - expect(getNthLastMessage(3)).toContain('Peer Address:') - expect(getNthLastMessage(3)).toContain('1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad') - expect(getNthLastMessage(2)).toContain('Cheque Value:') - expect(getNthLastMessage(2)).toContain('0.0008944000000000 xBZZ') - expect(getLastMessage()).toContain('Tx:') - expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') - }) + describe('cashout', () => { + beforeEach(() => { + process.env.BEE_API_URL = 'http://localhost:16337' + }) + it('should cashout all cheques', async () => { + await invokeTestCli(['cheque', 'cashout', '--all']) + expect(getNthLastMessage(3)).toContain('Peer Address:') + expect(getNthLastMessage(3)).toContain('1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad') + expect(getNthLastMessage(2)).toContain('Cheque Value:') + expect(getNthLastMessage(2)).toContain('0.0008944000000000 xBZZ') + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') + }) - it('should allow specifying gas price and limit for cashout', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli(['cheque', 'cashout', '--all', '--gas-price', '100', '--gas-limit', '100']) - expect(getLastMessage()).toContain('Tx:') - expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') - }) + it('should allow specifying gas price and limit for cashout', async () => { + await invokeTestCli(['cheque', 'cashout', '--all', '--gas-price', '100', '--gas-limit', '100']) + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') + }) - it('should not cashout any cheques when --minimum is higher', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli(['cheque', 'cashout', '--all', '--minimum', '10000000000000000000']) - expect(getLastMessage()).toContain('Found 0 cheques') - }) + it('should not cashout any cheques when --minimum is higher', async () => { + await invokeTestCli(['cheque', 'cashout', '--all', '--minimum', '10000000000000000000']) + expect(getLastMessage()).toContain('Found 0 cheques') + }) - it('should cashout one specific cheque', async () => { - process.env.BEE_API_URL = 'http://localhost:16337' - await invokeTestCli([ - 'cheque', - 'cashout', - '--peer', - '1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad', - ]) - expect(getNthLastMessage(3)).toContain('Peer Address:') - expect(getNthLastMessage(3)).toContain('1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad') - expect(getNthLastMessage(2)).toContain('Cheque Value:') - expect(getNthLastMessage(2)).toContain('0.0008944000000000 xBZZ') - expect(getLastMessage()).toContain('Tx:') - expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') + it('should cashout one specific cheque', async () => { + await invokeTestCli([ + 'cheque', + 'cashout', + '--peer', + '1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad', + ]) + expect(getNthLastMessage(3)).toContain('Peer Address:') + expect(getNthLastMessage(3)).toContain('1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad') + expect(getNthLastMessage(2)).toContain('Cheque Value:') + expect(getNthLastMessage(2)).toContain('0.0008944000000000 xBZZ') + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') + }) }) it('should raise error when withdrawing negative amount', async () => { - await runCommandAndExpectError(['cheque', 'withdraw', '-1'], '[amount] must be at least 1', consoleMessages) + await runCommandAndExpectError( + ['cheque', 'withdraw', '-1'], + "Invalid amount '-1'. Amount must be a positive number.", + consoleMessages, + ) }) it('should raise error when depositing negative amount', async () => { - await runCommandAndExpectError(['cheque', 'deposit', '-42000000'], '[amount] must be at least 1', consoleMessages) + await runCommandAndExpectError( + ['cheque', 'deposit', '-42000000'], + 'Expected decimal string for amount, got -42000000', + consoleMessages, + ) }) it('should raise error when withdrawing zero', async () => { - await runCommandAndExpectError(['cheque', 'withdraw', '0'], '[amount] must be at least 1', consoleMessages) + await runCommandAndExpectError( + ['cheque', 'withdraw', '0'], + "Invalid amount '0'. Amount must be a positive number.", + consoleMessages, + ) }) it('should raise error when depositing zero', async () => { - await runCommandAndExpectError(['cheque', 'deposit', '0'], '[amount] must be at least 1', consoleMessages) + await runCommandAndExpectError( + ['cheque', 'deposit', '0'], + "Invalid amount '0'. Amount must be a positive number.", + consoleMessages, + ) + }) + + describe('deposit', () => { + const fakeTxHash = 'a'.repeat(64) + + it('should deposit {amount} of BZZ to chequebook', async () => { + const spy = jest.spyOn(Bee.prototype, 'depositBZZToChequebook').mockResolvedValue(new TransactionId(fakeTxHash)) + await invokeTestCli(['cheque', 'deposit', '20']) + expect(spy).toHaveBeenCalledWith(BZZ.fromDecimalString('20')) + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain(fakeTxHash) + }) + + it('should deposit {amount} of PLUR to chequebook', async () => { + const spy = jest.spyOn(Bee.prototype, 'depositBZZToChequebook').mockResolvedValue(new TransactionId(fakeTxHash)) + await invokeTestCli(['cheque', 'deposit', '15', '--unit', 'plur']) + expect(spy).toHaveBeenCalledWith(BZZ.fromPLUR('15')) + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain(fakeTxHash) + }) + }) + + describe('withdraw', () => { + const fakeTxHash = 'a'.repeat(64) + + it('should withdraw {amount} of BZZ from chequebook', async () => { + const spy = jest + .spyOn(Bee.prototype, 'withdrawBZZFromChequebook') + .mockResolvedValue(new TransactionId(fakeTxHash)) + await invokeTestCli(['cheque', 'withdraw', '20']) + expect(spy).toHaveBeenCalledWith(BZZ.fromDecimalString('20')) + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain(fakeTxHash) + }) + + it('should withdraw {amount} of PLUR from chequebook', async () => { + const spy = jest + .spyOn(Bee.prototype, 'withdrawBZZFromChequebook') + .mockResolvedValue(new TransactionId(fakeTxHash)) + await invokeTestCli(['cheque', 'withdraw', '15', '--unit', 'plur']) + expect(spy).toHaveBeenCalledWith(BZZ.fromPLUR('15')) + expect(getLastMessage()).toContain('Tx:') + expect(getLastMessage()).toContain(fakeTxHash) + }) }) }, { configFileName: 'cheque' }, diff --git a/test/command/history.spec.ts b/test/command/history.spec.ts index edc66f46..54536551 100644 --- a/test/command/history.spec.ts +++ b/test/command/history.spec.ts @@ -8,118 +8,122 @@ async function uploadTestFile() { await invokeTestCli(['upload', uploadFilePath, ...getStampOption()]) } -describeCommand('Test History command', ({ consoleMessages }) => { - describe('list', () => { - it('should have table header row', async () => { - await invokeTestCli(['history', 'enable']) - await invokeTestCli(['history', 'list']) - expect(consoleMessages[1]).toContain('Timestamp') - expect(consoleMessages[1]).toContain('Reference') - expect(consoleMessages[1]).toContain('Postage stamp batch ID') - expect(consoleMessages[1]).toContain('File path') - expect(consoleMessages[1]).toContain('Upload type') - await invokeTestCli(['history', 'disable', '--yes']) - }) +describeCommand( + 'Test History command', + ({ consoleMessages }) => { + describe('list', () => { + it('should have table header row', async () => { + await invokeTestCli(['history', 'enable']) + await invokeTestCli(['history', 'list']) + expect(consoleMessages[1]).toContain('Timestamp') + expect(consoleMessages[1]).toContain('Reference') + expect(consoleMessages[1]).toContain('Postage stamp batch ID') + expect(consoleMessages[1]).toContain('File path') + expect(consoleMessages[1]).toContain('Upload type') + await invokeTestCli(['history', 'disable', '--yes']) + }) - it('should list history items', async () => { - await invokeTestCli(['history', 'enable']) - await uploadTestFile() - await invokeTestCli(['history', 'list']) + it('should list history items', async () => { + await invokeTestCli(['history', 'enable']) + await uploadTestFile() + await invokeTestCli(['history', 'list']) - const tableString = consoleMessages[consoleMessages.length - 1] - expect(tableString).toContain(' 1 ') - expect(tableString).toContain('b4b1557e29c2') - expect(tableString).toContain('testpage/images/swarm.png') - expect(tableString).toContain('file') - await invokeTestCli(['history', 'disable', '--yes']) - }) + const tableString = consoleMessages[consoleMessages.length - 1] + expect(tableString).toContain(' 1 ') + expect(tableString).toContain('b4b1557e29c2') + expect(tableString).toContain('testpage/images/swarm.png') + expect(tableString).toContain('file') + await invokeTestCli(['history', 'disable', '--yes']) + }) - it('should show warning message if history tracking is not enabled', async () => { - await invokeTestCli(['history', 'disable', '--yes']) - await invokeTestCli(['history', 'list']) - expect(consoleMessages[1]).toContain( - 'Upload history tracking is not enabled. Use "swarm-cli history enable" command to enable it.', - ) + it('should show warning message if history tracking is not enabled', async () => { + await invokeTestCli(['history', 'disable', '--yes']) + await invokeTestCli(['history', 'list']) + expect(consoleMessages[1]).toContain( + 'Upload history tracking is not enabled. Use "swarm-cli history enable" command to enable it.', + ) + }) }) - }) - describe('show', () => { - it('should show all detail for a certain history item', async () => { - const identityName = randomUUID() - await invokeTestCli(['identity', 'create', identityName, '--password', 'test']) - await invokeTestCli(['history', 'enable']) - await invokeTestCli([ - 'feed', - 'upload', - `${__dirname}/../testpage/images`, - '--identity', - identityName, - '--topic-string', - 'test', - '--password', - 'test', - '--quiet', - ...getStampOption(), - ]) - await invokeTestCli(['history', 'show', '1']) + describe('show', () => { + it('should show all detail for a certain history item', async () => { + const identityName = randomUUID() + await invokeTestCli(['identity', 'create', identityName, '--password', 'test']) + await invokeTestCli(['history', 'enable']) + await invokeTestCli([ + 'feed', + 'upload', + `${__dirname}/../testpage/images`, + '--identity', + identityName, + '--topic-string', + 'test', + '--password', + 'test', + '--quiet', + ...getStampOption(), + ]) + await invokeTestCli(['history', 'show', '1']) - expect(consoleMessages[8]).toContain('c86177d67756e097b') - expect(consoleMessages[9]).toMatch(/[a-f0-9]{64}/g) - expect(consoleMessages[10]).toContain('folder') - expect(consoleMessages[11]).toContain('testpage/images') - expect(consoleMessages[12]).toMatch(/[a-f0-9]{64}/g) - expect(consoleMessages[13]).toContain(identityName) - await invokeTestCli(['history', 'disable', '--yes']) - }) + expect(consoleMessages[8]).toContain('c86177d67756e097b') + expect(consoleMessages[9]).toMatch(/[a-f0-9]{64}/g) + expect(consoleMessages[10]).toContain('folder') + expect(consoleMessages[11]).toContain('testpage/images') + expect(consoleMessages[12]).toMatch(/[a-f0-9]{64}/g) + expect(consoleMessages[13]).toContain(identityName) + await invokeTestCli(['history', 'disable', '--yes']) + }) - it('should show warning message if history tracking is not enabled', async () => { - await invokeTestCli(['history', 'show', '1']) - expect(consoleMessages[0]).toContain( - 'Upload history tracking is not enabled. Use "swarm-cli history enable" command to enable it.', - ) + it('should show warning message if history tracking is not enabled', async () => { + await invokeTestCli(['history', 'show', '1']) + expect(consoleMessages[0]).toContain( + 'Upload history tracking is not enabled. Use "swarm-cli history enable" command to enable it.', + ) + }) }) - }) - describe('enable', () => { - it('should enable history tracking', async () => { - await invokeTestCli(['history', 'enable']) - expect(consoleMessages[0]).toContain('Upload history tracking enabled') - }) + describe('enable', () => { + it('should enable history tracking', async () => { + await invokeTestCli(['history', 'enable']) + expect(consoleMessages[0]).toContain('Upload history tracking enabled') + }) - it('should not enable history tracking if it is already enabled', async () => { - await invokeTestCli(['history', 'enable']) - await invokeTestCli(['history', 'enable']) - expect(consoleMessages[1]).toContain('Upload history tracking is already enabled') - await invokeTestCli(['history', 'disable', '--yes']) + it('should not enable history tracking if it is already enabled', async () => { + await invokeTestCli(['history', 'enable']) + await invokeTestCli(['history', 'enable']) + expect(consoleMessages[1]).toContain('Upload history tracking is already enabled') + await invokeTestCli(['history', 'disable', '--yes']) + }) }) - }) - describe('disable', () => { - it('should disable history tracking', async () => { - await invokeTestCli(['history', 'enable']) - await invokeTestCli(['history', 'disable', '--yes']) - expect(consoleMessages[1]).toContain('Upload history file deleted') - expect(consoleMessages[2]).toContain('Upload history tracking disabled') - }) + describe('disable', () => { + it('should disable history tracking', async () => { + await invokeTestCli(['history', 'enable']) + await invokeTestCli(['history', 'disable', '--yes']) + expect(consoleMessages[1]).toContain('Upload history file deleted') + expect(consoleMessages[2]).toContain('Upload history tracking disabled') + }) - it('should not disable history tracking if it is already disabled', async () => { - await invokeTestCli(['history', 'disable', '--yes']) - expect(consoleMessages[0]).toContain('Upload history tracking is already disabled and no history file exists') + it('should not disable history tracking if it is already disabled', async () => { + await invokeTestCli(['history', 'disable', '--yes']) + expect(consoleMessages[0]).toContain('Upload history tracking is already disabled and no history file exists') + }) }) - }) - describe('status', () => { - it('should show history tracking status', async () => { - await invokeTestCli(['history', 'status']) - expect(consoleMessages[0]).toEqual(chalk.green.bold('Upload history tracking status:')) - expect(consoleMessages[1]).toContain('inactive') - await invokeTestCli(['history', 'enable']) - await uploadTestFile() - await invokeTestCli(['history', 'status']) - expect(consoleMessages[9]).toContain('active') - expect(consoleMessages[10]).toContain('/test/testconfig/upload-history.json') - expect(consoleMessages[11]).toEqual('Number of history entries: 1') - await invokeTestCli(['history', 'disable', '--yes']) + describe('status', () => { + it('should show history tracking status', async () => { + await invokeTestCli(['history', 'status']) + expect(consoleMessages[0]).toEqual(chalk.green.bold('Upload history tracking status:')) + expect(consoleMessages[1]).toContain('inactive') + await invokeTestCli(['history', 'enable']) + await uploadTestFile() + await invokeTestCli(['history', 'status']) + expect(consoleMessages[9]).toContain('active') + expect(consoleMessages[10]).toContain('upload-history.json') + expect(consoleMessages[11]).toEqual('Number of history entries: 1') + await invokeTestCli(['history', 'disable', '--yes']) + }) }) - }) -}) + }, + { configFileName: 'history' }, +) diff --git a/test/coverage/coverage-summary.json b/test/coverage/coverage-summary.json index b031765b..32223d81 100644 --- a/test/coverage/coverage-summary.json +++ b/test/coverage/coverage-summary.json @@ -1,4 +1,4 @@ -{"total": {"lines":{"total":2835,"covered":2155,"skipped":0,"pct":76.01},"statements":{"total":2856,"covered":2169,"skipped":0,"pct":75.94},"functions":{"total":340,"covered":267,"skipped":0,"pct":78.52},"branches":{"total":603,"covered":338,"skipped":0,"pct":56.05},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} +{"total": {"lines":{"total":2864,"covered":2187,"skipped":0,"pct":76.36},"statements":{"total":2885,"covered":2201,"skipped":0,"pct":76.29},"functions":{"total":343,"covered":271,"skipped":0,"pct":79},"branches":{"total":621,"covered":354,"skipped":0,"pct":57},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/application.ts": {"lines":{"total":2,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/config.ts": {"lines":{"total":33,"covered":32,"skipped":0,"pct":96.96},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":33,"covered":32,"skipped":0,"pct":96.96},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/curl.ts": {"lines":{"total":24,"covered":24,"skipped":0,"pct":100},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":25,"covered":25,"skipped":0,"pct":100},"branches":{"total":13,"covered":12,"skipped":0,"pct":92.3}} @@ -12,11 +12,11 @@ ,"/home/runner/work/swarm-cli/swarm-cli/src/command/upload.ts": {"lines":{"total":223,"covered":157,"skipped":0,"pct":70.4},"functions":{"total":16,"covered":14,"skipped":0,"pct":87.5},"statements":{"total":224,"covered":158,"skipped":0,"pct":70.53},"branches":{"total":101,"covered":58,"skipped":0,"pct":57.42}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/cashout.ts": {"lines":{"total":32,"covered":30,"skipped":0,"pct":93.75},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":32,"covered":30,"skipped":0,"pct":93.75},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/cheque-command.ts": {"lines":{"total":25,"covered":21,"skipped":0,"pct":84},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":26,"covered":22,"skipped":0,"pct":84.61},"branches":{"total":2,"covered":0,"skipped":0,"pct":0}} -,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/deposit.ts": {"lines":{"total":12,"covered":8,"skipped":0,"pct":66.66},"functions":{"total":2,"covered":1,"skipped":0,"pct":50},"statements":{"total":12,"covered":8,"skipped":0,"pct":66.66},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/deposit.ts": {"lines":{"total":25,"covered":23,"skipped":0,"pct":92},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":25,"covered":23,"skipped":0,"pct":92},"branches":{"total":8,"covered":7,"skipped":0,"pct":87.5}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/index.ts": {"lines":{"total":9,"covered":9,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":9,"covered":9,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/list.ts": {"lines":{"total":13,"covered":13,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":14,"covered":14,"skipped":0,"pct":100},"branches":{"total":1,"covered":1,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/withdraw-all.ts": {"lines":{"total":15,"covered":6,"skipped":0,"pct":40},"functions":{"total":2,"covered":1,"skipped":0,"pct":50},"statements":{"total":15,"covered":6,"skipped":0,"pct":40},"branches":{"total":1,"covered":0,"skipped":0,"pct":0}} -,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/withdraw.ts": {"lines":{"total":12,"covered":8,"skipped":0,"pct":66.66},"functions":{"total":2,"covered":1,"skipped":0,"pct":50},"statements":{"total":12,"covered":8,"skipped":0,"pct":66.66},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/withdraw.ts": {"lines":{"total":26,"covered":24,"skipped":0,"pct":92.3},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":26,"covered":24,"skipped":0,"pct":92.3},"branches":{"total":8,"covered":7,"skipped":0,"pct":87.5}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/feed/feed-command.ts": {"lines":{"total":49,"covered":49,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":49,"covered":49,"skipped":0,"pct":100},"branches":{"total":13,"covered":13,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/feed/index.ts": {"lines":{"total":7,"covered":7,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":7,"covered":7,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/feed/print.ts": {"lines":{"total":80,"covered":26,"skipped":0,"pct":32.5},"functions":{"total":4,"covered":2,"skipped":0,"pct":50},"statements":{"total":81,"covered":26,"skipped":0,"pct":32.09},"branches":{"total":21,"covered":4,"skipped":0,"pct":19.04}} @@ -63,7 +63,7 @@ ,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/receive.ts": {"lines":{"total":24,"covered":18,"skipped":0,"pct":75},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":24,"covered":18,"skipped":0,"pct":75},"branches":{"total":6,"covered":2,"skipped":0,"pct":33.33}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/send.ts": {"lines":{"total":34,"covered":29,"skipped":0,"pct":85.29},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":34,"covered":29,"skipped":0,"pct":85.29},"branches":{"total":5,"covered":2,"skipped":0,"pct":40}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/subscribe.ts": {"lines":{"total":18,"covered":8,"skipped":0,"pct":44.44},"functions":{"total":5,"covered":1,"skipped":0,"pct":20},"statements":{"total":18,"covered":8,"skipped":0,"pct":44.44},"branches":{"total":4,"covered":0,"skipped":0,"pct":0}} -,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/command-config.ts": {"lines":{"total":39,"covered":33,"skipped":0,"pct":84.61},"functions":{"total":8,"covered":8,"skipped":0,"pct":100},"statements":{"total":42,"covered":35,"skipped":0,"pct":83.33},"branches":{"total":9,"covered":5,"skipped":0,"pct":55.55}} +,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/command-config.ts": {"lines":{"total":39,"covered":33,"skipped":0,"pct":84.61},"functions":{"total":8,"covered":8,"skipped":0,"pct":100},"statements":{"total":42,"covered":35,"skipped":0,"pct":83.33},"branches":{"total":11,"covered":6,"skipped":0,"pct":54.54}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/command-log.ts": {"lines":{"total":78,"covered":60,"skipped":0,"pct":76.92},"functions":{"total":9,"covered":6,"skipped":0,"pct":66.66},"statements":{"total":78,"covered":60,"skipped":0,"pct":76.92},"branches":{"total":11,"covered":7,"skipped":0,"pct":63.63}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/index.ts": {"lines":{"total":44,"covered":40,"skipped":0,"pct":90.9},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":44,"covered":40,"skipped":0,"pct":90.9},"branches":{"total":9,"covered":5,"skipped":0,"pct":55.55}} ,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/printer.ts": {"lines":{"total":9,"covered":9,"skipped":0,"pct":100},"functions":{"total":6,"covered":6,"skipped":0,"pct":100},"statements":{"total":9,"covered":9,"skipped":0,"pct":100},"branches":{"total":1,"covered":1,"skipped":0,"pct":100}} @@ -96,7 +96,7 @@ ,"/home/runner/work/swarm-cli/swarm-cli/src/service/identity/index.ts": {"lines":{"total":36,"covered":32,"skipped":0,"pct":88.88},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":36,"covered":32,"skipped":0,"pct":88.88},"branches":{"total":9,"covered":6,"skipped":0,"pct":66.66}} ,"/home/runner/work/swarm-cli/swarm-cli/src/service/identity/types/identity.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/service/identity/types/index.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":2,"covered":1,"skipped":0,"pct":50},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/swarm-cli/swarm-cli/src/service/stamp/index.ts": {"lines":{"total":32,"covered":30,"skipped":0,"pct":93.75},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":32,"covered":30,"skipped":0,"pct":93.75},"branches":{"total":11,"covered":8,"skipped":0,"pct":72.72}} +,"/home/runner/work/swarm-cli/swarm-cli/src/service/stamp/index.ts": {"lines":{"total":32,"covered":30,"skipped":0,"pct":93.75},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":32,"covered":30,"skipped":0,"pct":93.75},"branches":{"total":11,"covered":9,"skipped":0,"pct":81.81}} ,"/home/runner/work/swarm-cli/swarm-cli/src/utils/bzz-address.ts": {"lines":{"total":30,"covered":24,"skipped":0,"pct":80},"functions":{"total":3,"covered":2,"skipped":0,"pct":66.66},"statements":{"total":30,"covered":24,"skipped":0,"pct":80},"branches":{"total":6,"covered":3,"skipped":0,"pct":50}} ,"/home/runner/work/swarm-cli/swarm-cli/src/utils/chainsync.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/utils/contracts.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} @@ -108,5 +108,5 @@ ,"/home/runner/work/swarm-cli/swarm-cli/src/utils/option.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} ,"/home/runner/work/swarm-cli/swarm-cli/src/utils/rpc.ts": {"lines":{"total":37,"covered":9,"skipped":0,"pct":24.32},"functions":{"total":6,"covered":0,"skipped":0,"pct":0},"statements":{"total":37,"covered":9,"skipped":0,"pct":24.32},"branches":{"total":5,"covered":0,"skipped":0,"pct":0}} ,"/home/runner/work/swarm-cli/swarm-cli/src/utils/spinner.ts": {"lines":{"total":15,"covered":15,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":15,"covered":15,"skipped":0,"pct":100},"branches":{"total":5,"covered":3,"skipped":0,"pct":60}} -,"/home/runner/work/swarm-cli/swarm-cli/src/utils/text.ts": {"lines":{"total":19,"covered":17,"skipped":0,"pct":89.47},"functions":{"total":8,"covered":7,"skipped":0,"pct":87.5},"statements":{"total":20,"covered":18,"skipped":0,"pct":90},"branches":{"total":5,"covered":3,"skipped":0,"pct":60}} +,"/home/runner/work/swarm-cli/swarm-cli/src/utils/text.ts": {"lines":{"total":21,"covered":18,"skipped":0,"pct":85.71},"functions":{"total":9,"covered":7,"skipped":0,"pct":77.77},"statements":{"total":22,"covered":19,"skipped":0,"pct":86.36},"branches":{"total":5,"covered":3,"skipped":0,"pct":60}} } diff --git a/test/misc/monetary-units.spec.ts b/test/misc/monetary-units.spec.ts index 0d7968f8..7138a333 100644 --- a/test/misc/monetary-units.spec.ts +++ b/test/misc/monetary-units.spec.ts @@ -38,12 +38,12 @@ describeCommand('Test Monetary units', ({ consoleMessages }) => { it('should show units in help: cheque withdraw', async () => { await invokeTestCli(['cheque', 'withdraw', '--help']) - expectSubstringsPrinted('amount', 'in PLUR') + expectSubstringsPrinted('amount', 'Amount of tokens to withdraw') }) it('should show units in help: cheque deposit', async () => { await invokeTestCli(['cheque', 'deposit', '--help']) - expectSubstringsPrinted('amount', 'in PLUR') + expectSubstringsPrinted('amount', 'Amount of tokens to deposit') }) it('should show units after running: cheque list', async () => { diff --git a/test/prompt/history-prompt.spec.ts b/test/prompt/history-prompt.spec.ts index 6ec91f6d..8f96f7c8 100644 --- a/test/prompt/history-prompt.spec.ts +++ b/test/prompt/history-prompt.spec.ts @@ -11,7 +11,7 @@ async function uploadTestFile() { describeCommand( 'Using History Disable Command with Prompts', - ({ consoleMessages, configFolderPath, getLastMessage }) => { + ({ configFolderPath, getLastMessage, hasMessageContaining }) => { it('history disables asks whether the file should be deleted', async () => { await invokeTestCli(['history', 'enable']) await uploadTestFile() @@ -19,8 +19,8 @@ describeCommand( jest.spyOn(inquirer, 'prompt').mockClear().mockResolvedValueOnce({ value: false }) await invokeTestCli(['history', 'disable']) - expect(consoleMessages[6]).toEqual('Upload history tracking disabled') - expect(existsSync(`${configFolderPath}/upload-history.json`)).toEqual(true) + expect(hasMessageContaining('Upload history tracking disabled')).toBe(true) + expect(existsSync(`${configFolderPath}/history-prompt-upload-history.json`)).toEqual(true) expect(inquirer.prompt).toHaveBeenCalledWith({ message: 'Do you want to delete the upload history file? This action cannot be undone.', name: 'value', @@ -43,4 +43,5 @@ describeCommand( }) }) }, + { configFileName: 'history-prompt' }, ) diff --git a/test/utility/index.ts b/test/utility/index.ts index 0a354283..84847640 100644 --- a/test/utility/index.ts +++ b/test/utility/index.ts @@ -72,6 +72,12 @@ export function describeCommand( jest.spyOn(global.console, 'warn') + const historyFilePath = join( + configFolderPath, + configFileName ? `${configFileName}-upload-history.json` : 'upload-history.json', + ) + process.env.SWARM_CLI_HISTORY_FILE_PATH = historyFilePath + //if own config is needed if (configFileName) { const fileName = `${configFileName}.json` @@ -90,8 +96,6 @@ export function describeCommand( }) afterEach(() => { - const historyFilePath = join(configFolderPath, 'upload-history.json') - if (existsSync(historyFilePath)) { unlinkSync(historyFilePath) }