Skip to content

Commit

Permalink
cli-test: small internal refactor to use new app.list command (#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
filmaj authored May 27, 2024
1 parent c3725a9 commit 9fb278a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
41 changes: 41 additions & 0 deletions packages/cli-test/src/cli/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
7 changes: 2 additions & 5 deletions packages/cli-test/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,9 +77,7 @@ export const SlackCLI = {
}): Promise<void> {
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
Expand All @@ -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}`);
}
},
};

0 comments on commit 9fb278a

Please sign in to comment.