@futdevpro/nts-dynamo 1.9.50 → 1.10.2
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/.eslintrc.json +1 -0
- package/.github/workflows/main.yml +57 -3
- package/build/_collections/archive.util.spec.d.ts +2 -0
- package/build/_collections/archive.util.spec.d.ts.map +1 -0
- package/build/_collections/archive.util.spec.js +21 -0
- package/build/_collections/archive.util.spec.js.map +1 -0
- package/build/_models/control-models/api-call-params.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/api-call-params.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/api-call-params.control-model.spec.js +82 -0
- package/build/_models/control-models/api-call-params.control-model.spec.js.map +1 -0
- package/build/_models/control-models/app-params.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/app-params.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/app-params.control-model.spec.js +59 -0
- package/build/_models/control-models/app-params.control-model.spec.js.map +1 -0
- package/build/_models/control-models/app-system-controls.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/app-system-controls.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/app-system-controls.control-model.spec.js +26 -0
- package/build/_models/control-models/app-system-controls.control-model.spec.js.map +1 -0
- package/build/_models/control-models/endpoint-params.control-model.d.ts +1 -1
- package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js +3 -3
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/control-models/http-settings.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/http-settings.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/http-settings.control-model.spec.js +62 -0
- package/build/_models/control-models/http-settings.control-model.spec.js.map +1 -0
- package/build/_models/control-models/system-control.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/system-control.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/system-control.control-model.spec.js +24 -0
- package/build/_models/control-models/system-control.control-model.spec.js.map +1 -0
- package/build/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
- package/build/_modules/custom-data/custom-data.controller.js +3 -3
- package/build/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/build/_modules/custom-data/custom-data.data-service.d.ts +1 -1
- package/build/_modules/custom-data/custom-data.data-service.d.ts.map +1 -1
- package/build/_modules/custom-data/custom-data.data-service.js +3 -3
- package/build/_modules/custom-data/custom-data.data-service.js.map +1 -1
- package/build/_modules/mock/app-params.mock.spec.d.ts +2 -0
- package/build/_modules/mock/app-params.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/app-params.mock.spec.js +19 -0
- package/build/_modules/mock/app-params.mock.spec.js.map +1 -0
- package/build/_modules/mock/auth-service.mock.spec.d.ts +2 -0
- package/build/_modules/mock/auth-service.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/auth-service.mock.spec.js +40 -0
- package/build/_modules/mock/auth-service.mock.spec.js.map +1 -0
- package/build/_modules/mock/controller.mock.spec.d.ts +2 -0
- package/build/_modules/mock/controller.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/controller.mock.spec.js +23 -0
- package/build/_modules/mock/controller.mock.spec.js.map +1 -0
- package/build/_modules/mock/data-model.mock.spec.d.ts +2 -0
- package/build/_modules/mock/data-model.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/data-model.mock.spec.js +99 -0
- package/build/_modules/mock/data-model.mock.spec.js.map +1 -0
- package/build/_modules/mock/email-service-collection.mock.spec.d.ts +2 -0
- package/build/_modules/mock/email-service-collection.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/email-service-collection.mock.spec.js +21 -0
- package/build/_modules/mock/email-service-collection.mock.spec.js.map +1 -0
- package/build/_modules/mock/email-service.mock.spec.d.ts +2 -0
- package/build/_modules/mock/email-service.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/email-service.mock.spec.js +14 -0
- package/build/_modules/mock/email-service.mock.spec.js.map +1 -0
- package/build/_modules/mock/socket-client.mock.js +2 -2
- package/build/_modules/mock/socket-client.mock.spec.d.ts +2 -0
- package/build/_modules/mock/socket-client.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/socket-client.mock.spec.js +32 -0
- package/build/_modules/mock/socket-client.mock.spec.js.map +1 -0
- package/build/_modules/mock/socket-server.mock.spec.d.ts +2 -0
- package/build/_modules/mock/socket-server.mock.spec.d.ts.map +1 -0
- package/build/_modules/mock/socket-server.mock.spec.js +36 -0
- package/build/_modules/mock/socket-server.mock.spec.js.map +1 -0
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.d.ts +2 -0
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.d.ts.map +1 -0
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.js +22 -0
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.js.map +1 -0
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.d.ts +2 -0
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.d.ts.map +1 -0
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.js +29 -0
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.js.map +1 -0
- package/build/_modules/socket/_services/socket-server.service.js +1 -1
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_modules/usage/usage.controller.d.ts.map +1 -1
- package/build/_modules/usage/usage.controller.js +6 -4
- package/build/_modules/usage/usage.controller.js.map +1 -1
- package/build/_modules/usage/usage.data-service.d.ts +4 -4
- package/build/_modules/usage/usage.data-service.d.ts.map +1 -1
- package/build/_modules/usage/usage.data-service.js +2 -2
- package/build/_modules/usage/usage.data-service.js.map +1 -1
- package/build/_services/base/data.service.d.ts +7 -5
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +153 -13
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/base/db.service.d.ts +2 -1
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +49 -19
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/base/singleton.service-base.d.ts.map +1 -1
- package/build/_services/base/singleton.service-base.js.map +1 -1
- package/build/_services/core/api.service.d.ts +1 -1
- package/build/_services/core/api.service.js +2 -2
- package/build/_services/core/api.service.spec.d.ts +2 -0
- package/build/_services/core/api.service.spec.d.ts.map +1 -0
- package/build/_services/core/api.service.spec.js +75 -0
- package/build/_services/core/api.service.spec.js.map +1 -0
- package/build/_services/core/email.service.d.ts +6 -6
- package/build/_services/core/email.service.d.ts.map +1 -1
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/email.service.spec.d.ts +2 -0
- package/build/_services/core/email.service.spec.d.ts.map +1 -0
- package/build/_services/core/email.service.spec.js +77 -0
- package/build/_services/core/email.service.spec.js.map +1 -0
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +2 -1
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/route/controller.service.d.ts +3 -3
- package/build/_services/route/controller.service.js +2 -2
- package/build/_services/route/controller.service.spec.d.ts +2 -0
- package/build/_services/route/controller.service.spec.d.ts.map +1 -0
- package/build/_services/route/controller.service.spec.js +48 -0
- package/build/_services/route/controller.service.spec.js.map +1 -0
- package/build/_services/route/routing-module.service.spec.d.ts +2 -0
- package/build/_services/route/routing-module.service.spec.d.ts.map +1 -0
- package/build/_services/route/routing-module.service.spec.js +65 -0
- package/build/_services/route/routing-module.service.spec.js.map +1 -0
- package/build/_services/server/app.server.d.ts +5 -5
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +9 -7
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +8 -8
- package/spec/support/jasmine.json +8 -0
- package/src/_collections/archive.util.spec.ts +22 -0
- package/src/_models/control-models/api-call-params.control-model.spec.ts +94 -0
- package/src/_models/control-models/app-params.control-model.spec.ts +69 -0
- package/src/_models/control-models/app-system-controls.control-model.spec.ts +31 -0
- package/src/_models/control-models/endpoint-params.control-model.ts +7 -6
- package/src/_models/control-models/http-settings.control-model.spec.ts +66 -0
- package/src/_models/control-models/system-control.control-model.spec.ts +27 -0
- package/src/_modules/custom-data/custom-data.controller.ts +6 -6
- package/src/_modules/custom-data/custom-data.data-service.ts +4 -3
- package/src/_modules/mock/app-params.mock.spec.ts +21 -0
- package/src/_modules/mock/auth-service.mock.spec.ts +47 -0
- package/src/_modules/mock/controller.mock.spec.ts +26 -0
- package/src/_modules/mock/data-model.mock.spec.ts +109 -0
- package/src/_modules/mock/email-service-collection.mock.spec.ts +24 -0
- package/src/_modules/mock/email-service.mock.spec.ts +17 -0
- package/src/_modules/mock/socket-client.mock.spec.ts +40 -0
- package/src/_modules/mock/socket-client.mock.ts +4 -4
- package/src/_modules/mock/socket-server.mock.spec.ts +44 -0
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +30 -0
- package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +33 -0
- package/src/_modules/socket/_services/socket-server.service.ts +1 -1
- package/src/_modules/test/get-test-routing-module.util.ts +2 -2
- package/src/_modules/usage/usage.controller.ts +10 -8
- package/src/_modules/usage/usage.data-service.ts +10 -7
- package/src/_services/base/data.service.ts +235 -17
- package/src/_services/base/db.service.ts +50 -12
- package/src/_services/base/singleton.service-base.ts +0 -2
- package/src/_services/core/api.service.spec.ts +96 -0
- package/src/_services/core/api.service.ts +2 -2
- package/src/_services/core/email.service.spec.ts +93 -0
- package/src/_services/core/email.service.ts +9 -11
- package/src/_services/core/global.service.ts +3 -2
- package/src/_services/route/controller.service.spec.ts +52 -0
- package/src/_services/route/controller.service.ts +3 -3
- package/src/_services/route/routing-module.service.spec.ts +81 -0
- package/src/_services/server/app.server.ts +26 -24
|
@@ -45,7 +45,7 @@ export class DyNTS_ApiService {
|
|
|
45
45
|
public static async startApiCall<T_Response, T_Body = any>(
|
|
46
46
|
/**
|
|
47
47
|
* you must setup the basic api call params with this.
|
|
48
|
-
* follow the instructions in the constructor: new
|
|
48
|
+
* follow the instructions in the constructor: new DyNTS_ApiCall_Params({ ... })
|
|
49
49
|
*/
|
|
50
50
|
callParams: DyNTS_ApiCall_Params,
|
|
51
51
|
/**
|
|
@@ -133,7 +133,7 @@ export class DyNTS_ApiService {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/* private static setupQueryParams<T_Body = any>(
|
|
136
|
-
inputParams: DyNTS_ApiCallInputParams<T_Body>, callParams:
|
|
136
|
+
inputParams: DyNTS_ApiCallInputParams<T_Body>, callParams: DyNTS_ApiCall_Params) {
|
|
137
137
|
const httpParams = new HttpParams();
|
|
138
138
|
|
|
139
139
|
for (const queryParamKey in inputParams.queryParams) {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
3
|
+
import { DyNTS_EmailService, DyNTS_EmailService_Settings, DyNTS_EmailTemplateComponent, DyNTS_SendEmail_Settings } from './email.service';
|
|
4
|
+
|
|
5
|
+
describe('DyNTS_EmailService', () => {
|
|
6
|
+
let emailService: DyNTS_EmailService;
|
|
7
|
+
const settings: DyNTS_EmailService_Settings = {
|
|
8
|
+
host: 'smtp.example.com',
|
|
9
|
+
port: 587,
|
|
10
|
+
email: 'test@example.com',
|
|
11
|
+
pass: 'password',
|
|
12
|
+
senderName: 'Test Sender',
|
|
13
|
+
rootPath: '/path/to/templates',
|
|
14
|
+
templateComponents: [
|
|
15
|
+
new DyNTS_EmailTemplateComponent({
|
|
16
|
+
name: 'testComponent',
|
|
17
|
+
selector: 'test-selector',
|
|
18
|
+
template: '<div>{{property}}</div>',
|
|
19
|
+
properties: [ 'property' ],
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
emailService = new DyNTS_EmailService(settings);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should initialize with correct settings', () => {
|
|
29
|
+
expect(emailService.serviceName).toBe('DyNTS_EmailService');
|
|
30
|
+
expect(emailService['senderName']).toBe(settings.senderName);
|
|
31
|
+
expect(emailService['senderNEmail']).toBe(`${settings.senderName} <${settings.email}>`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should load email template components', async () => {
|
|
35
|
+
await emailService.asyncPostConstruct();
|
|
36
|
+
expect(emailService['componentsByName']['testComponent']).toBeDefined();
|
|
37
|
+
expect(emailService['componentsBySelector']['test-selector']).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
xit('should send email with direct content', async () => {
|
|
41
|
+
const sendEmailSettings: DyNTS_SendEmail_Settings = {
|
|
42
|
+
to: 'recipient@example.com',
|
|
43
|
+
subject: 'Test Subject',
|
|
44
|
+
content: '<p>Test Content</p>',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
await emailService.sendEmail(sendEmailSettings, 'testIssuer');
|
|
48
|
+
// No error should be thrown
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should throw error if no template component name is provided', async () => {
|
|
52
|
+
const sendEmailSettings: DyNTS_SendEmail_Settings = {
|
|
53
|
+
to: 'recipient@example.com',
|
|
54
|
+
subject: 'Test Subject',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
await expectAsync(emailService.sendEmail(sendEmailSettings, 'testIssuer'))
|
|
58
|
+
.toBeRejectedWith(jasmine.any(DyFM_Error));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should throw error if template component is not found', async () => {
|
|
62
|
+
const sendEmailSettings: DyNTS_SendEmail_Settings = {
|
|
63
|
+
to: 'recipient@example.com',
|
|
64
|
+
subject: 'Test Subject',
|
|
65
|
+
templateComponentName: 'nonExistentComponent',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
await expectAsync(emailService.sendEmail(sendEmailSettings, 'testIssuer'))
|
|
69
|
+
.toBeRejectedWith(jasmine.any(DyFM_Error));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
xit('should compile template component correctly', async () => {
|
|
73
|
+
const compiledTemplate = await emailService['compileTemplateComponent'](
|
|
74
|
+
'testComponent',
|
|
75
|
+
{ property: 'value' },
|
|
76
|
+
'testIssuer'
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(compiledTemplate).toContain('<div>value</div>');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should throw error if template property is missing', async () => {
|
|
83
|
+
const component = new DyNTS_EmailTemplateComponent({
|
|
84
|
+
name: 'testComponent',
|
|
85
|
+
selector: 'test-selector',
|
|
86
|
+
template: '<div>{{missingProperty}}</div>',
|
|
87
|
+
properties: [ 'missingProperty' ],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await expectAsync(emailService['compileComponentProperties'](component, {}, '', 'testIssuer'))
|
|
91
|
+
.toBeRejectedWith(jasmine.any(DyFM_Error));
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import * as FileSystem from 'fs';
|
|
3
|
-
import * as Path from 'path';
|
|
4
3
|
import * as NodeMailer from 'nodemailer';
|
|
5
4
|
|
|
6
|
-
import { Options as MailOptions
|
|
5
|
+
import { Attachment, Options as MailOptions } from 'nodemailer/lib/mailer';
|
|
7
6
|
|
|
8
|
-
import {
|
|
9
|
-
DyFM_AnyError, DyFM_Array, DyFM_Error, DyFM_Error_Settings, DyFM_Log
|
|
7
|
+
import {
|
|
8
|
+
DyFM_AnyError, DyFM_Array, DyFM_Error, DyFM_Error_Settings, DyFM_Log
|
|
10
9
|
} from '@futdevpro/fsm-dynamo';
|
|
11
|
-
import { DyNTS_SingletonService } from '../base/singleton.service';
|
|
12
10
|
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
13
11
|
|
|
14
12
|
export interface DyNTS_EmailService_Settings {
|
|
@@ -63,15 +61,15 @@ export interface DyNTS_SendEmail_Settings<T = { [propertyKey: string]: string; }
|
|
|
63
61
|
export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
64
62
|
serviceName: string;
|
|
65
63
|
|
|
66
|
-
private nmTransporter: NodeMailer.Transporter;
|
|
67
|
-
private senderName: string;
|
|
68
|
-
private senderNEmail: string;
|
|
64
|
+
private readonly nmTransporter: NodeMailer.Transporter;
|
|
65
|
+
private readonly senderName: string;
|
|
66
|
+
private readonly senderNEmail: string;
|
|
69
67
|
|
|
70
|
-
private components: DyNTS_EmailTemplateComponent[] = [];
|
|
71
|
-
private componentsBySelector: {
|
|
68
|
+
private readonly components: DyNTS_EmailTemplateComponent[] = [];
|
|
69
|
+
private readonly componentsBySelector: {
|
|
72
70
|
[selector: string]: DyNTS_EmailTemplateComponent
|
|
73
71
|
} = {};
|
|
74
|
-
private componentsByName: {
|
|
72
|
+
private readonly componentsByName: {
|
|
75
73
|
[componentName: string]: DyNTS_EmailTemplateComponent
|
|
76
74
|
} = {};
|
|
77
75
|
|
|
@@ -225,8 +225,9 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
225
225
|
}
|
|
226
226
|
} catch (error) {
|
|
227
227
|
DyFM_Log.error(
|
|
228
|
-
`NTS GLOBAL MULTILEVEL ERROR:
|
|
229
|
-
error
|
|
228
|
+
`NTS GLOBAL MULTILEVEL ERROR: ` +
|
|
229
|
+
`\nFailed to handle error on globalErrorHandler.`,
|
|
230
|
+
(error as DyFM_Error)?.getErrorSimplified?.() ?? error
|
|
230
231
|
);
|
|
231
232
|
}
|
|
232
233
|
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
|
|
3
|
+
import { DyNTS_Endpoint_Params } from '../../_models/control-models/endpoint-params.control-model';
|
|
4
|
+
import { DyNTS_Controller } from './controller.service';
|
|
5
|
+
|
|
6
|
+
class TestController extends DyNTS_Controller {
|
|
7
|
+
setupEndpoints(): void {
|
|
8
|
+
this.endpoints = [
|
|
9
|
+
new DyNTS_Endpoint_Params({
|
|
10
|
+
name: 'testEndpoint',
|
|
11
|
+
type: DyNTS_HttpCallType.get,
|
|
12
|
+
endpoint: '/test-endpoint',
|
|
13
|
+
preProcesses: [],
|
|
14
|
+
tasks: [
|
|
15
|
+
async (req: any, res: any) => {
|
|
16
|
+
res.send({ message: 'Test successful' });
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
}),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static getInstance(): TestController {
|
|
24
|
+
return new TestController();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('DyNTS_Controller', () => {
|
|
29
|
+
let controller: TestController;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
controller = TestController.getInstance();
|
|
33
|
+
controller.setupEndpoints();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should initialize endpoints correctly', () => {
|
|
37
|
+
expect(controller.endpoints.length).toBe(1);
|
|
38
|
+
expect(controller.endpoints[0].name).toBe('testEndpoint');
|
|
39
|
+
expect(controller.endpoints[0].endpoint).toBe('/test-endpoint');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/* it('should execute task and send response', async () => {
|
|
43
|
+
const req = {};
|
|
44
|
+
const res = {
|
|
45
|
+
send: jasmine.createSpy('send'),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
await controller.endpoints[0].tasks[0](req, res);
|
|
49
|
+
|
|
50
|
+
expect(res.send).toHaveBeenCalledWith({ message: 'Test successful' });
|
|
51
|
+
}); */
|
|
52
|
+
});
|
|
@@ -23,7 +23,7 @@ import { DyNTS_SingletonService } from '../base/singleton.service';
|
|
|
23
23
|
* this.authService = AuthService.getInstance();
|
|
24
24
|
*
|
|
25
25
|
* this.endpoints = [
|
|
26
|
-
* new
|
|
26
|
+
* new DyNTS_Endpoint_Params({
|
|
27
27
|
* name: 'getUserMatchStatistics',
|
|
28
28
|
* type: DyNX_HttpCallType.get,
|
|
29
29
|
* endpoint: '/get/user-match-statistics/:userId',
|
|
@@ -54,7 +54,7 @@ export abstract class DyNTS_Controller extends DyNTS_SingletonService {
|
|
|
54
54
|
* @example
|
|
55
55
|
*
|
|
56
56
|
* this.endpoints = [
|
|
57
|
-
* new
|
|
57
|
+
* new DyNTS_Endpoint_Params({
|
|
58
58
|
* name: 'getUserMatchStatistics',
|
|
59
59
|
* type: DyNX_HttpCallType.get,
|
|
60
60
|
* endpoint: '/get/user-match-statistics/:userId',
|
|
@@ -102,7 +102,7 @@ export abstract class DyNTS_Controller extends DyNTS_SingletonService {
|
|
|
102
102
|
* this.authService = AuthService.getInstance();
|
|
103
103
|
*
|
|
104
104
|
* this.endpoints = [
|
|
105
|
-
* new
|
|
105
|
+
* new DyNTS_Endpoint_Params({
|
|
106
106
|
* name: 'getUserMatchStatistics',
|
|
107
107
|
* type: DyNX_HttpCallType.get,
|
|
108
108
|
* endpoint: '/get/user-match-statistics/:userId',
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
3
|
+
import { DyNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
|
|
4
|
+
import { DyNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
5
|
+
import { DyNTS_Endpoint_Params } from '../../_models/control-models/endpoint-params.control-model';
|
|
6
|
+
import {
|
|
7
|
+
DyNTS_RoutingModule_Settings
|
|
8
|
+
} from '../../_models/interfaces/routing-module-settings.interface';
|
|
9
|
+
import { DyNTS_Controller } from './controller.service';
|
|
10
|
+
import { DyNTS_RoutingModule } from './routing-module.service';
|
|
11
|
+
|
|
12
|
+
describe('DyNTS_RoutingModule', () => {
|
|
13
|
+
let routingModule: DyNTS_RoutingModule;
|
|
14
|
+
let mockController: DyNTS_Controller;
|
|
15
|
+
let mockEndpoint: DyNTS_Endpoint_Params;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockController = {
|
|
19
|
+
setupEndpoints: jasmine.createSpy('setupEndpoints'),
|
|
20
|
+
endpoints: [],
|
|
21
|
+
} as unknown as DyNTS_Controller;
|
|
22
|
+
|
|
23
|
+
mockEndpoint = {
|
|
24
|
+
endpoint: '/test',
|
|
25
|
+
type: DyNTS_HttpCallType.get,
|
|
26
|
+
getFullExecution: jasmine.createSpy('getFullExecution'),
|
|
27
|
+
security: DyNTS_RouteSecurity.open,
|
|
28
|
+
} as any as DyNTS_Endpoint_Params;
|
|
29
|
+
|
|
30
|
+
const settings: DyNTS_RoutingModule_Settings = {
|
|
31
|
+
route: '/test',
|
|
32
|
+
controllers: [ mockController ],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
routingModule = new DyNTS_RoutingModule(settings);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should initialize with given settings', () => {
|
|
39
|
+
expect(routingModule.route).toContain('/test');
|
|
40
|
+
expect(routingModule.endpoints.length).toBe(0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should setup routes by calling setupEndpoints on each controller', () => {
|
|
44
|
+
routingModule['setupRoutes']();
|
|
45
|
+
expect(mockController.setupEndpoints).toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should add endpoints from controllers to the routing module', () => {
|
|
49
|
+
mockController.endpoints = [ mockEndpoint ];
|
|
50
|
+
routingModule['setupRoutes']();
|
|
51
|
+
expect(routingModule.endpoints).toContain(mockEndpoint);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
xit('should mount open routes correctly', () => {
|
|
55
|
+
routingModule.endpoints = [ mockEndpoint ];
|
|
56
|
+
routingModule['mountOpenRoute'](mockEndpoint);
|
|
57
|
+
expect(routingModule.openRouter.stack.length).toBeGreaterThan(0);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
xit('should mount secure routes correctly', () => {
|
|
61
|
+
mockEndpoint.security = DyNTS_RouteSecurity.secure;
|
|
62
|
+
routingModule.endpoints = [ mockEndpoint ];
|
|
63
|
+
routingModule['mountSecureRoute'](mockEndpoint);
|
|
64
|
+
expect(routingModule.secureRouter.stack.length).toBeGreaterThan(0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
xit('should throw error for invalid route type in open route', () => {
|
|
68
|
+
mockEndpoint.type = 'invalid' as DyNTS_HttpCallType;
|
|
69
|
+
expect(() => routingModule['mountOpenRoute'](mockEndpoint)).toThrow(DyFM_Error);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
xit('should throw error for invalid route type in secure route', () => {
|
|
73
|
+
mockEndpoint.type = 'invalid' as DyNTS_HttpCallType;
|
|
74
|
+
expect(() => routingModule['mountSecureRoute'](mockEndpoint)).toThrow(DyFM_Error);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should handle endpoint duplication error', () => {
|
|
78
|
+
routingModule.endpoints = [ mockEndpoint, mockEndpoint ];
|
|
79
|
+
expect(() => routingModule['mountRoutes']()).toThrowError(/ENDPOINT DUPLICATION/);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -4,41 +4,43 @@ import Express = require('express');
|
|
|
4
4
|
/* import Mongoose from 'mongoose';
|
|
5
5
|
import Express from 'express'; */
|
|
6
6
|
|
|
7
|
+
import * as BodyParser from 'body-parser';
|
|
8
|
+
import * as FileSystem from 'fs';
|
|
7
9
|
import * as Http from 'http';
|
|
8
10
|
import * as Https from 'https';
|
|
9
|
-
import * as FileSystem from 'fs';
|
|
10
|
-
import * as BodyParser from 'body-parser';
|
|
11
11
|
|
|
12
12
|
/* import { version } from '../../../package.json'; */
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
15
|
DyFM_AnyError,
|
|
16
|
-
DyFM_Array,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
DyFM_Array,
|
|
17
|
+
DyFM_delay,
|
|
18
|
+
DyFM_Error, DyFM_error_defaults,
|
|
19
|
+
DyFM_Error_Settings,
|
|
20
|
+
DyFM_ErrorLevel, DyFM_Log,
|
|
21
|
+
DyFM_wait,
|
|
22
|
+
second
|
|
21
23
|
} from '@futdevpro/fsm-dynamo';
|
|
22
24
|
|
|
23
|
-
import {
|
|
25
|
+
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
24
26
|
import { DyNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
+
import { DyNTS_App_Params } from '../../_models/control-models/app-params.control-model';
|
|
28
|
+
import {
|
|
29
|
+
DyNTS_AppSystemControls
|
|
30
|
+
} from '../../_models/control-models/app-system-controls.control-model';
|
|
31
|
+
import {
|
|
32
|
+
DyNTS_Endpoint_Params
|
|
33
|
+
} from '../../_models/control-models/endpoint-params.control-model';
|
|
27
34
|
import { DyNTS_Http_Settings } from '../../_models/control-models/http-settings.control-model';
|
|
28
|
-
import {
|
|
29
|
-
DyNTS_Certification_Settings
|
|
35
|
+
import {
|
|
36
|
+
DyNTS_Certification_Settings
|
|
30
37
|
} from '../../_models/interfaces/certification-settings.interface';
|
|
31
|
-
import {
|
|
32
|
-
DyNTS_GlobalService_Settings
|
|
38
|
+
import {
|
|
39
|
+
DyNTS_GlobalService_Settings
|
|
33
40
|
} from '../../_models/interfaces/global-service-settings.interface';
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
} from '../../_models/control-models/endpoint-params.control-model';
|
|
38
|
-
import {
|
|
39
|
-
DyNTS_AppSystemControls
|
|
40
|
-
} from '../../_models/control-models/app-system-controls.control-model';
|
|
41
|
-
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
41
|
+
import { DyNTS_SingletonService } from '../base/singleton.service';
|
|
42
|
+
import { DyNTS_GlobalService } from '../core/global.service';
|
|
43
|
+
import { DyNTS_RoutingModule } from '../route/routing-module.service';
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* This will be the MAIN service of our server project,
|
|
@@ -167,7 +169,7 @@ import { DyNTS_global_settings } from '../../_collections/global-settings.const'
|
|
|
167
169
|
* getAppParams(): DyNTS_AppParams
|
|
168
170
|
*
|
|
169
171
|
* // this is where you connect your main services
|
|
170
|
-
* getGlobalServiceSettings():
|
|
172
|
+
* getGlobalServiceSettings(): DyNTS_GlobalService_Settings
|
|
171
173
|
*
|
|
172
174
|
* // this is where you set up your ports
|
|
173
175
|
* getPorts(): DyNTS_PortSettings
|