From 9fb278a41f56dd77b79c56d66940c59df38f491a Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Mon, 27 May 2024 20:07:33 +0000 Subject: [PATCH] cli-test: small internal refactor to use new app.list command (#1797) --- packages/cli-test/src/cli/index.spec.ts | 41 +++++++++++++++++++++++++ packages/cli-test/src/cli/index.ts | 7 ++--- 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 packages/cli-test/src/cli/index.spec.ts diff --git a/packages/cli-test/src/cli/index.spec.ts b/packages/cli-test/src/cli/index.spec.ts new file mode 100644 index 000000000..ae0f736ad --- /dev/null +++ b/packages/cli-test/src/cli/index.spec.ts @@ -0,0 +1,41 @@ +import sinon from 'sinon'; +import logger from '../utils/logger'; +import { SlackCLI } from './index'; + +describe('cli module', () => { + const sandbox = sinon.createSandbox(); + let logoutSpy: sinon.SinonStub; + let warnSpy: sinon.SinonStub; + let deleteSpy: sinon.SinonStub; + + beforeEach(() => { + logoutSpy = sandbox.stub(SlackCLI, 'logout').resolves(); + warnSpy = sandbox.stub(logger, 'warn'); + sandbox.stub(SlackCLI.app, 'list').resolves('This thing has so many apps you would not believe'); + deleteSpy = sandbox.stub(SlackCLI.app, 'delete').resolves(); + }); + afterEach(() => { + sandbox.restore(); + }); + + describe('stopSession method', () => { + it('should invoke logout', async () => { + await SlackCLI.stopSession({ appTeamID: 'T123' }); + sandbox.assert.called(logoutSpy); + }); + it('should warn if logout failed', async () => { + logoutSpy.rejects('boomsies'); + await SlackCLI.stopSession({ appTeamID: 'T123' }); + sandbox.assert.calledWithMatch(warnSpy, 'boomsies'); + }); + it('should attempt to delete app if appPath is provided', async () => { + await SlackCLI.stopSession({ appTeamID: 'T123', appPath: '/some/path' }); + sandbox.assert.called(deleteSpy); + }); + it('should warn if app deletion fails', async () => { + deleteSpy.rejects('explosions'); + await SlackCLI.stopSession({ appTeamID: 'T123', appPath: '/some/path' }); + sandbox.assert.calledWithMatch(warnSpy, 'explosions'); + }); + }); +}); diff --git a/packages/cli-test/src/cli/index.ts b/packages/cli-test/src/cli/index.ts index 3144aeefc..a9e936155 100644 --- a/packages/cli-test/src/cli/index.ts +++ b/packages/cli-test/src/cli/index.ts @@ -11,7 +11,6 @@ import functionCommands from './commands/function'; import manifestCommands from './commands/manifest'; import platformCommands from './commands/platform'; import triggerCommands from './commands/trigger'; -import { SlackCLIProcess } from './cli-process'; /** * Set of functions to spawn and interact with Slack Platform CLI processes and commands @@ -78,9 +77,7 @@ export const SlackCLI = { }): Promise { if (appPath) { // List instances of app installation if app path provided - // TODO: refactor this into standalone workspace list command - const cmd = new SlackCLIProcess('workspace list'); - const { output: installedAppsOutput } = await cmd.execAsync({ cwd: appPath }); + const installedAppsOutput = await SlackCLI.app.list(appPath); // If app is installed if (!installedAppsOutput.includes('This project has no apps')) { // Soft app delete @@ -103,7 +100,7 @@ export const SlackCLI = { await SlackCLI.logout({ allWorkspaces: true }); } catch (error) { // TODO: maybe should error instead? this seems pretty bad - logger.info(`Could not logout gracefully. Error: ${error}`); + logger.warn(`Could not logout gracefully. Error: ${error}`); } }, };