@futdevpro/nts-dynamo 1.15.2 → 1.15.5
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.
- package/.cursor/rules/__assistant_guide.mdc +30 -0
- package/.cursor/rules/__main.mdc +64 -0
- package/.cursor/rules/_ag_backend-structure.mdc +86 -0
- package/.cursor/rules/_ag_backend.mdc +16 -0
- package/.cursor/rules/_ag_debug.mdc +8 -0
- package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -0
- package/.cursor/rules/_ag_file-refactoring.mdc +113 -0
- package/.cursor/rules/_ag_fixes_rules.mdc +6 -0
- package/.cursor/rules/_ag_frontend-structure.mdc +87 -0
- package/.cursor/rules/_ag_frontend.mdc +40 -0
- package/.cursor/rules/_ag_import-rules.mdc +45 -0
- package/.cursor/rules/_ag_naming.mdc +116 -0
- package/.cursor/rules/_ag_running_commands.mdc +5 -0
- package/.cursor/rules/_ag_server-controller.mdc +6 -0
- package/.cursor/rules/_ag_should-be.mdc +7 -0
- package/.cursor/rules/_ag_swearing.mdc +47 -0
- package/.cursor/rules/ai_development_guide.md +61 -0
- package/.cursor/rules/ai_directives.md +114 -0
- package/.cursor/rules/cursor-rules.md +160 -0
- package/.cursor/rules/default-command.mdc +465 -0
- package/.cursor/rules/error_code_pattern.md +40 -0
- package/.cursor/rules/saved rule mcp server use.md +16 -0
- package/_specifications/BACKLOG.md +15 -0
- package/_specifications/TODO.md +15 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts +17 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts.map +1 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.js +3 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.js.map +1 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts +36 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts.map +1 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js +118 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js.map +1 -0
- package/build/_modules/ai/_modules/anthropic/index.d.ts +3 -0
- package/build/_modules/ai/_modules/anthropic/index.d.ts.map +1 -0
- package/build/_modules/ai/_modules/anthropic/index.js +8 -0
- package/build/_modules/ai/_modules/anthropic/index.js.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts +35 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js +129 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/index.d.ts +3 -0
- package/build/_modules/ai/_modules/fdp-ai/index.d.ts.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/index.js +8 -0
- package/build/_modules/ai/_modules/fdp-ai/index.js.map +1 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts +40 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts.map +1 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js +111 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js.map +1 -0
- package/build/_modules/ai/_modules/open-ai/index.d.ts +1 -0
- package/build/_modules/ai/_modules/open-ai/index.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/index.js +1 -0
- package/build/_modules/ai/_modules/open-ai/index.js.map +1 -1
- package/build/_modules/ai/_services/ai-user-key.service-base.d.ts +45 -0
- package/build/_modules/ai/_services/ai-user-key.service-base.d.ts.map +1 -0
- package/build/_modules/ai/_services/ai-user-key.service-base.js +15 -0
- package/build/_modules/ai/_services/ai-user-key.service-base.js.map +1 -0
- package/build/_modules/ai/index.d.ts +2 -0
- package/build/_modules/ai/index.d.ts.map +1 -1
- package/build/_modules/ai/index.js +2 -0
- package/build/_modules/ai/index.js.map +1 -1
- package/build/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
- package/build/_modules/custom-data/custom-data.controller.js +1 -2
- package/build/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/build/_modules/socket/app-extended.server.js +1 -1
- package/build/_modules/socket/app-extended.server.js.map +1 -1
- package/build/_services/base/data.service.d.ts +1 -1
- package/build/_services/base/data.service.js +1 -1
- package/build/_services/base/db.service.d.ts +1 -1
- package/build/_services/base/db.service.js +1 -1
- package/build/_services/core/api.service.d.ts.map +1 -1
- package/build/_services/core/api.service.js +1 -0
- package/build/_services/core/api.service.js.map +1 -1
- package/build/_services/core/auth.service.d.ts +2 -2
- package/build/_services/core/auth.service.js +1 -1
- package/build/_services/core/email.service.js +1 -1
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +1 -1
- package/build/_services/core/global.service.js +2 -2
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +11 -1
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +18 -4
- package/scripts/run-coverage-tests.js +5 -1
- package/spec/support/helpers/spec-reporter-loader.js +359 -0
- package/spec/support/helpers/ts-node-helper.js +84 -0
- package/spec/support/jasmine.coverage.json +2 -1
- package/spec/support/jasmine.json +3 -3
- package/src/_collections/archive.util.spec.ts +36 -0
- package/src/_collections/get-environment-settings.util.spec.ts +210 -0
- package/src/_collections/star.controller.spec.ts +224 -0
- package/src/_models/control-models/api-call-params.control-model.spec.ts +62 -3
- package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -0
- package/src/_models/control-models/app-params.control-model.spec.ts +158 -2
- package/src/_models/control-models/endpoint-params.control-model.spec.ts +578 -0
- package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -0
- package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -0
- package/src/_modules/ai/_modules/anthropic/index.ts +5 -0
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -0
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -0
- package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -0
- package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -0
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -0
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +240 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +437 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -0
- package/src/_modules/ai/_modules/open-ai/index.ts +1 -0
- package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -0
- package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -0
- package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -0
- package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +79 -0
- package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -0
- package/src/_modules/ai/index.ts +2 -0
- package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -0
- package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -0
- package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -0
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -0
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -0
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -0
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -0
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -0
- package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -0
- package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -0
- package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -0
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -0
- package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -0
- package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -0
- package/src/_modules/custom-data/custom-data.controller.ts +1 -3
- package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -0
- package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -0
- package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -0
- package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -0
- package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -0
- package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -0
- package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -0
- package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -0
- package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -0
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -0
- package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -0
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -0
- package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -0
- package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -0
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -0
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -0
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +345 -0
- package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -0
- package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -0
- package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -0
- package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -0
- package/src/_modules/mock/data-model.mock.spec.ts +27 -24
- package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -0
- package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -0
- package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -0
- package/src/_modules/server/errors/errors.control-service.spec.ts +230 -0
- package/src/_modules/server/errors/errors.controller.spec.ts +165 -0
- package/src/_modules/server/errors/errors.data-service.spec.ts +355 -0
- package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -0
- package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -0
- package/src/_modules/server/server-status/server-status.control-service.spec.ts +516 -0
- package/src/_modules/server/server-status/server-status.controller.spec.ts +156 -0
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +6 -3
- package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -0
- package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -0
- package/src/_modules/socket/app-extended.server.ts +1 -1
- package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -0
- package/src/_modules/test/test.controller.spec.ts +72 -0
- package/src/_modules/usage/usage.controller.spec.ts +81 -0
- package/src/_modules/usage/usage.data-service.spec.ts +332 -0
- package/src/_services/base/api.service-base.spec.ts +125 -0
- package/src/_services/base/archive-data.service.spec.ts +196 -0
- package/src/_services/base/data.service.spec.ts +493 -0
- package/src/_services/base/data.service.ts +1 -1
- package/src/_services/base/db.service.spec.ts +59 -18
- package/src/_services/base/db.service.ts +1 -1
- package/src/_services/base/singleton.service-base.spec.ts +28 -0
- package/src/_services/base/singleton.service.spec.ts +114 -0
- package/src/_services/core/api.service.ts +1 -0
- package/src/_services/core/auth.service.spec.ts +159 -0
- package/src/_services/core/auth.service.ts +2 -2
- package/src/_services/core/email.service.spec.ts +14 -22
- package/src/_services/core/email.service.ts +1 -1
- package/src/_services/core/global.service.spec.ts +275 -0
- package/src/_services/core/global.service.ts +2 -2
- package/src/_services/core/service-collection.service.spec.ts +46 -0
- package/src/_services/route/controller.service.ts +1 -1
- package/src/_services/route/routing-module.service.spec.ts +8 -6
- package/src/_services/server/app.server.ts +17 -1
- package/src/_services/shared.static-service.spec.ts +89 -0
- package/src/_modules/socket/app-extended.server.spec.ts +0 -227
- package/src/_services/server/app.server.spec.ts +0 -138
|
@@ -7,3 +7,87 @@ require('ts-node').register({
|
|
|
7
7
|
}
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
+
// Set default timeout for all tests immediately
|
|
11
|
+
// This ensures that failed tests timeout quickly (2 seconds) instead of running for too long
|
|
12
|
+
// We set it both immediately and in a delayed callback to ensure it works even if spec files override it
|
|
13
|
+
// NOTE: This is also set in jasmine.json and jasmine.coverage.json - keep all 3 in sync!
|
|
14
|
+
const FORCE_TIMEOUT = 2000; // 2 seconds
|
|
15
|
+
|
|
16
|
+
// Function to force timeout setting - agresszíven felülírja minden timeout beállítást
|
|
17
|
+
const forceTimeout = () => {
|
|
18
|
+
if (typeof jasmine !== 'undefined') {
|
|
19
|
+
jasmine.DEFAULT_TIMEOUT_INTERVAL = FORCE_TIMEOUT;
|
|
20
|
+
}
|
|
21
|
+
if (typeof global !== 'undefined' && global.jasmine) {
|
|
22
|
+
global.jasmine.DEFAULT_TIMEOUT_INTERVAL = FORCE_TIMEOUT;
|
|
23
|
+
}
|
|
24
|
+
// Try to access jasmine through window if available (for browser environments)
|
|
25
|
+
if (typeof window !== 'undefined' && window.jasmine) {
|
|
26
|
+
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = FORCE_TIMEOUT;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Set timeout immediately if jasmine is available
|
|
31
|
+
forceTimeout();
|
|
32
|
+
|
|
33
|
+
// Agresszív timeout felülírás - folyamatosan felülírja minden 100ms-ben
|
|
34
|
+
// Ez biztosítja, hogy még a spec fájlokban lévő timeout beállítások is felülírásra kerüljenek
|
|
35
|
+
const aggressiveTimeoutInterval = setInterval(() => {
|
|
36
|
+
forceTimeout();
|
|
37
|
+
}, 100);
|
|
38
|
+
|
|
39
|
+
// Stop the aggressive interval after 10 seconds (enough time for all tests to start)
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
clearInterval(aggressiveTimeoutInterval);
|
|
42
|
+
}, 10000);
|
|
43
|
+
|
|
44
|
+
// Hook into jasmine's environment if available
|
|
45
|
+
const initTimeout = () => {
|
|
46
|
+
// Try both global and local jasmine
|
|
47
|
+
const jasmineObj = (typeof global !== 'undefined' && global.jasmine) || (typeof jasmine !== 'undefined' ? jasmine : null);
|
|
48
|
+
|
|
49
|
+
if (jasmineObj && typeof jasmineObj.getEnv === 'function') {
|
|
50
|
+
try {
|
|
51
|
+
const env = jasmineObj.getEnv();
|
|
52
|
+
if (env) {
|
|
53
|
+
// Force timeout immediately
|
|
54
|
+
forceTimeout();
|
|
55
|
+
|
|
56
|
+
// Add a global beforeEach that runs in every spec file to force timeout
|
|
57
|
+
env.beforeEach(() => {
|
|
58
|
+
forceTimeout();
|
|
59
|
+
});
|
|
60
|
+
// Also add afterEach to ensure timeout is set after each test
|
|
61
|
+
env.afterEach(() => {
|
|
62
|
+
forceTimeout();
|
|
63
|
+
});
|
|
64
|
+
// Add a reporter that forces timeout on every spec start and done
|
|
65
|
+
// This ensures that even if a spec file sets timeout, it gets overridden
|
|
66
|
+
env.addReporter({
|
|
67
|
+
specStarted: () => {
|
|
68
|
+
forceTimeout();
|
|
69
|
+
},
|
|
70
|
+
specDone: () => {
|
|
71
|
+
forceTimeout();
|
|
72
|
+
},
|
|
73
|
+
suiteStarted: () => {
|
|
74
|
+
forceTimeout();
|
|
75
|
+
},
|
|
76
|
+
suiteDone: () => {
|
|
77
|
+
forceTimeout();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
// Ignore errors if jasmine is not fully initialized yet
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Try to initialize multiple times to catch late initialization
|
|
88
|
+
initTimeout();
|
|
89
|
+
setTimeout(initTimeout, 0);
|
|
90
|
+
setTimeout(initTimeout, 50);
|
|
91
|
+
setTimeout(initTimeout, 200);
|
|
92
|
+
setTimeout(initTimeout, 1000);
|
|
93
|
+
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"**/*[sS]pec.ts"
|
|
15
15
|
],
|
|
16
16
|
"helpers": [
|
|
17
|
-
"helpers
|
|
18
|
-
"helpers/**/*.js"
|
|
17
|
+
"../spec/support/helpers/ts-node-helper.js"
|
|
19
18
|
],
|
|
20
19
|
"env": {
|
|
21
20
|
"stopSpecOnExpectationFailure": false,
|
|
22
|
-
"random": true
|
|
21
|
+
"random": true,
|
|
22
|
+
"defaultTimeoutInterval": 2000
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -18,4 +18,40 @@ describe('| DyNTS_getArchivedDBName', () => {
|
|
|
18
18
|
const expectedArchivedName = `${dbName}_${DyNTS_archiveSuffix}`;
|
|
19
19
|
expect(DyNTS_getArchivedDBName(dbName)).toBe(expectedArchivedName);
|
|
20
20
|
});
|
|
21
|
+
|
|
22
|
+
it('| should handle database names with spaces', () => {
|
|
23
|
+
const dbName = 'Test DB Name';
|
|
24
|
+
const expectedArchivedName = `${dbName}_${DyNTS_archiveSuffix}`;
|
|
25
|
+
expect(DyNTS_getArchivedDBName(dbName)).toBe(expectedArchivedName);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('| should handle database names with numbers', () => {
|
|
29
|
+
const dbName = 'DB123';
|
|
30
|
+
const expectedArchivedName = `${dbName}_${DyNTS_archiveSuffix}`;
|
|
31
|
+
expect(DyNTS_getArchivedDBName(dbName)).toBe(expectedArchivedName);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('| should handle very long database names', () => {
|
|
35
|
+
const dbName = 'A'.repeat(100);
|
|
36
|
+
const expectedArchivedName = `${dbName}_${DyNTS_archiveSuffix}`;
|
|
37
|
+
expect(DyNTS_getArchivedDBName(dbName)).toBe(expectedArchivedName);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('| should use the correct archive suffix constant', () => {
|
|
41
|
+
expect(DyNTS_archiveSuffix).toBe('archived');
|
|
42
|
+
const dbName = 'TestDB';
|
|
43
|
+
const result = DyNTS_getArchivedDBName(dbName);
|
|
44
|
+
expect(result).toContain('archived');
|
|
45
|
+
expect(result).toBe('TestDB_archived');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('| DyNTS_archiveSuffix', () => {
|
|
50
|
+
it('| should have the correct value', () => {
|
|
51
|
+
expect(DyNTS_archiveSuffix).toBe('archived');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('| should be a string', () => {
|
|
55
|
+
expect(typeof DyNTS_archiveSuffix).toBe('string');
|
|
56
|
+
});
|
|
21
57
|
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_EnvironmentFlag, DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
3
|
+
import { DyNTS_getEnvironment_settings } from './get-environment-settings.util';
|
|
4
|
+
|
|
5
|
+
describe('| DyNTS_getEnvironment_settings', () => {
|
|
6
|
+
let originalEnv: string | undefined;
|
|
7
|
+
let originalNodeEnv: string | undefined;
|
|
8
|
+
let originalEnvironment: string | undefined;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
// Save original environment variables
|
|
12
|
+
originalEnv = process.env.ENV;
|
|
13
|
+
originalNodeEnv = process.env.NODE_ENV;
|
|
14
|
+
originalEnvironment = process.env.ENVIRONMENT;
|
|
15
|
+
|
|
16
|
+
// Clear environment variables
|
|
17
|
+
delete process.env.ENV;
|
|
18
|
+
delete process.env.NODE_ENV;
|
|
19
|
+
delete process.env.ENVIRONMENT;
|
|
20
|
+
delete process.env.DISCORD_GUILD_ID;
|
|
21
|
+
delete process.env.DISCORD_BOT_TOKEN;
|
|
22
|
+
delete process.env.DISCORD_BOT_CLIENT_ID;
|
|
23
|
+
delete process.env.DISCORD_BOT_OAUTH2_URL;
|
|
24
|
+
delete process.env.MONGO_URL;
|
|
25
|
+
delete process.env.MONGO_URI;
|
|
26
|
+
delete process.env.OPENAI_API_KEY;
|
|
27
|
+
delete process.env.OPENAI_ORGANIZATION;
|
|
28
|
+
delete process.env.OPENAI_PROJECT;
|
|
29
|
+
delete process.env.OPENAI_TTS_API_KEY;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
// Restore original environment variables
|
|
34
|
+
if (originalEnv !== undefined) {
|
|
35
|
+
process.env.ENV = originalEnv;
|
|
36
|
+
} else {
|
|
37
|
+
delete process.env.ENV;
|
|
38
|
+
}
|
|
39
|
+
if (originalNodeEnv !== undefined) {
|
|
40
|
+
process.env.NODE_ENV = originalNodeEnv;
|
|
41
|
+
} else {
|
|
42
|
+
delete process.env.NODE_ENV;
|
|
43
|
+
}
|
|
44
|
+
if (originalEnvironment !== undefined) {
|
|
45
|
+
process.env.ENVIRONMENT = originalEnvironment;
|
|
46
|
+
} else {
|
|
47
|
+
delete process.env.ENVIRONMENT;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('| should return local environment when no environment variables are set', () => {
|
|
52
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
53
|
+
|
|
54
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.local);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('| should use ENV variable when set', () => {
|
|
58
|
+
process.env.ENV = 'prod';
|
|
59
|
+
|
|
60
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
61
|
+
|
|
62
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.prod);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('| should use NODE_ENV when ENV is not set', () => {
|
|
66
|
+
process.env.NODE_ENV = 'dev';
|
|
67
|
+
|
|
68
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
69
|
+
|
|
70
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.local);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('| should use ENVIRONMENT when ENV and NODE_ENV are not set', () => {
|
|
74
|
+
process.env.ENVIRONMENT = 'test';
|
|
75
|
+
|
|
76
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
77
|
+
|
|
78
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.local);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('| should prioritize ENV over NODE_ENV and ENVIRONMENT', () => {
|
|
82
|
+
process.env.ENV = 'prod';
|
|
83
|
+
process.env.NODE_ENV = 'dev';
|
|
84
|
+
process.env.ENVIRONMENT = 'test';
|
|
85
|
+
|
|
86
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
87
|
+
|
|
88
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.prod);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('| should handle lowercase environment values', () => {
|
|
92
|
+
process.env.ENV = 'prod';
|
|
93
|
+
|
|
94
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
95
|
+
|
|
96
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.prod);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('| should log error and use local for unknown environment', () => {
|
|
100
|
+
const logSpy = spyOn(DyFM_Log, 'error');
|
|
101
|
+
process.env.ENV = 'unknown-env';
|
|
102
|
+
|
|
103
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
104
|
+
|
|
105
|
+
expect(logSpy).toHaveBeenCalled();
|
|
106
|
+
expect(settings.environment).toBe(DyFM_EnvironmentFlag.local);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('| should return discord settings from environment variables', () => {
|
|
110
|
+
process.env.DISCORD_GUILD_ID = 'guild123';
|
|
111
|
+
process.env.DISCORD_BOT_TOKEN = 'token123';
|
|
112
|
+
process.env.DISCORD_BOT_CLIENT_ID = 'client123';
|
|
113
|
+
process.env.DISCORD_BOT_OAUTH2_URL = 'https://discord.com/oauth2';
|
|
114
|
+
|
|
115
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
116
|
+
|
|
117
|
+
expect(settings.discord.guildId).toBe('guild123');
|
|
118
|
+
expect(settings.discord.token).toBe('token123');
|
|
119
|
+
expect(settings.discord.clientId).toBe('client123');
|
|
120
|
+
expect(settings.discord.oauth2Url).toBe('https://discord.com/oauth2');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('| should return undefined for discord settings when not set', () => {
|
|
124
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
125
|
+
|
|
126
|
+
expect(settings.discord.guildId).toBeUndefined();
|
|
127
|
+
expect(settings.discord.token).toBeUndefined();
|
|
128
|
+
expect(settings.discord.clientId).toBeUndefined();
|
|
129
|
+
expect(settings.discord.oauth2Url).toBeUndefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('| should return mongoUri from MONGO_URL', () => {
|
|
133
|
+
process.env.MONGO_URL = 'mongodb://localhost:27017';
|
|
134
|
+
|
|
135
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
136
|
+
|
|
137
|
+
expect(settings.mongoUri).toBe('mongodb://localhost:27017');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('| should return mongoUri from MONGO_URI when MONGO_URL is not set', () => {
|
|
141
|
+
process.env.MONGO_URI = 'mongodb://localhost:27017';
|
|
142
|
+
|
|
143
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
144
|
+
|
|
145
|
+
expect(settings.mongoUri).toBe('mongodb://localhost:27017');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('| should prioritize MONGO_URL over MONGO_URI', () => {
|
|
149
|
+
process.env.MONGO_URL = 'mongodb://localhost:27017';
|
|
150
|
+
process.env.MONGO_URI = 'mongodb://other:27017';
|
|
151
|
+
|
|
152
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
153
|
+
|
|
154
|
+
expect(settings.mongoUri).toBe('mongodb://localhost:27017');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('| should return undefined for mongoUri when not set', () => {
|
|
158
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
159
|
+
|
|
160
|
+
expect(settings.mongoUri).toBeUndefined();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('| should return openAi settings from environment variables', () => {
|
|
164
|
+
process.env.OPENAI_API_KEY = 'api-key-123';
|
|
165
|
+
process.env.OPENAI_ORGANIZATION = 'org-123';
|
|
166
|
+
process.env.OPENAI_PROJECT = 'project-123';
|
|
167
|
+
process.env.OPENAI_TTS_API_KEY = 'tts-key-123';
|
|
168
|
+
|
|
169
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
170
|
+
|
|
171
|
+
expect(settings.openAi.apiKey).toBe('api-key-123');
|
|
172
|
+
expect(settings.openAi.organization).toBe('org-123');
|
|
173
|
+
expect(settings.openAi.project).toBe('project-123');
|
|
174
|
+
expect(settings.openAi.ttsApiKey).toBe('tts-key-123');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('| should return undefined for openAi settings when not set', () => {
|
|
178
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
179
|
+
|
|
180
|
+
expect(settings.openAi.apiKey).toBeUndefined();
|
|
181
|
+
expect(settings.openAi.organization).toBeUndefined();
|
|
182
|
+
expect(settings.openAi.project).toBeUndefined();
|
|
183
|
+
expect(settings.openAi.ttsApiKey).toBeUndefined();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('| should handle dotenv.config() being called', () => {
|
|
187
|
+
// This test ensures that dotenv.config() is called without errors
|
|
188
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
189
|
+
expect(settings).toBeDefined();
|
|
190
|
+
expect(settings.environment).toBeDefined();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('| should return consistent results on multiple calls', () => {
|
|
194
|
+
const settings1 = DyNTS_getEnvironment_settings();
|
|
195
|
+
const settings2 = DyNTS_getEnvironment_settings();
|
|
196
|
+
|
|
197
|
+
expect(settings1.environment).toBe(settings2.environment);
|
|
198
|
+
expect(settings1.discord).toEqual(settings2.discord);
|
|
199
|
+
expect(settings1.mongoUri).toBe(settings2.mongoUri);
|
|
200
|
+
expect(settings1.openAi).toEqual(settings2.openAi);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('| should handle mixed case environment variables', () => {
|
|
204
|
+
process.env.ENV = 'PROD';
|
|
205
|
+
const settings = DyNTS_getEnvironment_settings();
|
|
206
|
+
// The function should handle case conversion
|
|
207
|
+
expect(settings.environment).toBeDefined();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyNTS_Star_Controller, DyNTS_getStarRoute } from './star.controller';
|
|
3
|
+
import { DyFM_HttpCallType, DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
4
|
+
import { DyNTS_RoutingModule } from '../_services/route/routing-module.service';
|
|
5
|
+
|
|
6
|
+
describe('| DyNTS_Star_Controller', () => {
|
|
7
|
+
let controller: DyNTS_Star_Controller;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
controller = DyNTS_Star_Controller.getInstance();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('| should be a singleton instance', () => {
|
|
14
|
+
const instance1 = DyNTS_Star_Controller.getInstance();
|
|
15
|
+
const instance2 = DyNTS_Star_Controller.getInstance();
|
|
16
|
+
|
|
17
|
+
expect(instance1).toBe(instance2);
|
|
18
|
+
expect(instance1).toBeInstanceOf(DyNTS_Star_Controller);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('| setupEndpoints', () => {
|
|
22
|
+
it('| should setup all default endpoints', () => {
|
|
23
|
+
controller.setupEndpoints();
|
|
24
|
+
|
|
25
|
+
expect(controller.endpoints).toBeDefined();
|
|
26
|
+
expect(controller.endpoints.length).toBe(5);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('| should setup defaultGet endpoint', () => {
|
|
30
|
+
controller.setupEndpoints();
|
|
31
|
+
|
|
32
|
+
const defaultGetEndpoint = controller.endpoints.find(ep => ep.name === 'defaultGet');
|
|
33
|
+
expect(defaultGetEndpoint).toBeDefined();
|
|
34
|
+
expect(defaultGetEndpoint?.type).toBe(DyFM_HttpCallType.get);
|
|
35
|
+
expect(defaultGetEndpoint?.endpoint).toBe('/*');
|
|
36
|
+
expect((defaultGetEndpoint as any)?.tasks).toBeDefined();
|
|
37
|
+
expect((defaultGetEndpoint as any)?.tasks?.length).toBe(1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('| should setup defaultPost endpoint', () => {
|
|
41
|
+
controller.setupEndpoints();
|
|
42
|
+
|
|
43
|
+
const defaultPostEndpoint = controller.endpoints.find(ep => ep.name === 'defaultPost');
|
|
44
|
+
expect(defaultPostEndpoint).toBeDefined();
|
|
45
|
+
expect(defaultPostEndpoint?.type).toBe(DyFM_HttpCallType.post);
|
|
46
|
+
expect(defaultPostEndpoint?.endpoint).toBe('/*');
|
|
47
|
+
expect((defaultPostEndpoint as any)?.tasks).toBeDefined();
|
|
48
|
+
expect((defaultPostEndpoint as any)?.tasks?.length).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('| should setup defaultPut endpoint', () => {
|
|
52
|
+
controller.setupEndpoints();
|
|
53
|
+
|
|
54
|
+
const defaultPutEndpoint = controller.endpoints.find(ep => ep.name === 'defaultPut');
|
|
55
|
+
expect(defaultPutEndpoint).toBeDefined();
|
|
56
|
+
expect(defaultPutEndpoint?.type).toBe(DyFM_HttpCallType.put);
|
|
57
|
+
expect(defaultPutEndpoint?.endpoint).toBe('/*');
|
|
58
|
+
expect((defaultPutEndpoint as any)?.tasks).toBeDefined();
|
|
59
|
+
expect((defaultPutEndpoint as any)?.tasks?.length).toBe(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('| should setup defaultPatch endpoint', () => {
|
|
63
|
+
controller.setupEndpoints();
|
|
64
|
+
|
|
65
|
+
const defaultPatchEndpoint = controller.endpoints.find(ep => ep.name === 'defaultPatch');
|
|
66
|
+
expect(defaultPatchEndpoint).toBeDefined();
|
|
67
|
+
expect(defaultPatchEndpoint?.type).toBe(DyFM_HttpCallType.patch);
|
|
68
|
+
expect(defaultPatchEndpoint?.endpoint).toBe('/*');
|
|
69
|
+
expect((defaultPatchEndpoint as any)?.tasks).toBeDefined();
|
|
70
|
+
expect((defaultPatchEndpoint as any)?.tasks?.length).toBe(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('| should setup defaultDelete endpoint', () => {
|
|
74
|
+
controller.setupEndpoints();
|
|
75
|
+
|
|
76
|
+
const defaultDeleteEndpoint = controller.endpoints.find(ep => ep.name === 'defaultDelete');
|
|
77
|
+
expect(defaultDeleteEndpoint).toBeDefined();
|
|
78
|
+
expect(defaultDeleteEndpoint?.type).toBe(DyFM_HttpCallType.delete);
|
|
79
|
+
expect(defaultDeleteEndpoint?.endpoint).toBe('/*');
|
|
80
|
+
expect((defaultDeleteEndpoint as any)?.tasks).toBeDefined();
|
|
81
|
+
expect((defaultDeleteEndpoint as any)?.tasks?.length).toBe(1);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('| DyNTS_getStarRoute', () => {
|
|
86
|
+
it('| should return routing module', () => {
|
|
87
|
+
const routingModule = DyNTS_getStarRoute();
|
|
88
|
+
|
|
89
|
+
expect(routingModule).toBeInstanceOf(DyNTS_RoutingModule);
|
|
90
|
+
// The route might be modified by RoutingModule, check if it contains /**
|
|
91
|
+
expect(routingModule.route).toContain('**');
|
|
92
|
+
expect((routingModule as any).controllers).toBeDefined();
|
|
93
|
+
expect((routingModule as any).controllers.length).toBe(1);
|
|
94
|
+
expect((routingModule as any).controllers[0]).toBeInstanceOf(DyNTS_Star_Controller);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('| should return routing module with correct route', () => {
|
|
98
|
+
const routingModule = DyNTS_getStarRoute();
|
|
99
|
+
expect(routingModule.route).toBe('/api/**');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('| endpoint tasks', () => {
|
|
104
|
+
it('| should throw 404 error for defaultGet endpoint', async () => {
|
|
105
|
+
controller.setupEndpoints();
|
|
106
|
+
const defaultGetEndpoint = controller.endpoints.find(ep => ep.name === 'defaultGet');
|
|
107
|
+
expect(defaultGetEndpoint).toBeDefined();
|
|
108
|
+
|
|
109
|
+
const mockReq = {
|
|
110
|
+
originalUrl: '/test-route',
|
|
111
|
+
} as any;
|
|
112
|
+
const mockRes = {} as any;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await (defaultGetEndpoint as any).tasks[0](mockReq, mockRes, 'test-issuer');
|
|
116
|
+
fail('Should have thrown an error');
|
|
117
|
+
} catch (error) {
|
|
118
|
+
expect(error).toBeInstanceOf(DyFM_Error);
|
|
119
|
+
expect((error as DyFM_Error).___status).toBe(404);
|
|
120
|
+
expect((error as DyFM_Error)._errorCode).toContain('DyNTS-RMS-G404');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('| should throw 404 error for defaultPost endpoint', async () => {
|
|
125
|
+
controller.setupEndpoints();
|
|
126
|
+
const defaultPostEndpoint = controller.endpoints.find(ep => ep.name === 'defaultPost');
|
|
127
|
+
expect(defaultPostEndpoint).toBeDefined();
|
|
128
|
+
|
|
129
|
+
const mockReq = {
|
|
130
|
+
originalUrl: '/test-route',
|
|
131
|
+
} as any;
|
|
132
|
+
const mockRes = {} as any;
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await (defaultPostEndpoint as any).tasks[0](mockReq, mockRes, 'test-issuer');
|
|
136
|
+
fail('Should have thrown an error');
|
|
137
|
+
} catch (error) {
|
|
138
|
+
expect(error).toBeInstanceOf(DyFM_Error);
|
|
139
|
+
expect((error as DyFM_Error).___status).toBe(404);
|
|
140
|
+
expect((error as DyFM_Error)._errorCode).toContain('DyNTS-RMS-PO404');
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('| should throw 404 error for defaultPut endpoint', async () => {
|
|
145
|
+
controller.setupEndpoints();
|
|
146
|
+
const defaultPutEndpoint = controller.endpoints.find(ep => ep.name === 'defaultPut');
|
|
147
|
+
expect(defaultPutEndpoint).toBeDefined();
|
|
148
|
+
|
|
149
|
+
const mockReq = {
|
|
150
|
+
originalUrl: '/test-route',
|
|
151
|
+
} as any;
|
|
152
|
+
const mockRes = {} as any;
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
await (defaultPutEndpoint as any).tasks[0](mockReq, mockRes, 'test-issuer');
|
|
156
|
+
fail('Should have thrown an error');
|
|
157
|
+
} catch (error) {
|
|
158
|
+
expect(error).toBeInstanceOf(DyFM_Error);
|
|
159
|
+
expect((error as DyFM_Error).___status).toBe(404);
|
|
160
|
+
expect((error as DyFM_Error)._errorCode).toContain('DyNTS-RMS-PU404');
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('| should throw 404 error for defaultPatch endpoint', async () => {
|
|
165
|
+
controller.setupEndpoints();
|
|
166
|
+
const defaultPatchEndpoint = controller.endpoints.find(ep => ep.name === 'defaultPatch');
|
|
167
|
+
expect(defaultPatchEndpoint).toBeDefined();
|
|
168
|
+
|
|
169
|
+
const mockReq = {
|
|
170
|
+
originalUrl: '/test-route',
|
|
171
|
+
} as any;
|
|
172
|
+
const mockRes = {} as any;
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
await (defaultPatchEndpoint as any).tasks[0](mockReq, mockRes, 'test-issuer');
|
|
176
|
+
fail('Should have thrown an error');
|
|
177
|
+
} catch (error) {
|
|
178
|
+
expect(error).toBeInstanceOf(DyFM_Error);
|
|
179
|
+
expect((error as DyFM_Error).___status).toBe(404);
|
|
180
|
+
expect((error as DyFM_Error)._errorCode).toContain('DyNTS-RMS-PA404');
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('| should throw 404 error for defaultDelete endpoint', async () => {
|
|
185
|
+
controller.setupEndpoints();
|
|
186
|
+
const defaultDeleteEndpoint = controller.endpoints.find(ep => ep.name === 'defaultDelete');
|
|
187
|
+
expect(defaultDeleteEndpoint).toBeDefined();
|
|
188
|
+
|
|
189
|
+
const mockReq = {
|
|
190
|
+
originalUrl: '/test-route',
|
|
191
|
+
} as any;
|
|
192
|
+
const mockRes = {} as any;
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
await (defaultDeleteEndpoint as any).tasks[0](mockReq, mockRes, 'test-issuer');
|
|
196
|
+
fail('Should have thrown an error');
|
|
197
|
+
} catch (error) {
|
|
198
|
+
expect(error).toBeInstanceOf(DyFM_Error);
|
|
199
|
+
expect((error as DyFM_Error).___status).toBe(404);
|
|
200
|
+
expect((error as DyFM_Error)._errorCode).toContain('DyNTS-RMS-D404');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('| should include originalUrl in error message', async () => {
|
|
205
|
+
controller.setupEndpoints();
|
|
206
|
+
const defaultGetEndpoint = controller.endpoints.find(ep => ep.name === 'defaultGet');
|
|
207
|
+
expect(defaultGetEndpoint).toBeDefined();
|
|
208
|
+
|
|
209
|
+
const mockReq = {
|
|
210
|
+
originalUrl: '/custom-route',
|
|
211
|
+
} as any;
|
|
212
|
+
const mockRes = {} as any;
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
await (defaultGetEndpoint as any).tasks[0](mockReq, mockRes, 'test-issuer');
|
|
216
|
+
fail('Should have thrown an error');
|
|
217
|
+
} catch (error) {
|
|
218
|
+
expect(error).toBeInstanceOf(DyFM_Error);
|
|
219
|
+
expect((error as DyFM_Error)._message).toContain('/custom-route');
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
@@ -46,7 +46,7 @@ describe('| DyNTS_ApiCall_Params', () => {
|
|
|
46
46
|
expect(params.httpOptions).toEqual(httpOptions);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
it('| should replace deprecated endpoint parameter braces', () => {
|
|
50
50
|
spyOn(DyFM_Log, 'warn');
|
|
51
51
|
|
|
52
52
|
const params = new DyNTS_ApiCall_Params({
|
|
@@ -57,11 +57,70 @@ describe('| DyNTS_ApiCall_Params', () => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
expect(DyFM_Log.warn).toHaveBeenCalledWith(
|
|
60
|
-
'using {param} bracets in endpoint definitions will be deprecated... (/test/{param}/endpoint)' +
|
|
61
|
-
'use :param instead ({pathparam} --> :pathparam)'
|
|
60
|
+
'WARNING: using {param} bracets in endpoint definitions will be deprecated... (/test/{param}/endpoint)' +
|
|
61
|
+
'\n use :param instead ({pathparam} --> :pathparam)'
|
|
62
62
|
);
|
|
63
63
|
expect(params.endpoint).toBe('/test/:param/endpoint');
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
it('| should extract pathParamKeys from endpoint with colons', () => {
|
|
67
|
+
const params = new DyNTS_ApiCall_Params({
|
|
68
|
+
name: 'testCall',
|
|
69
|
+
type: DyFM_HttpCallType.get,
|
|
70
|
+
endpoint: '/test/:userId/:itemId',
|
|
71
|
+
baseUrl: 'https://example.com/api',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(params.pathParamKeys).toEqual(['userId', 'itemId']);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('| should handle endpoint without path parameters', () => {
|
|
78
|
+
const params = new DyNTS_ApiCall_Params({
|
|
79
|
+
name: 'testCall',
|
|
80
|
+
type: DyFM_HttpCallType.get,
|
|
81
|
+
endpoint: '/test/endpoint',
|
|
82
|
+
baseUrl: 'https://example.com/api',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(params.pathParamKeys).toEqual([]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('| should use global baseUrl when baseUrl is not provided', () => {
|
|
89
|
+
spyOn(DyFM_Log, 'error');
|
|
90
|
+
|
|
91
|
+
const params = new DyNTS_ApiCall_Params({
|
|
92
|
+
name: 'testCall',
|
|
93
|
+
type: DyFM_HttpCallType.get,
|
|
94
|
+
endpoint: '/test/endpoint',
|
|
95
|
+
} as any);
|
|
96
|
+
|
|
97
|
+
expect(DyFM_Log.error).toHaveBeenCalled();
|
|
98
|
+
expect(params.baseUrl).toBeDefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('| should handle missing endpoint', () => {
|
|
102
|
+
spyOn(DyFM_Log, 'warn');
|
|
103
|
+
|
|
104
|
+
const params = new DyNTS_ApiCall_Params({
|
|
105
|
+
name: 'testCall',
|
|
106
|
+
type: DyFM_HttpCallType.get,
|
|
107
|
+
baseUrl: 'https://example.com/api',
|
|
108
|
+
} as any);
|
|
109
|
+
|
|
110
|
+
expect(DyFM_Log.warn).toHaveBeenCalled();
|
|
111
|
+
expect(params.endpoint).toBe('');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('| should throw error when endpoint is invalid', () => {
|
|
115
|
+
expect(() => {
|
|
116
|
+
new DyNTS_ApiCall_Params({
|
|
117
|
+
name: 'testCall',
|
|
118
|
+
type: DyFM_HttpCallType.get,
|
|
119
|
+
endpoint: { includes: false } as any,
|
|
120
|
+
baseUrl: 'https://example.com/api',
|
|
121
|
+
});
|
|
122
|
+
}).toThrowError(/DyNTS_ApiCall_Params Error: something went wrong with the endpoint, it is provided but not valid/);
|
|
123
|
+
});
|
|
65
124
|
});
|
|
66
125
|
|
|
67
126
|
describe('| DyNTS_HttpOptions', () => {
|