96 lines
2.9 KiB
TypeScript
96 lines
2.9 KiB
TypeScript
/**
|
|
* Tests for commands/config/sysprompt.ts
|
|
*/
|
|
|
|
jest.mock('node:fs', () => ({
|
|
readFileSync: jest.fn(() => 'Mock system prompt content'),
|
|
writeFileSync: jest.fn(),
|
|
existsSync: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('node:path', () => ({
|
|
...jest.requireActual('node:path'),
|
|
resolve: jest.fn((_, filename) => `/mock/path/${filename}`),
|
|
}));
|
|
|
|
jest.mock('glob', () => ({
|
|
globSync: jest.fn(() => ['/mock/path/sysprompt_cache/nous.txt']),
|
|
}));
|
|
|
|
jest.mock('discord.js', () => {
|
|
const actual = jest.requireActual('discord.js');
|
|
return {
|
|
...actual,
|
|
SlashCommandBuilder: jest.fn().mockImplementation(() => ({
|
|
setName: jest.fn().mockReturnThis(),
|
|
setDescription: jest.fn().mockReturnThis(),
|
|
addStringOption: jest.fn().mockReturnThis(),
|
|
})),
|
|
AttachmentBuilder: jest.fn().mockImplementation((buffer, options) => ({
|
|
buffer,
|
|
name: options?.name,
|
|
})),
|
|
};
|
|
});
|
|
|
|
const syspromptCommand = require('../commands/config/sysprompt');
|
|
|
|
describe('sysprompt command', () => {
|
|
let mockInteraction: {
|
|
user: { id: string };
|
|
options: { getString: jest.Mock };
|
|
reply: jest.Mock;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
process.env.ADMIN = '123456789012345678';
|
|
mockInteraction = {
|
|
user: { id: '123456789012345678' },
|
|
options: { getString: jest.fn() },
|
|
reply: jest.fn(),
|
|
};
|
|
});
|
|
|
|
it('should have correct command data structure', () => {
|
|
expect(syspromptCommand.data).toBeDefined();
|
|
expect(syspromptCommand.execute).toBeDefined();
|
|
expect(syspromptCommand.state).toBeDefined();
|
|
});
|
|
|
|
it('should reject non-admin users', async () => {
|
|
mockInteraction.user = { id: 'unauthorized-user' };
|
|
|
|
await syspromptCommand.execute(mockInteraction);
|
|
|
|
expect(mockInteraction.reply).toHaveBeenCalledWith(
|
|
'You are not authorized to change model settings'
|
|
);
|
|
});
|
|
|
|
it('should return current sysprompt for admin users', async () => {
|
|
mockInteraction.options.getString.mockReturnValue(null);
|
|
|
|
await syspromptCommand.execute(mockInteraction);
|
|
|
|
expect(mockInteraction.reply).toHaveBeenCalled();
|
|
const replyContent = mockInteraction.reply.mock.calls[0][0];
|
|
expect(replyContent.content).toContain('Current system prompt');
|
|
});
|
|
|
|
it('should handle unknown prompt name gracefully', async () => {
|
|
mockInteraction.options.getString.mockReturnValue('nonexistent_prompt');
|
|
|
|
await syspromptCommand.execute(mockInteraction);
|
|
|
|
const replyContent = mockInteraction.reply.mock.calls[0][0];
|
|
expect(replyContent.content).toContain('not found');
|
|
});
|
|
|
|
it('state function should return sysprompt content', () => {
|
|
const state = syspromptCommand.state();
|
|
expect(typeof state).toBe('string');
|
|
expect(state.length).toBeGreaterThan(0);
|
|
});
|
|
});
|