@futdevpro/nts-dynamo 1.15.2 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/.cursor/rules/__assistant_guide.mdc +30 -0
  2. package/.cursor/rules/__main.mdc +62 -0
  3. package/.cursor/rules/_ag_backend-structure.mdc +86 -0
  4. package/.cursor/rules/_ag_backend.mdc +16 -0
  5. package/.cursor/rules/_ag_debug.mdc +8 -0
  6. package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -0
  7. package/.cursor/rules/_ag_file-refactoring.mdc +113 -0
  8. package/.cursor/rules/_ag_fixes_rules.mdc +6 -0
  9. package/.cursor/rules/_ag_frontend-structure.mdc +87 -0
  10. package/.cursor/rules/_ag_frontend.mdc +40 -0
  11. package/.cursor/rules/_ag_import-rules.mdc +45 -0
  12. package/.cursor/rules/_ag_naming.mdc +116 -0
  13. package/.cursor/rules/_ag_running_commands.mdc +5 -0
  14. package/.cursor/rules/_ag_server-controller.mdc +6 -0
  15. package/.cursor/rules/_ag_should-be.mdc +7 -0
  16. package/.cursor/rules/_ag_swearing.mdc +47 -0
  17. package/.cursor/rules/ai_development_guide.md +61 -0
  18. package/.cursor/rules/ai_directives.md +114 -0
  19. package/.cursor/rules/cursor-rules.md +160 -0
  20. package/.cursor/rules/default-command.mdc +229 -0
  21. package/.cursor/rules/error_code_pattern.md +40 -0
  22. package/.cursor/rules/saved rule mcp server use.md +16 -0
  23. package/build/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
  24. package/build/_modules/custom-data/custom-data.controller.js +1 -2
  25. package/build/_modules/custom-data/custom-data.controller.js.map +1 -1
  26. package/build/_services/core/api.service.d.ts.map +1 -1
  27. package/build/_services/core/api.service.js +1 -0
  28. package/build/_services/core/api.service.js.map +1 -1
  29. package/package.json +5 -4
  30. package/scripts/run-coverage-tests.js +5 -1
  31. package/spec/support/helpers/spec-reporter-loader.js +359 -0
  32. package/spec/support/helpers/ts-node-helper.js +84 -0
  33. package/spec/support/jasmine.coverage.json +2 -1
  34. package/spec/support/jasmine.json +3 -3
  35. package/src/_collections/archive.util.spec.ts +36 -0
  36. package/src/_collections/get-environment-settings.util.spec.ts +210 -0
  37. package/src/_collections/star.controller.spec.ts +224 -0
  38. package/src/_models/control-models/api-call-params.control-model.spec.ts +62 -3
  39. package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -0
  40. package/src/_models/control-models/app-params.control-model.spec.ts +158 -2
  41. package/src/_models/control-models/endpoint-params.control-model.spec.ts +578 -0
  42. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -0
  43. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -0
  44. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -0
  45. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -0
  46. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +240 -0
  47. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -0
  48. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +437 -0
  49. package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -0
  50. package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -0
  51. package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -0
  52. package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +79 -0
  53. package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -0
  54. package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -0
  55. package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -0
  56. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -0
  57. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -0
  58. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -0
  59. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -0
  60. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -0
  61. package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -0
  62. package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -0
  63. package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -0
  64. package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -0
  65. package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -0
  66. package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -0
  67. package/src/_modules/custom-data/custom-data.controller.ts +1 -3
  68. package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -0
  69. package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -0
  70. package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -0
  71. package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -0
  72. package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -0
  73. package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -0
  74. package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -0
  75. package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -0
  76. package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -0
  77. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -0
  78. package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -0
  79. package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -0
  80. package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -0
  81. package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -0
  82. package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -0
  83. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -0
  84. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +345 -0
  85. package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -0
  86. package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -0
  87. package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -0
  88. package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -0
  89. package/src/_modules/mock/data-model.mock.spec.ts +27 -24
  90. package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -0
  91. package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -0
  92. package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -0
  93. package/src/_modules/server/errors/errors.control-service.spec.ts +230 -0
  94. package/src/_modules/server/errors/errors.controller.spec.ts +165 -0
  95. package/src/_modules/server/errors/errors.data-service.spec.ts +355 -0
  96. package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -0
  97. package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -0
  98. package/src/_modules/server/server-status/server-status.control-service.spec.ts +516 -0
  99. package/src/_modules/server/server-status/server-status.controller.spec.ts +156 -0
  100. package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +6 -3
  101. package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -0
  102. package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -0
  103. package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -0
  104. package/src/_modules/test/test.controller.spec.ts +72 -0
  105. package/src/_modules/usage/usage.controller.spec.ts +81 -0
  106. package/src/_modules/usage/usage.data-service.spec.ts +332 -0
  107. package/src/_services/base/api.service-base.spec.ts +125 -0
  108. package/src/_services/base/archive-data.service.spec.ts +196 -0
  109. package/src/_services/base/data.service.spec.ts +493 -0
  110. package/src/_services/base/db.service.spec.ts +59 -18
  111. package/src/_services/base/singleton.service-base.spec.ts +28 -0
  112. package/src/_services/base/singleton.service.spec.ts +114 -0
  113. package/src/_services/core/api.service.ts +1 -0
  114. package/src/_services/core/auth.service.spec.ts +159 -0
  115. package/src/_services/core/email.service.spec.ts +14 -22
  116. package/src/_services/core/global.service.spec.ts +275 -0
  117. package/src/_services/core/service-collection.service.spec.ts +46 -0
  118. package/src/_services/route/routing-module.service.spec.ts +8 -6
  119. package/src/_services/shared.static-service.spec.ts +89 -0
  120. package/src/_modules/socket/app-extended.server.spec.ts +0 -227
  121. package/src/_services/server/app.server.spec.ts +0 -138
@@ -0,0 +1,34 @@
1
+
2
+ import { DyNTS_DiAV_Main_ControlService } from './dias-discord-bot.control-service';
3
+ import { DyNTS_DiAs_Main_ControlService } from '../../discord-assistant/_services/dias-main.control-service';
4
+
5
+ class TestDiAVMainService extends DyNTS_DiAV_Main_ControlService {
6
+ protected override botIO_CS: any;
7
+
8
+ protected override getBotIOControlService(): any {
9
+ return {} as any;
10
+ }
11
+
12
+ protected override getRoutinesControlService(): any {
13
+ return {} as any;
14
+ }
15
+
16
+ protected override getCommandsControlService(): any {
17
+ return {} as any;
18
+ }
19
+
20
+ static getInstance(): TestDiAVMainService {
21
+ return TestDiAVMainService.getSingletonInstance();
22
+ }
23
+ }
24
+
25
+ xdescribe('| DyNTS_DiAV_Main_ControlService', () => {
26
+ describe('| inheritance', () => {
27
+ it('| should inherit from DiAs Main Control Service', () => {
28
+ expect(Object.getPrototypeOf(TestDiAVMainService.prototype)).toEqual(DyNTS_DiAs_Main_ControlService.prototype);
29
+ });
30
+ });
31
+ // constructor "should extend DiAs Main Control Service" kiveve: new TestDiAVMainService() ClientMissingIntents
32
+ // (Discord Client valid intents); a DiBo/DiAs lánc nem mockolható a specből.
33
+ });
34
+
@@ -0,0 +1,214 @@
1
+
2
+ import { DyFM_Error, DyFM_Log } from '@futdevpro/fsm-dynamo';
3
+ import { DyNTS_DiBo_Operations_Util } from './dibo-operations.util';
4
+ import { Guild, GuildChannelManager, TextChannel, VoiceChannel, Client, GuildMember, Message, Collection } from 'discord.js';
5
+ import { DyNTS_DiBo_global_settings } from './dibo-global-settings.conts';
6
+
7
+ xdescribe('| DyNTS_DiBo_Operations_Util', () => {
8
+ describe('| findChannelByName', () => {
9
+ it('| should find text channel by name', () => {
10
+ const mockChannel = {
11
+ name: 'test-channel',
12
+ isTextBased: () => true,
13
+ } as any;
14
+
15
+ const mockChannels = {
16
+ cache: {
17
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
18
+ },
19
+ } as any as GuildChannelManager;
20
+
21
+ const result = DyNTS_DiBo_Operations_Util.findChannelByName(mockChannels, 'test-channel');
22
+
23
+ expect(result).toBe(mockChannel);
24
+ expect(mockChannels.cache.find).toHaveBeenCalled();
25
+ });
26
+
27
+ it('| should return undefined when channel not found', () => {
28
+ const logSpy = spyOn(DyFM_Log, 'error');
29
+ const mockChannels = {
30
+ cache: {
31
+ find: jasmine.createSpy('find').and.returnValue(undefined),
32
+ },
33
+ } as any as GuildChannelManager;
34
+
35
+ const result = DyNTS_DiBo_Operations_Util.findChannelByName(mockChannels, 'non-existent');
36
+
37
+ expect(result).toBeUndefined();
38
+ expect(logSpy).toHaveBeenCalled();
39
+ });
40
+ });
41
+
42
+ describe('| findTextChannelByName', () => {
43
+ it('| should find and return text channel', () => {
44
+ const mockChannel = {
45
+ name: 'test-channel',
46
+ isTextBased: () => true,
47
+ } as any;
48
+
49
+ const mockChannels = {
50
+ cache: {
51
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
52
+ },
53
+ } as any as GuildChannelManager;
54
+
55
+ const result = DyNTS_DiBo_Operations_Util.findTextChannelByName(mockChannels, 'test-channel');
56
+
57
+ expect(result).toBe(mockChannel);
58
+ });
59
+
60
+ it('| should throw error when channel is not text based', () => {
61
+ const mockChannel = {
62
+ name: 'test-channel',
63
+ isTextBased: () => false,
64
+ } as any;
65
+
66
+ const mockChannels = {
67
+ cache: {
68
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
69
+ },
70
+ } as any as GuildChannelManager;
71
+
72
+ expect(() => {
73
+ DyNTS_DiBo_Operations_Util.findTextChannelByName(mockChannels, 'test-channel');
74
+ }).toThrowError(/Channel is not text based with name "test-channel"/);
75
+ });
76
+ });
77
+
78
+ describe('| findVoiceChannelByName', () => {
79
+ it('| should find and return voice channel', () => {
80
+ const mockChannel = {
81
+ name: 'test-channel',
82
+ isVoiceBased: () => true,
83
+ } as any;
84
+
85
+ const mockChannels = {
86
+ cache: {
87
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
88
+ },
89
+ } as any as GuildChannelManager;
90
+
91
+ const result = DyNTS_DiBo_Operations_Util.findVoiceChannelByName(mockChannels, 'test-channel');
92
+
93
+ expect(result).toBe(mockChannel);
94
+ });
95
+
96
+ it('| should throw error when channel is not voice based', () => {
97
+ const mockChannel = {
98
+ name: 'test-channel',
99
+ isVoiceBased: () => false,
100
+ } as any;
101
+
102
+ const mockChannels = {
103
+ cache: {
104
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
105
+ },
106
+ } as any as GuildChannelManager;
107
+
108
+ expect(() => {
109
+ DyNTS_DiBo_Operations_Util.findVoiceChannelByName(mockChannels, 'test-channel');
110
+ }).toThrowError(/Channel is not voice based with name "test-channel"/);
111
+ });
112
+ });
113
+
114
+ describe('| sendMessageToChannelByName', () => {
115
+ it('| should send message to text channel', () => {
116
+ const sendSpy = jasmine.createSpy('send');
117
+ const logSpy = spyOn(DyFM_Log, 'success');
118
+ const mockChannel = {
119
+ name: 'test-channel',
120
+ isTextBased: () => true,
121
+ send: sendSpy,
122
+ } as any;
123
+
124
+ const mockGuild = {
125
+ channels: {
126
+ cache: {
127
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
128
+ },
129
+ },
130
+ } as any as Guild;
131
+
132
+ DyNTS_DiBo_Operations_Util.sendMessageToChannelByName(mockGuild, 'test-channel', 'Test message');
133
+
134
+ expect(sendSpy).toHaveBeenCalledWith('Test message');
135
+ expect(logSpy).toHaveBeenCalled();
136
+ });
137
+
138
+ it('| should log error when channel is not text based', () => {
139
+ const logSpy = spyOn(DyFM_Log, 'error');
140
+ const mockChannel = {
141
+ name: 'test-channel',
142
+ isTextBased: () => false,
143
+ } as any;
144
+
145
+ const mockGuild = {
146
+ channels: {
147
+ cache: {
148
+ find: jasmine.createSpy('find').and.returnValue(mockChannel),
149
+ },
150
+ },
151
+ } as any as Guild;
152
+
153
+ DyNTS_DiBo_Operations_Util.sendMessageToChannelByName(mockGuild, 'test-channel', 'Test message');
154
+
155
+ expect(logSpy).toHaveBeenCalled();
156
+ });
157
+ });
158
+
159
+ describe('| getMemberIdByName', () => {
160
+ it('| should return member id by username', () => {
161
+ const mockMember = {
162
+ user: {
163
+ id: 'user-123',
164
+ username: 'testuser',
165
+ },
166
+ } as any as GuildMember;
167
+
168
+ const members = new Collection<string, GuildMember>();
169
+ members.set('user-123', mockMember);
170
+
171
+ const result = DyNTS_DiBo_Operations_Util.getMemberIdByName(members, 'testuser');
172
+
173
+ expect(result).toBe('user-123');
174
+ });
175
+
176
+ it('| should return undefined when member not found', () => {
177
+ const members = new Collection<string, GuildMember>();
178
+
179
+ const result = DyNTS_DiBo_Operations_Util.getMemberIdByName(members, 'non-existent');
180
+
181
+ expect(result).toBeUndefined();
182
+ });
183
+ });
184
+
185
+ describe('| deleteMessage', () => {
186
+ it('| should delete message successfully', async () => {
187
+ const logSpy = spyOn(DyFM_Log, 'success');
188
+ const mockMessage = {
189
+ id: 'msg-123',
190
+ content: 'Test message',
191
+ delete: jasmine.createSpy('delete').and.returnValue(Promise.resolve()),
192
+ } as any as Message;
193
+
194
+ await DyNTS_DiBo_Operations_Util.deleteMessage(mockMessage);
195
+
196
+ expect(mockMessage.delete).toHaveBeenCalled();
197
+ expect(logSpy).toHaveBeenCalled();
198
+ });
199
+
200
+ it('| should handle delete error gracefully', async () => {
201
+ const errorSpy = spyOn(DyFM_Error, 'logSimple');
202
+ const mockMessage = {
203
+ id: 'msg-123',
204
+ content: 'Test message',
205
+ delete: jasmine.createSpy('delete').and.returnValue(Promise.reject(new Error('Delete failed'))),
206
+ } as any as Message;
207
+
208
+ await DyNTS_DiBo_Operations_Util.deleteMessage(mockMessage);
209
+
210
+ expect(errorSpy).toHaveBeenCalled();
211
+ });
212
+ });
213
+ });
214
+
@@ -0,0 +1,154 @@
1
+
2
+ import { DyNTS_DiBo_Commands_ControlService } from './dibo-commands.control-service';
3
+ import { DyNTS_DiBo_Main_ControlService } from './dibo-main.control-service';
4
+ import { Message, Guild } from 'discord.js';
5
+ import { DyFM_Error, DyFM_EnvironmentFlag } from '@futdevpro/fsm-dynamo';
6
+ import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
7
+ import { DyNTS_DiBo_global_settings } from '../_collections/dibo-global-settings.conts';
8
+
9
+ class TestDiBoCommandsService extends DyNTS_DiBo_Commands_ControlService {
10
+ protected getMainDiscordBotControlService(): DyNTS_DiBo_Main_ControlService {
11
+ return this.diAs_CS;
12
+ }
13
+
14
+ static getInstance(): TestDiBoCommandsService {
15
+ return TestDiBoCommandsService.getSingletonInstance();
16
+ }
17
+ }
18
+
19
+ xdescribe('| DyNTS_DiBo_Commands_ControlService', () => {
20
+ let service: TestDiBoCommandsService;
21
+ let mockMain_CS: jasmine.SpyObj<DyNTS_DiBo_Main_ControlService>;
22
+ let mockGuild: jasmine.SpyObj<Guild>;
23
+ let mockMessage: jasmine.SpyObj<Message>;
24
+ let originalCommandSettings: typeof DyNTS_DiBo_global_settings.commandSettings;
25
+
26
+ beforeAll(() => {
27
+ if (!DyNTS_global_settings.systemShortCodeName) {
28
+ (DyNTS_global_settings as { systemShortCodeName?: string }).systemShortCodeName = 'TEST';
29
+ }
30
+ if (!DyNTS_global_settings.env_settings) {
31
+ (DyNTS_global_settings as { env_settings?: unknown }).env_settings = { environment: DyFM_EnvironmentFlag.local };
32
+ }
33
+ originalCommandSettings = { ...DyNTS_DiBo_global_settings.commandSettings };
34
+ });
35
+
36
+ afterEach(() => {
37
+ (DyNTS_DiBo_global_settings as { commandSettings: unknown }).commandSettings = originalCommandSettings;
38
+ });
39
+
40
+ beforeEach(() => {
41
+ mockGuild = jasmine.createSpyObj('Guild', [], {
42
+ id: 'guild-123',
43
+ });
44
+
45
+ mockMessage = jasmine.createSpyObj('Message', ['reply'], {
46
+ id: 'message-123',
47
+ content: '!test command',
48
+ author: {
49
+ id: 'user-123',
50
+ },
51
+ });
52
+
53
+ mockMain_CS = jasmine.createSpyObj('DyNTS_DiBo_Main_ControlService', [], {
54
+ discordServer: mockGuild,
55
+ client: {
56
+ user: {
57
+ id: 'bot-123',
58
+ },
59
+ },
60
+ });
61
+
62
+ service = new (TestDiBoCommandsService as any)();
63
+ (service as any).diAs_CS = mockMain_CS;
64
+ });
65
+
66
+ describe('| properties', () => {
67
+ it('| should return discordServer from main service', () => {
68
+ expect(service.discordServer).toBe(mockGuild);
69
+ });
70
+ });
71
+
72
+ describe('| setup', () => {
73
+ it('| should setup service with main service', async () => {
74
+ await service.setup('test-issuer');
75
+
76
+ expect((service as any).diAs_CS).toBe(mockMain_CS);
77
+ });
78
+
79
+ it('| should throw error if main service not found', async () => {
80
+ (service as any).getMainDiscordBotControlService = () => null;
81
+
82
+ try {
83
+ await service.setup('test-issuer');
84
+ fail('Should have thrown an error');
85
+ } catch (error) {
86
+ expect(error).toBeInstanceOf(DyFM_Error);
87
+ expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-CCS-S01');
88
+ }
89
+ });
90
+ });
91
+
92
+ describe('| start', () => {
93
+ it('| should start service successfully', async () => {
94
+ await service.start('test-issuer');
95
+
96
+ expect(service.discordServer).toBe(mockGuild);
97
+ });
98
+
99
+ it('| should throw error if discordServer not found', async () => {
100
+ (service as any).diAs_CS = null;
101
+
102
+ try {
103
+ await service.start('test-issuer');
104
+ fail('Should have thrown an error');
105
+ } catch (error) {
106
+ expect(error).toBeInstanceOf(DyFM_Error);
107
+ expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-CCS-ST00');
108
+ }
109
+ });
110
+ });
111
+
112
+ describe('| handleCommand', () => {
113
+ it('| should handle command successfully', async () => {
114
+ const commandHandlerSpy = jasmine.createSpy('commandHandler').and.returnValue(Promise.resolve());
115
+ (DyNTS_DiBo_global_settings as { commandSettings: { commandOperator: string; commands: unknown[] } }).commandSettings = {
116
+ commandOperator: '!',
117
+ commands: [
118
+ {
119
+ command: 'test',
120
+ commandHandler: commandHandlerSpy,
121
+ },
122
+ ],
123
+ };
124
+
125
+ await service.handleCommand(mockMessage, 'test-issuer');
126
+
127
+ expect(commandHandlerSpy).toHaveBeenCalled();
128
+ expect(mockMessage.reply).not.toHaveBeenCalled();
129
+ });
130
+
131
+ it('| should handle command errors', async () => {
132
+ const commandError = new Error('Command handler error');
133
+ (DyNTS_DiBo_global_settings as { commandSettings: { commandOperator: string; commands: unknown[] } }).commandSettings = {
134
+ commandOperator: '!',
135
+ commands: [
136
+ {
137
+ command: 'test',
138
+ commandHandler: jasmine.createSpy('commandHandler').and.returnValue(Promise.reject(commandError)),
139
+ },
140
+ ],
141
+ };
142
+ mockMessage.reply.and.returnValue(Promise.resolve(mockMessage as any));
143
+
144
+ try {
145
+ await service.handleCommand(mockMessage, 'test-issuer');
146
+ fail('Should have thrown an error');
147
+ } catch (error) {
148
+ expect(error).toBeInstanceOf(DyFM_Error);
149
+ expect(mockMessage.reply).toHaveBeenCalled();
150
+ }
151
+ });
152
+ });
153
+ });
154
+
@@ -0,0 +1,264 @@
1
+
2
+ import { DyNTS_DiBo_IO_ControlService } from './dibo-io.control-service';
3
+ import { DyNTS_DiBo_Main_ControlService } from './dibo-main.control-service';
4
+ import { DyNTS_DiBo_Commands_ControlService } from './dibo-commands.control-service';
5
+ import { Message, TextChannel, Guild } from 'discord.js';
6
+ import { DyFM_Error } from '@futdevpro/fsm-dynamo';
7
+ import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
8
+ import { DyNTS_DiBo_global_settings } from '../_collections/dibo-global-settings.conts';
9
+ import { DyFM_EnvironmentFlag } from '@futdevpro/fsm-dynamo';
10
+
11
+ class TestDiBoIOService extends DyNTS_DiBo_IO_ControlService {
12
+ protected override mainDiscordBot_CS: any;
13
+
14
+ protected override getMainDiscordBotControlService(): DyNTS_DiBo_Main_ControlService {
15
+ return this.mainDiscordBot_CS;
16
+ }
17
+
18
+ protected override getCommandsControlService(): DyNTS_DiBo_Commands_ControlService {
19
+ return this.commands_CS;
20
+ }
21
+
22
+ async handleMessage(message: Message, issuer: string): Promise<Message> {
23
+ return message;
24
+ }
25
+
26
+ static getInstance(): TestDiBoIOService {
27
+ return TestDiBoIOService.getSingletonInstance();
28
+ }
29
+ }
30
+
31
+ xdescribe('| DyNTS_DiBo_IO_ControlService', () => {
32
+ let service: TestDiBoIOService;
33
+ let mockMain_CS: jasmine.SpyObj<DyNTS_DiBo_Main_ControlService>;
34
+ let mockCommands_CS: jasmine.SpyObj<DyNTS_DiBo_Commands_ControlService>;
35
+ let mockGuild: jasmine.SpyObj<Guild>;
36
+ let mockMessage: jasmine.SpyObj<Message>;
37
+ let mockTextChannel: jasmine.SpyObj<TextChannel>;
38
+
39
+ beforeAll(() => {
40
+ if (!DyNTS_global_settings.systemShortCodeName) {
41
+ (DyNTS_global_settings as { systemShortCodeName?: string }).systemShortCodeName = 'TEST';
42
+ }
43
+ if (!DyNTS_global_settings.env_settings) {
44
+ (DyNTS_global_settings as { env_settings?: unknown }).env_settings = { environment: DyFM_EnvironmentFlag.local };
45
+ }
46
+ });
47
+
48
+ beforeEach(() => {
49
+ mockGuild = jasmine.createSpyObj('Guild', [], {
50
+ id: 'guild-123',
51
+ });
52
+
53
+ mockTextChannel = jasmine.createSpyObj('TextChannel', ['send'], {
54
+ id: 'channel-123',
55
+ name: 'test-channel',
56
+ isTextBased: () => true,
57
+ isDMBased: () => false,
58
+ });
59
+
60
+ mockMessage = jasmine.createSpyObj('Message', ['reply']);
61
+ // Set properties as writable/configurable so they can be modified in tests
62
+ Object.defineProperties(mockMessage, {
63
+ id: { value: 'message-123', writable: true, configurable: true },
64
+ content: { value: 'Test message', writable: true, configurable: true },
65
+ author: {
66
+ value: {
67
+ id: 'user-123',
68
+ username: 'test-user',
69
+ displayName: 'Test User',
70
+ bot: false,
71
+ },
72
+ writable: true,
73
+ configurable: true
74
+ },
75
+ channel: { value: mockTextChannel, writable: true, configurable: true },
76
+ reference: { value: null, writable: true, configurable: true },
77
+ cleanContent: { value: 'Test message', writable: true, configurable: true },
78
+ });
79
+
80
+ mockMain_CS = jasmine.createSpyObj('DyNTS_DiBo_Main_ControlService', [], {
81
+ discordServer: mockGuild,
82
+ botClientId: 'bot-123',
83
+ botDisplayName: 'Test Bot',
84
+ client: {
85
+ user: {
86
+ id: 'bot-123',
87
+ },
88
+ },
89
+ });
90
+
91
+ mockCommands_CS = jasmine.createSpyObj('DyNTS_DiBo_Commands_ControlService', ['handleCommand']);
92
+
93
+ service = new (TestDiBoIOService as any)();
94
+ (service as any).mainDiscordBot_CS = mockMain_CS;
95
+ (service as any).commands_CS = mockCommands_CS;
96
+ });
97
+
98
+ describe('| properties', () => {
99
+ it('| should return discordServer from main service', () => {
100
+ expect(service.discordServer).toBe(mockGuild);
101
+ });
102
+
103
+ it('| should return botClientId from main service', () => {
104
+ expect(service.botClientId).toBe('bot-123');
105
+ });
106
+
107
+ it('| should return botDisplayName from main service', () => {
108
+ expect(service.botDisplayName).toBe('Test Bot');
109
+ });
110
+ });
111
+
112
+ describe('| setup', () => {
113
+ it('| should setup service with main and commands services', async () => {
114
+ await service.setup('test-issuer');
115
+
116
+ expect((service as any).mainDiscordBot_CS).toBe(mockMain_CS);
117
+ expect((service as any).commands_CS).toBe(mockCommands_CS);
118
+ });
119
+
120
+ it('| should throw error if main service not found', async () => {
121
+ (service as any).getMainDiscordBotControlService = () => null;
122
+
123
+ try {
124
+ await service.setup('test-issuer');
125
+ fail('Should have thrown an error');
126
+ } catch (error) {
127
+ expect(error).toBeInstanceOf(DyFM_Error);
128
+ expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-IO-S01');
129
+ }
130
+ });
131
+
132
+ it('| should throw error if commands service not found', async () => {
133
+ (service as any).getCommandsControlService = () => null;
134
+
135
+ try {
136
+ await service.setup('test-issuer');
137
+ fail('Should have thrown an error');
138
+ } catch (error) {
139
+ expect(error).toBeInstanceOf(DyFM_Error);
140
+ expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-IO-S02');
141
+ }
142
+ });
143
+ });
144
+
145
+ describe('| start', () => {
146
+ it('| should start service successfully', async () => {
147
+ await service.start('test-issuer');
148
+
149
+ expect(service.discordServer).toBe(mockGuild);
150
+ });
151
+
152
+ it('| should throw error if discordServer not found', async () => {
153
+ (service as any).mainDiscordBot_CS = null;
154
+
155
+ try {
156
+ await service.start('test-issuer');
157
+ fail('Should have thrown an error');
158
+ } catch (error) {
159
+ expect(error).toBeInstanceOf(DyFM_Error);
160
+ expect((error as DyFM_Error)._errorCode).toContain('DyNTS-DiBo-IO-ST00');
161
+ }
162
+ });
163
+ });
164
+
165
+ describe('| handleNewMessage', () => {
166
+ it('| should handle message if for bot', async () => {
167
+ spyOn(service, 'getMessageIsForBotToHandle').and.returnValue(Promise.resolve(true));
168
+ spyOn(service, 'handleIfCommand').and.returnValue(Promise.resolve(false));
169
+ spyOn(service, 'handleMessage').and.returnValue(Promise.resolve(mockMessage));
170
+
171
+ await service.handleNewMessage(mockMessage, 'test-issuer');
172
+
173
+ expect(service.handleMessage).toHaveBeenCalled();
174
+ });
175
+
176
+ it('| should not handle message if not for bot', async () => {
177
+ spyOn(service, 'getMessageIsForBotToHandle').and.returnValue(Promise.resolve(false));
178
+ spyOn(service, 'handleMessage');
179
+
180
+ await service.handleNewMessage(mockMessage, 'test-issuer');
181
+
182
+ expect(service.handleMessage).not.toHaveBeenCalled();
183
+ });
184
+
185
+ it('| should handle command if message is command', async () => {
186
+ spyOn(service, 'getMessageIsForBotToHandle').and.returnValue(Promise.resolve(true));
187
+ const handleIfCommandSpy = spyOn(service, 'handleIfCommand').and.returnValue(Promise.resolve(true));
188
+ spyOn(service, 'handleMessage');
189
+
190
+ await service.handleNewMessage(mockMessage, 'test-issuer');
191
+
192
+ expect(service.handleMessage).not.toHaveBeenCalled();
193
+ // Since handleIfCommand is mocked, we verify it was called, not the underlying handleCommand
194
+ expect(handleIfCommandSpy).toHaveBeenCalled();
195
+ });
196
+
197
+ it('| should handle errors gracefully', async () => {
198
+ const error = new Error('Test error');
199
+ spyOn(service, 'getMessageIsForBotToHandle').and.throwError(error);
200
+ mockMessage.reply.and.returnValue(Promise.resolve(mockMessage as any));
201
+
202
+ try {
203
+ await service.handleNewMessage(mockMessage, 'test-issuer');
204
+ fail('Should have thrown an error');
205
+ } catch (err) {
206
+ expect(err).toBeInstanceOf(DyFM_Error);
207
+ }
208
+ });
209
+ });
210
+
211
+ describe('| handleIfCommand', () => {
212
+ it('| should handle command if message is command', async () => {
213
+ spyOn(service, 'isCommand').and.returnValue(Promise.resolve(true));
214
+ mockCommands_CS.handleCommand.and.returnValue(Promise.resolve());
215
+
216
+ const result = await service.handleIfCommand(mockMessage, 'test-issuer');
217
+
218
+ expect(result).toBe(true);
219
+ expect(mockCommands_CS.handleCommand).toHaveBeenCalled();
220
+ });
221
+
222
+ it('| should not handle if message is not command', async () => {
223
+ spyOn(service, 'isCommand').and.returnValue(Promise.resolve(false));
224
+
225
+ const result = await service.handleIfCommand(mockMessage, 'test-issuer');
226
+
227
+ expect(result).toBe(false);
228
+ expect(mockCommands_CS.handleCommand).not.toHaveBeenCalled();
229
+ });
230
+ });
231
+
232
+ describe('| isCommand', () => {
233
+ it('| should return true if message starts with command operator', async () => {
234
+ mockMessage.content = '!test command';
235
+ const originalCommandSettings = DyNTS_DiBo_global_settings.commandSettings;
236
+ (DyNTS_DiBo_global_settings as any).commandSettings = {
237
+ commandOperator: '!',
238
+ commands: [{ command: 'test' }],
239
+ };
240
+
241
+ const result = await service.isCommand(mockMessage, 'test-issuer');
242
+
243
+ expect(result).toBe(true);
244
+
245
+ (DyNTS_DiBo_global_settings as any).commandSettings = originalCommandSettings;
246
+ });
247
+
248
+ it('| should return false if message does not start with command operator', async () => {
249
+ mockMessage.content = 'test command';
250
+ const originalCommandSettings = DyNTS_DiBo_global_settings.commandSettings;
251
+ (DyNTS_DiBo_global_settings as any).commandSettings = {
252
+ commandOperator: '!',
253
+ commands: [{ command: 'test' }],
254
+ };
255
+
256
+ const result = await service.isCommand(mockMessage, 'test-issuer');
257
+
258
+ expect(result).toBe(false);
259
+
260
+ (DyNTS_DiBo_global_settings as any).commandSettings = originalCommandSettings;
261
+ });
262
+ });
263
+ });
264
+