Migrate /privacy to new architecture (#4202)

This commit is contained in:
Abhi
2025-07-15 01:45:06 -04:00
committed by GitHub
parent 886faa2990
commit e584241141
6 changed files with 71 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ import { helpCommand } from '../ui/commands/helpCommand.js';
import { clearCommand } from '../ui/commands/clearCommand.js';
import { authCommand } from '../ui/commands/authCommand.js';
import { themeCommand } from '../ui/commands/themeCommand.js';
import { privacyCommand } from '../ui/commands/privacyCommand.js';
// Mock the command modules to isolate the service from the command implementations.
vi.mock('../ui/commands/memoryCommand.js', () => ({
@@ -29,6 +30,9 @@ vi.mock('../ui/commands/authCommand.js', () => ({
vi.mock('../ui/commands/themeCommand.js', () => ({
themeCommand: { name: 'theme', description: 'Mock Theme' },
}));
vi.mock('../ui/commands/privacyCommand.js', () => ({
privacyCommand: { name: 'privacy', description: 'Mock Privacy' },
}));
describe('CommandService', () => {
describe('when using default production loader', () => {
@@ -54,7 +58,7 @@ describe('CommandService', () => {
const tree = commandService.getCommands();
// Post-condition assertions
expect(tree.length).toBe(5);
expect(tree.length).toBe(6);
const commandNames = tree.map((cmd) => cmd.name);
expect(commandNames).toContain('auth');
@@ -62,19 +66,20 @@ describe('CommandService', () => {
expect(commandNames).toContain('help');
expect(commandNames).toContain('clear');
expect(commandNames).toContain('theme');
expect(commandNames).toContain('privacy');
});
it('should overwrite any existing commands when called again', async () => {
// Load once
await commandService.loadCommands();
expect(commandService.getCommands().length).toBe(5);
expect(commandService.getCommands().length).toBe(6);
// Load again
await commandService.loadCommands();
const tree = commandService.getCommands();
// Should not append, but overwrite
expect(tree.length).toBe(5);
expect(tree.length).toBe(6);
});
});
@@ -86,12 +91,13 @@ describe('CommandService', () => {
await commandService.loadCommands();
const loadedTree = commandService.getCommands();
expect(loadedTree.length).toBe(5);
expect(loadedTree.length).toBe(6);
expect(loadedTree).toEqual([
authCommand,
clearCommand,
helpCommand,
memoryCommand,
privacyCommand,
themeCommand,
]);
});