import { DyNTS_DiBo_Routines_ControlService } from './dibo-routines.control-service'; import { DyNTS_DiBo_Main_ControlService } from './dibo-main.control-service'; import { Guild } from 'discord.js'; import { DyFM_Error } from '@futdevpro/fsm-dynamo'; class TestDiBoRoutinesService extends DyNTS_DiBo_Routines_ControlService { protected getMainDiscordBotControlService(): DyNTS_DiBo_Main_ControlService { return this.mainDiscordBot_CS; } async startRoutines(issuer: string): Promise { // Mock implementation } static getInstance(): TestDiBoRoutinesService { return TestDiBoRoutinesService.getSingletonInstance(); } } xdescribe('| DyNTS_DiBo_Routines_ControlService', () => { let service: TestDiBoRoutinesService; let mockMain_CS: jasmine.SpyObj; let mockGuild: jasmine.SpyObj; beforeEach(() => { mockGuild = jasmine.createSpyObj('Guild', [], { id: 'guild-123', }); mockMain_CS = jasmine.createSpyObj('DyNTS_DiBo_Main_ControlService', [], { discordServer: mockGuild, }); service = new (TestDiBoRoutinesService as any)(); (service as any).mainDiscordBot_CS = mockMain_CS; }); describe('| properties', () => { it('| should return discordServer from main service', () => { expect(service.discordServer).toBe(mockGuild); }); it('| should return routinesStarted as false initially', () => { expect(service.routinesStarted).toBeUndefined(); }); }); describe('| setup', () => { it('| should setup service with main service', async () => { await service.setup('test-issuer'); expect((service as any).mainDiscordBot_CS).toBe(mockMain_CS); }); it('| should throw error if main service not found', async () => { (service as any).getMainDiscordBotControlService = () => null; try { await service.setup('test-issuer'); fail('Should have thrown an error'); } catch (error) { expect(error).toBeInstanceOf(DyFM_Error); expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-RCS-S01'); } }); }); describe('| start', () => { it('| should start routines and set routinesStarted to true', async () => { spyOn(service, 'startRoutines').and.returnValue(Promise.resolve()); await service.start('test-issuer'); expect(service.startRoutines).toHaveBeenCalled(); expect(service.routinesStarted).toBe(true); }); it('| should throw error if discordServer not found', async () => { (service as any).mainDiscordBot_CS = null; try { await service.start('test-issuer'); fail('Should have thrown an error'); } catch (error) { expect(error).toBeInstanceOf(DyFM_Error); expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-RCS-ST01'); } }); it('| should handle start errors', async () => { const error = new Error('Start routines error'); spyOn(service, 'startRoutines').and.returnValue(Promise.reject(error)); try { await service.start('test-issuer'); fail('Should have thrown an error'); } catch (err) { expect(err).toBeInstanceOf(DyFM_Error); expect((err as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-RCS-ST0'); } }); }); });