import { expect } from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { stub, restore } from 'sinon';
import { AuthTool } from '../../../src/tools/auth.js';
import { AuthStateManager } from '../../../src/auth/authState.js';
import { OAuthError } from '../../../src/errors/mcpErrors.js';
import { SessionAuthManager } from '../../../src/auth/sessionManager.js';
describe('AuthTool', () => {
let authTool: AuthTool;
let authManager: AuthStateManager;
let sessionAuthManager: SessionAuthManager;
beforeEach(() => {
// Set test mode to prevent OAuth server conflicts
process.env.MCP_TEST_MODE = 'true';
sessionAuthManager = new SessionAuthManager();
authTool = new AuthTool(sessionAuthManager);
authManager = AuthStateManager.getInstance();
authManager.clearAuth();
});
afterEach(() => {
restore();
delete process.env.MCP_TEST_MODE;
});
describe('tool properties', () => {
it('should have correct name and description', () => {
expect(authTool.name).to.equal('auth');
expect(authTool.description).to.include('Google Apps Script API');
expect(authTool.description).to.include('OAuth 2.0');
});
it('should have correct input schema', () => {
const tool = new AuthTool();
const schema = tool.inputSchema as any;
expect(schema.type).to.equal('object');
expect(schema.properties.mode).to.exist;
expect(schema.properties.openBrowser).to.exist;
expect(schema.properties.waitForCompletion).to.exist;
expect(schema.properties.accessToken).to.exist;
// Verify mode enum values
expect(schema.properties.mode.enum).to.deep.equal(['start', 'status', 'logout']);
});
});
/*
* =========================================================================
* INTEGRATION TEST COVERAGE NOTE
* =========================================================================
* The following behaviors are tested via integration tests, not unit tests:
*
* - Mode routing (start/status/logout) - AuthTool uses private methods
* that cannot be stubbed without architectural changes. The actual
* OAuth flow is verified in: test/integration/mcp-gas-validation/auth-workflow.test.ts
*
* - Browser integration, callback handling, error scenarios - These require
* real OAuth server interaction and are covered by integration tests.
*
* Unit tests here verify: tool properties, input schema validation.
* Integration tests verify: actual authentication flow, token persistence.
* =========================================================================
*/
describe.skip('status mode', () => {
// SKIPPED: Tests try to stub private methods/properties
});
});