mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 01:23:13 +01:00
refactor(guild): introduce service layer for guild member operations
Extract business logic from handleMsgMhfOperateGuildMember into GuildService.OperateMember, establishing the handler→service→repo layering pattern. The handler is now ~20 lines of protocol glue (type-assert, map action, call service, send ACK, notify). GuildService owns authorization checks, repo coordination, mail composition, and best-effort mail delivery. It accepts plain Go types (no mhfpacket or Session imports), making it fully testable with mock repos. Cross-channel notification stays in the handler since it requires Session. Adds 7 table-driven service-level tests covering accept/reject/kick, authorization, repo errors, mail errors, and unknown actions.
This commit is contained in:
@@ -51,9 +51,16 @@ func createMockServer() *Server {
|
||||
}
|
||||
s.i18n = getLangStrings(s)
|
||||
s.Registry = NewLocalChannelRegistry([]*Server{s})
|
||||
// GuildService is wired lazily by tests that set repos then call ensureGuildService.
|
||||
return s
|
||||
}
|
||||
|
||||
// ensureGuildService wires the GuildService from the server's current repos.
|
||||
// Call this after setting guildRepo, mailRepo, and charRepo on the mock server.
|
||||
func ensureGuildService(s *Server) {
|
||||
s.guildService = NewGuildService(s.guildRepo, s.mailRepo, s.charRepo, s.logger)
|
||||
}
|
||||
|
||||
// createMockSession creates a minimal Session for testing.
|
||||
// Imported from v9.2.x-stable and adapted for main.
|
||||
func createMockSession(charID uint32, server *Server) *Session {
|
||||
|
||||
Reference in New Issue
Block a user