@flusys/nestjs-form-builder 6.0.1 → 6.1.0
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/cjs/controllers/form-result.controller.spec.js +257 -0
- package/cjs/controllers/form.controller.spec.js +212 -0
- package/cjs/docs/form-builder-swagger.config.spec.js +75 -0
- package/cjs/entities/index.spec.js +18 -0
- package/cjs/modules/form-builder.module.spec.js +133 -0
- package/cjs/services/form-builder-config.service.spec.js +121 -0
- package/cjs/services/form-builder-datasource.provider.spec.js +147 -0
- package/cjs/services/form-result.service.spec.js +702 -0
- package/cjs/services/form.service.spec.js +746 -0
- package/cjs/utils/computed-field.utils.spec.js +1205 -0
- package/cjs/utils/permission.utils.spec.js +118 -0
- package/fesm/controllers/form-result.controller.spec.js +253 -0
- package/fesm/controllers/form.controller.spec.js +208 -0
- package/fesm/docs/form-builder-swagger.config.spec.js +71 -0
- package/fesm/entities/index.spec.js +14 -0
- package/fesm/modules/form-builder.module.spec.js +129 -0
- package/fesm/services/form-builder-config.service.spec.js +117 -0
- package/fesm/services/form-builder-datasource.provider.spec.js +143 -0
- package/fesm/services/form-result.service.spec.js +657 -0
- package/fesm/services/form.service.spec.js +701 -0
- package/fesm/utils/computed-field.utils.spec.js +1201 -0
- package/fesm/utils/permission.utils.spec.js +114 -0
- package/package.json +3 -3
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _formbuildermodule = require("./form-builder.module");
|
|
6
|
+
const _formbuilderconstants = require("../config/form-builder.constants");
|
|
7
|
+
const _controllers = require("../controllers");
|
|
8
|
+
function _define_property(obj, key, value) {
|
|
9
|
+
if (key in obj) {
|
|
10
|
+
Object.defineProperty(obj, key, {
|
|
11
|
+
value: value,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
obj[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
function providerTokens(providers) {
|
|
22
|
+
return providers.map((p)=>typeof p === 'function' ? p : p.provide);
|
|
23
|
+
}
|
|
24
|
+
describe('FormBuilderModule', ()=>{
|
|
25
|
+
describe('forRoot', ()=>{
|
|
26
|
+
it('should default to a non-global module with all controllers registered', ()=>{
|
|
27
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRoot({});
|
|
28
|
+
expect(dynamicModule.module).toBe(_formbuildermodule.FormBuilderModule);
|
|
29
|
+
expect(dynamicModule.global).toBe(false);
|
|
30
|
+
expect(dynamicModule.controllers).toEqual([
|
|
31
|
+
_controllers.FormController,
|
|
32
|
+
_controllers.FormResultController
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
it('should respect global: true', ()=>{
|
|
36
|
+
expect(_formbuildermodule.FormBuilderModule.forRoot({
|
|
37
|
+
global: true
|
|
38
|
+
}).global).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it('should register no controllers when includeController is false', ()=>{
|
|
41
|
+
expect(_formbuildermodule.FormBuilderModule.forRoot({
|
|
42
|
+
includeController: false
|
|
43
|
+
}).controllers).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
it('should register a FORM_BUILDER_MODULE_OPTIONS provider carrying the given options', ()=>{
|
|
46
|
+
const options = {
|
|
47
|
+
bootstrapAppConfig: {
|
|
48
|
+
enableCompanyFeature: true
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRoot(options);
|
|
52
|
+
const provider = dynamicModule.providers.find((p)=>p.provide === _formbuilderconstants.FORM_BUILDER_MODULE_OPTIONS);
|
|
53
|
+
expect(provider.useValue).toBe(options);
|
|
54
|
+
});
|
|
55
|
+
it('should always export the same fixed set of services', ()=>{
|
|
56
|
+
expect(_formbuildermodule.FormBuilderModule.forRoot({}).exports).toHaveLength(4);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('forRootAsync', ()=>{
|
|
60
|
+
it('should forward external imports alongside CacheModule/UtilsModule', ()=>{
|
|
61
|
+
let FakeImportedModule = class FakeImportedModule {
|
|
62
|
+
};
|
|
63
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRootAsync({
|
|
64
|
+
imports: [
|
|
65
|
+
FakeImportedModule
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
expect(dynamicModule.imports).toEqual(expect.arrayContaining([
|
|
69
|
+
FakeImportedModule
|
|
70
|
+
]));
|
|
71
|
+
});
|
|
72
|
+
it('useFactory: builds a FORM_BUILDER_MODULE_OPTIONS provider merging resolved config', async ()=>{
|
|
73
|
+
const useFactory = jest.fn().mockResolvedValue({
|
|
74
|
+
foo: 'bar'
|
|
75
|
+
});
|
|
76
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRootAsync({
|
|
77
|
+
useFactory,
|
|
78
|
+
inject: [
|
|
79
|
+
'SOME_TOKEN'
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
const provider = dynamicModule.providers.find((p)=>p.provide === _formbuilderconstants.FORM_BUILDER_MODULE_OPTIONS);
|
|
83
|
+
expect(provider.inject).toEqual([
|
|
84
|
+
'SOME_TOKEN'
|
|
85
|
+
]);
|
|
86
|
+
const resolved = await provider.useFactory('injected');
|
|
87
|
+
expect(useFactory).toHaveBeenCalledWith('injected');
|
|
88
|
+
expect(resolved.config).toEqual({
|
|
89
|
+
foo: 'bar'
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('useClass: registers both the class provider and an options provider calling createFormBuilderOptions()', async ()=>{
|
|
93
|
+
let MyOptionsFactory = class MyOptionsFactory {
|
|
94
|
+
constructor(){
|
|
95
|
+
_define_property(this, "createFormBuilderOptions", jest.fn().mockResolvedValue({
|
|
96
|
+
foo: 'from-class'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRootAsync({
|
|
101
|
+
useClass: MyOptionsFactory
|
|
102
|
+
});
|
|
103
|
+
const classProvider = dynamicModule.providers.find((p)=>p.provide === MyOptionsFactory);
|
|
104
|
+
expect(classProvider.useClass).toBe(MyOptionsFactory);
|
|
105
|
+
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _formbuilderconstants.FORM_BUILDER_MODULE_OPTIONS);
|
|
106
|
+
const instance = new MyOptionsFactory();
|
|
107
|
+
const resolved = await optionsProvider.useFactory(instance);
|
|
108
|
+
expect(instance.createFormBuilderOptions).toHaveBeenCalled();
|
|
109
|
+
expect(resolved.config).toEqual({
|
|
110
|
+
foo: 'from-class'
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it('useExisting: registers a single options provider without a duplicate class registration', ()=>{
|
|
114
|
+
let MyOptionsFactory = class MyOptionsFactory {
|
|
115
|
+
constructor(){
|
|
116
|
+
_define_property(this, "createFormBuilderOptions", jest.fn());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRootAsync({
|
|
120
|
+
useExisting: MyOptionsFactory
|
|
121
|
+
});
|
|
122
|
+
expect(dynamicModule.providers.filter((p)=>p.provide === MyOptionsFactory)).toHaveLength(0);
|
|
123
|
+
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _formbuilderconstants.FORM_BUILDER_MODULE_OPTIONS);
|
|
124
|
+
expect(optionsProvider.inject).toEqual([
|
|
125
|
+
MyOptionsFactory
|
|
126
|
+
]);
|
|
127
|
+
});
|
|
128
|
+
it('should register no FORM_BUILDER_MODULE_OPTIONS provider when neither useFactory, useClass, nor useExisting is given', ()=>{
|
|
129
|
+
const dynamicModule = _formbuildermodule.FormBuilderModule.forRootAsync({});
|
|
130
|
+
expect(providerTokens(dynamicModule.providers)).not.toContain(_formbuilderconstants.FORM_BUILDER_MODULE_OPTIONS);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _formbuilderconfigservice = require("./form-builder-config.service");
|
|
6
|
+
function buildOptions(overrides = {}) {
|
|
7
|
+
return {
|
|
8
|
+
bootstrapAppConfig: undefined,
|
|
9
|
+
config: undefined,
|
|
10
|
+
...overrides
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
describe('FormBuilderConfigService', ()=>{
|
|
14
|
+
describe('isCompanyFeatureEnabled', ()=>{
|
|
15
|
+
it('returns false when neither tenant nor bootstrap config enable the feature', ()=>{
|
|
16
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions());
|
|
17
|
+
expect(service.isCompanyFeatureEnabled()).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
it('returns true when bootstrapAppConfig enables the feature', ()=>{
|
|
20
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
21
|
+
bootstrapAppConfig: {
|
|
22
|
+
databaseMode: 'single',
|
|
23
|
+
enableCompanyFeature: true
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
expect(service.isCompanyFeatureEnabled()).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('prefers the tenant override over bootstrapAppConfig when a tenant is passed', ()=>{
|
|
29
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
30
|
+
bootstrapAppConfig: {
|
|
31
|
+
databaseMode: 'multi-tenant',
|
|
32
|
+
enableCompanyFeature: false
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
const result = service.isCompanyFeatureEnabled({
|
|
36
|
+
enableCompanyFeature: true
|
|
37
|
+
});
|
|
38
|
+
expect(result).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it('falls back to bootstrapAppConfig when tenant does not specify enableCompanyFeature', ()=>{
|
|
41
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
42
|
+
bootstrapAppConfig: {
|
|
43
|
+
databaseMode: 'multi-tenant',
|
|
44
|
+
enableCompanyFeature: true
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
const result = service.isCompanyFeatureEnabled({
|
|
48
|
+
id: 'tenant-1'
|
|
49
|
+
});
|
|
50
|
+
expect(result).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('getDatabaseMode', ()=>{
|
|
54
|
+
it('returns the configured database mode', ()=>{
|
|
55
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
56
|
+
bootstrapAppConfig: {
|
|
57
|
+
databaseMode: 'multi-tenant'
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
expect(service.getDatabaseMode()).toBe('multi-tenant');
|
|
61
|
+
});
|
|
62
|
+
it('defaults to "single" when bootstrapAppConfig is missing', ()=>{
|
|
63
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
64
|
+
bootstrapAppConfig: undefined
|
|
65
|
+
}));
|
|
66
|
+
expect(service.getDatabaseMode()).toBe('single');
|
|
67
|
+
});
|
|
68
|
+
it('defaults to "single" when databaseMode is not set on bootstrapAppConfig', ()=>{
|
|
69
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
70
|
+
bootstrapAppConfig: {}
|
|
71
|
+
}));
|
|
72
|
+
expect(service.getDatabaseMode()).toBe('single');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('isMultiTenant', ()=>{
|
|
76
|
+
it('returns true when database mode is multi-tenant', ()=>{
|
|
77
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
78
|
+
bootstrapAppConfig: {
|
|
79
|
+
databaseMode: 'multi-tenant'
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
expect(service.isMultiTenant()).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
it('returns false when database mode is single', ()=>{
|
|
85
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
86
|
+
bootstrapAppConfig: {
|
|
87
|
+
databaseMode: 'single'
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
expect(service.isMultiTenant()).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('getOptions', ()=>{
|
|
94
|
+
it('returns the exact options object it was constructed with', ()=>{
|
|
95
|
+
const options = buildOptions({
|
|
96
|
+
config: {
|
|
97
|
+
tenants: []
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(options);
|
|
101
|
+
expect(service.getOptions()).toBe(options);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('getConfig', ()=>{
|
|
105
|
+
it('returns the config sub-object', ()=>{
|
|
106
|
+
const config = {
|
|
107
|
+
tenants: []
|
|
108
|
+
};
|
|
109
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
110
|
+
config
|
|
111
|
+
}));
|
|
112
|
+
expect(service.getConfig()).toBe(config);
|
|
113
|
+
});
|
|
114
|
+
it('returns undefined when config was never provided', ()=>{
|
|
115
|
+
const service = new _formbuilderconfigservice.FormBuilderConfigService(buildOptions({
|
|
116
|
+
config: undefined
|
|
117
|
+
}));
|
|
118
|
+
expect(service.getConfig()).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _formbuilderdatasourceprovider = require("./form-builder-datasource.provider");
|
|
6
|
+
const _entities = require("../entities");
|
|
7
|
+
function buildConfigService(overrides = {}) {
|
|
8
|
+
const options = {
|
|
9
|
+
bootstrapAppConfig: {
|
|
10
|
+
databaseMode: 'single'
|
|
11
|
+
},
|
|
12
|
+
config: {
|
|
13
|
+
defaultDatabaseConfig: {
|
|
14
|
+
type: 'mysql',
|
|
15
|
+
host: 'localhost',
|
|
16
|
+
port: 3306,
|
|
17
|
+
username: 'root',
|
|
18
|
+
password: 'password',
|
|
19
|
+
database: 'flusys_test'
|
|
20
|
+
},
|
|
21
|
+
tenantDefaultDatabaseConfig: undefined,
|
|
22
|
+
tenants: []
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
getOptions: jest.fn().mockReturnValue(options),
|
|
27
|
+
isCompanyFeatureEnabled: jest.fn().mockReturnValue(overrides.isCompanyFeatureEnabled ?? false)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
describe('FormBuilderDataSourceProvider', ()=>{
|
|
31
|
+
afterEach(()=>{
|
|
32
|
+
// Reset the isolated static caches this provider owns so tests don't leak state between runs.
|
|
33
|
+
_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.tenantConnections = new Map();
|
|
34
|
+
_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.singleDataSource = null;
|
|
35
|
+
_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.tenantsRegistry = new Map();
|
|
36
|
+
_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.initialized = false;
|
|
37
|
+
_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.connectionLocks = new Map();
|
|
38
|
+
_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.singleConnectionLock = null;
|
|
39
|
+
});
|
|
40
|
+
it('constructs and forwards bootstrap/database config to the base class', ()=>{
|
|
41
|
+
const configService = buildConfigService();
|
|
42
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
43
|
+
expect(configService.getOptions).toHaveBeenCalled();
|
|
44
|
+
expect(provider.getDatabaseMode()).toBe('single');
|
|
45
|
+
expect(provider.isMultiTenant()).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
it('reflects multi-tenant mode from bootstrapAppConfig', ()=>{
|
|
48
|
+
const configService = buildConfigService();
|
|
49
|
+
configService.getOptions.mockReturnValue({
|
|
50
|
+
bootstrapAppConfig: {
|
|
51
|
+
databaseMode: 'multi-tenant'
|
|
52
|
+
},
|
|
53
|
+
config: {}
|
|
54
|
+
});
|
|
55
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
56
|
+
expect(provider.isMultiTenant()).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
it('owns isolated static caches, separate from the base MultiTenantDataSourceService', ()=>{
|
|
59
|
+
// Each DataSource Provider must override BOTH static cache properties and the
|
|
60
|
+
// methods that read them — otherwise modules would share connections (see FLUSYS_NEST/CLAUDE.md).
|
|
61
|
+
expect(_formbuilderdatasourceprovider.FormBuilderDataSourceProvider.tenantConnections).not.toBe(Object.getPrototypeOf(_formbuilderdatasourceprovider.FormBuilderDataSourceProvider).tenantConnections);
|
|
62
|
+
});
|
|
63
|
+
describe('getFormBuilderEntities', ()=>{
|
|
64
|
+
it('returns core entities (no company feature) using the config service default', async ()=>{
|
|
65
|
+
const configService = buildConfigService({
|
|
66
|
+
isCompanyFeatureEnabled: false
|
|
67
|
+
});
|
|
68
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
69
|
+
const entities = await provider.getFormBuilderEntities();
|
|
70
|
+
expect(entities).toEqual([
|
|
71
|
+
_entities.Form,
|
|
72
|
+
_entities.FormResult
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
it('returns company entities using the config service default', async ()=>{
|
|
76
|
+
const configService = buildConfigService({
|
|
77
|
+
isCompanyFeatureEnabled: true
|
|
78
|
+
});
|
|
79
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
80
|
+
const entities = await provider.getFormBuilderEntities();
|
|
81
|
+
expect(entities).toEqual([
|
|
82
|
+
_entities.FormWithCompany,
|
|
83
|
+
_entities.FormResult
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
it('allows an explicit enableCompanyFeature override, bypassing config service', async ()=>{
|
|
87
|
+
const configService = buildConfigService({
|
|
88
|
+
isCompanyFeatureEnabled: false
|
|
89
|
+
});
|
|
90
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
91
|
+
const entities = await provider.getFormBuilderEntities(true);
|
|
92
|
+
expect(entities).toEqual([
|
|
93
|
+
_entities.FormWithCompany,
|
|
94
|
+
_entities.FormResult
|
|
95
|
+
]);
|
|
96
|
+
expect(configService.isCompanyFeatureEnabled).not.toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('createDataSourceFromConfig', ()=>{
|
|
100
|
+
it('builds a DataSource using core entities when company feature disabled', async ()=>{
|
|
101
|
+
const configService = buildConfigService({
|
|
102
|
+
isCompanyFeatureEnabled: false
|
|
103
|
+
});
|
|
104
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
105
|
+
const fakeDataSource = {
|
|
106
|
+
isInitialized: true
|
|
107
|
+
};
|
|
108
|
+
const superSpy = jest.spyOn(Object.getPrototypeOf(Object.getPrototypeOf(provider)), 'createDataSourceFromConfig').mockResolvedValue(fakeDataSource);
|
|
109
|
+
const config = {
|
|
110
|
+
type: 'mysql',
|
|
111
|
+
host: 'localhost',
|
|
112
|
+
port: 3306,
|
|
113
|
+
username: 'root',
|
|
114
|
+
password: 'password',
|
|
115
|
+
database: 'flusys_test'
|
|
116
|
+
};
|
|
117
|
+
const result = await provider.createDataSourceFromConfig(config);
|
|
118
|
+
expect(superSpy).toHaveBeenCalledWith(config, [
|
|
119
|
+
_entities.Form,
|
|
120
|
+
_entities.FormResult
|
|
121
|
+
]);
|
|
122
|
+
expect(result).toBe(fakeDataSource);
|
|
123
|
+
superSpy.mockRestore();
|
|
124
|
+
});
|
|
125
|
+
it('builds a DataSource using company entities when company feature enabled', async ()=>{
|
|
126
|
+
const configService = buildConfigService({
|
|
127
|
+
isCompanyFeatureEnabled: true
|
|
128
|
+
});
|
|
129
|
+
const provider = new _formbuilderdatasourceprovider.FormBuilderDataSourceProvider(configService, undefined);
|
|
130
|
+
const fakeDataSource = {
|
|
131
|
+
isInitialized: true
|
|
132
|
+
};
|
|
133
|
+
const superSpy = jest.spyOn(Object.getPrototypeOf(Object.getPrototypeOf(provider)), 'createDataSourceFromConfig').mockResolvedValue(fakeDataSource);
|
|
134
|
+
const config = {
|
|
135
|
+
type: 'mysql',
|
|
136
|
+
database: 'flusys_test'
|
|
137
|
+
};
|
|
138
|
+
const result = await provider.createDataSourceFromConfig(config);
|
|
139
|
+
expect(superSpy).toHaveBeenCalledWith(config, [
|
|
140
|
+
_entities.FormWithCompany,
|
|
141
|
+
_entities.FormResult
|
|
142
|
+
]);
|
|
143
|
+
expect(result).toBe(fakeDataSource);
|
|
144
|
+
superSpy.mockRestore();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|