maintenance.spec.ts•5.4 kB
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
import { registerMaintenanceOnTool, registerMaintenanceOffTool } from './maintenance.js';
import { expect } from 'chai';
import sinon from 'sinon';
import { setupMcpToolMocks } from '../utils/mcp-tool-mocks.spechelper.js';
describe('Maintenance Tools', () => {
afterEach(() => {
sinon.restore();
});
describe('maintenance:on', () => {
let mocks: ReturnType<typeof setupMcpToolMocks>;
let toolCallback: Function;
beforeEach(() => {
mocks = setupMcpToolMocks();
registerMaintenanceOnTool(mocks.server, mocks.herokuRepl);
toolCallback = mocks.getToolCallback();
});
it('should register the tool with correct parameters', () => {
const tool = mocks.server.tool;
expect(tool.calledOnce).to.be.true;
expect(tool.firstCall.args[0]).to.equal('maintenance_on');
expect(tool.firstCall.args[1]).to.be.a('string');
expect(tool.firstCall.args[2]).to.be.an('object');
expect(tool.firstCall.args[3]).to.be.a('function');
});
it('should build correct command with required parameters', async () => {
mocks.herokuRepl.executeCommand.resolves('Enabling maintenance mode for myapp... done\n');
await toolCallback({ app: 'myapp' });
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(
`${TOOL_COMMAND_MAP.MAINTENANCE_ON} --app=myapp`
);
});
it('should handle successful response', async () => {
const successResponse = 'Enabling maintenance mode for myapp... done\n';
mocks.herokuRepl.executeCommand.resolves(successResponse);
const result = await toolCallback({ app: 'myapp' });
expect(result).to.deep.equal({
content: [{ type: 'text', text: 'Enabling maintenance mode for myapp... done\n' }]
});
});
it('should handle error response', async () => {
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
mocks.herokuRepl.executeCommand.resolves(errorResponse);
const result = await toolCallback({ app: 'myapp' });
expect(result).to.deep.equal({
content: [
{
type: 'text',
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\n<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n'
}
],
isError: true
});
});
});
describe('maintenance:off', () => {
let mocks: ReturnType<typeof setupMcpToolMocks>;
let toolCallback: Function;
beforeEach(() => {
mocks = setupMcpToolMocks();
registerMaintenanceOffTool(mocks.server, mocks.herokuRepl);
toolCallback = mocks.getToolCallback();
});
it('should register the tool with correct parameters', () => {
const tool = mocks.server.tool;
expect(tool.calledOnce).to.be.true;
expect(tool.firstCall.args[0]).to.equal('maintenance_off');
expect(tool.firstCall.args[1]).to.be.a('string');
expect(tool.firstCall.args[2]).to.be.an('object');
expect(tool.firstCall.args[3]).to.be.a('function');
});
it('should build correct command with required parameters', async () => {
mocks.herokuRepl.executeCommand.resolves('Disabling maintenance mode for myapp... done\n');
await toolCallback({ app: 'myapp' });
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(
`${TOOL_COMMAND_MAP.MAINTENANCE_OFF} --app=myapp`
);
});
it('should handle successful response', async () => {
const successResponse = 'Disabling maintenance mode for myapp... done\n';
mocks.herokuRepl.executeCommand.resolves(successResponse);
const result = await toolCallback({ app: 'myapp' });
expect(result).to.deep.equal({
content: [{ type: 'text', text: 'Disabling maintenance mode for myapp... done\n' }]
});
});
it('should handle error response', async () => {
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
mocks.herokuRepl.executeCommand.resolves(errorResponse);
const result = await toolCallback({ app: 'myapp' });
expect(result).to.deep.equal({
content: [
{
type: 'text',
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\n<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n'
}
],
isError: true
});
});
it('should handle undefined response', async () => {
mocks.herokuRepl.executeCommand.resolves(undefined);
const result = await toolCallback({ app: 'myapp' });
expect(result).to.deep.equal({
content: [
{
type: 'text',
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\nNo response from command'
}
],
isError: true
});
});
});
});