Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/__tests__/handlerRefactoringIntegration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Integration test to verify the refactored handlers work correctly
*/

describe('Handler Refactoring Integration', () => {
test('should have all handler files in their respective modules', () => {
const fs = require('fs');
const path = require('path');

const expectedHandlers = [
'src/modules/lfg/handlers/LFGInteractionHandler.js',
'src/modules/lfg/handlers/LFGMessageHandler.js',
'src/modules/lfg/handlers/LFGCleanupTask.js',
'src/modules/music/handlers/MusicInteractionHandler.js',
'src/modules/reminders/handlers/RemindersInteractionHandler.js',
'src/modules/tickets/handlers/TicketsInteractionHandler.js',
'src/modules/moderation/handlers/ModerationInteractionHandler.js',
'src/modules/tempvc/handlers/TempVCInteractionHandler.js',
'src/modules/selfrole/handlers/SelfRoleInteractionHandler.js',
'src/modules/templates/handlers/TemplatesInteractionHandler.js',
'src/modules/utils/handlers/UtilsInteractionHandler.js'
];

expectedHandlers.forEach(handlerPath => {
const fullPath = path.join(__dirname, '../../', handlerPath);
expect(fs.existsSync(fullPath)).toBe(true);
});
});

test('should have refactored main interaction handlers', () => {
const fs = require('fs');
const path = require('path');

// Check that the main handlers are much smaller now
const buttonHandlerPath = path.join(__dirname, '../interactionHandlers/buttonInteractionHandler.js');
const modalHandlerPath = path.join(__dirname, '../interactionHandlers/modalSubmitHandler.js');

expect(fs.existsSync(buttonHandlerPath)).toBe(true);
expect(fs.existsSync(modalHandlerPath)).toBe(true);

// Check that they are delegation-based (should be much smaller)
const buttonHandlerContent = fs.readFileSync(buttonHandlerPath, 'utf8');
const modalHandlerContent = fs.readFileSync(modalHandlerPath, 'utf8');

// Should contain imports from modules
expect(buttonHandlerContent).toContain('require(\'../modules/');
expect(modalHandlerContent).toContain('require(\'../modules/');

// Should be much smaller than the original (delegation pattern)
expect(buttonHandlerContent.length).toBeLessThan(5000); // Much smaller than original ~50KB
expect(modalHandlerContent.length).toBeLessThan(3000);
});

test('should be able to import all refactored handlers without errors', () => {
expect(() => {
require('../modules/lfg/handlers/LFGInteractionHandler');
require('../modules/music/handlers/MusicInteractionHandler');
require('../modules/reminders/handlers/RemindersInteractionHandler');
require('../modules/tickets/handlers/TicketsInteractionHandler');
require('../modules/moderation/handlers/ModerationInteractionHandler');
require('../modules/tempvc/handlers/TempVCInteractionHandler');
require('../modules/selfrole/handlers/SelfRoleInteractionHandler');
require('../modules/templates/handlers/TemplatesInteractionHandler');
require('../modules/utils/handlers/UtilsInteractionHandler');
}).not.toThrow();
});

test('should have consistent handler interface across all modules', () => {
const handlers = [
require('../modules/lfg/handlers/LFGInteractionHandler'),
require('../modules/music/handlers/MusicInteractionHandler'),
require('../modules/reminders/handlers/RemindersInteractionHandler'),
require('../modules/tickets/handlers/TicketsInteractionHandler'),
require('../modules/tempvc/handlers/TempVCInteractionHandler'),
require('../modules/selfrole/handlers/SelfRoleInteractionHandler'),
require('../modules/templates/handlers/TemplatesInteractionHandler'),
require('../modules/utils/handlers/UtilsInteractionHandler')
];

// All handlers should export a class or object with handleButtonInteraction method
handlers.forEach(handler => {
expect(handler).toBeDefined();
expect(typeof handler.handleButtonInteraction).toBe('function');
});
});
});
2 changes: 1 addition & 1 deletion src/events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { handleAutocomplete } = require('../interactionHandlers/autocompleteHandl
const { handleButtonInteraction } = require('../interactionHandlers/buttonInteractionHandler');
const { handleSelectMenuInteraction } = require('../interactionHandlers/selectMenuInteractionHandler');
const { handleModalSubmit } = require('../interactionHandlers/modalSubmitHandler');
const ticketAssignModalHandler = require('../interactionHandlers/ticketAssignModalHandler');
const ticketAssignModalHandler = require('../modules/tickets/handlers/ticketAssignModalHandler');

module.exports = {
name: 'interactionCreate',
Expand Down
2 changes: 1 addition & 1 deletion src/events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Events, EmbedBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } = require('discord.js');
const ChatBot = require('../utils/ChatBot');
const LFGMessageHandler = require('../handlers/lfg/LFGMessageHandler');
const LFGMessageHandler = require('../modules/lfg/handlers/LFGMessageHandler');
const timeParser = require('../utils/timeParser');
const Reminder = require('../schemas/Reminder');
const User = require('../schemas/User');
Expand Down
2 changes: 1 addition & 1 deletion src/events/messageDelete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Events } = require('discord.js');
const LFGMessageHandler = require('../handlers/lfg/LFGMessageHandler');
const LFGMessageHandler = require('../modules/lfg/handlers/LFGMessageHandler');

module.exports = {
name: Events.MessageDelete,
Expand Down
2 changes: 1 addition & 1 deletion src/events/messageUpdate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Events } = require('discord.js');
const LFGMessageHandler = require('../handlers/lfg/LFGMessageHandler');
const LFGMessageHandler = require('../modules/lfg/handlers/LFGMessageHandler');

module.exports = {
name: Events.MessageUpdate,
Expand Down
2 changes: 1 addition & 1 deletion src/events/ready.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ActivityType } = require('discord.js');
const Guild = require('../schemas/Guild');
const WelcomeSystem = require('../utils/WelcomeSystem');
const LFGCleanupTask = require('../handlers/lfg/LFGCleanupTask');
const LFGCleanupTask = require('../modules/lfg/handlers/LFGCleanupTask');

module.exports = {
name: 'ready',
Expand Down
33 changes: 0 additions & 33 deletions src/handlers/lfg/LFGCleanupTask.js

This file was deleted.

201 changes: 0 additions & 201 deletions src/handlers/lfg/LFGMessageHandler.js

This file was deleted.

Loading