@flusys/nestjs-auth 6.0.2 → 6.1.1

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 (71) hide show
  1. package/cjs/controllers/authentication.controller.spec.js +219 -0
  2. package/cjs/controllers/branch.controller.spec.js +134 -0
  3. package/cjs/controllers/company-selection.controller.spec.js +84 -0
  4. package/cjs/controllers/company.controller.spec.js +131 -0
  5. package/cjs/controllers/email-verification.controller.spec.js +142 -0
  6. package/cjs/controllers/user-permission.controller.spec.js +138 -0
  7. package/cjs/controllers/user.controller.spec.js +204 -0
  8. package/cjs/docs/auth-swagger.config.spec.js +130 -0
  9. package/cjs/entities/index.spec.js +73 -0
  10. package/cjs/helpers/auth-response.mapper.js +46 -0
  11. package/cjs/helpers/auth-response.mapper.spec.js +139 -0
  12. package/cjs/helpers/index.js +19 -0
  13. package/cjs/helpers/token.helper.js +58 -0
  14. package/cjs/helpers/token.helper.spec.js +86 -0
  15. package/cjs/index.js +1 -0
  16. package/cjs/interceptors/clear-token.interceptor.spec.js +107 -0
  17. package/cjs/interceptors/set-token.interceptor.spec.js +165 -0
  18. package/cjs/modules/auth.module.spec.js +243 -0
  19. package/cjs/services/auth-config.service.spec.js +97 -0
  20. package/cjs/services/auth-datasource.provider.spec.js +161 -0
  21. package/cjs/services/auth-email.service.spec.js +404 -0
  22. package/cjs/services/authentication.service.js +37 -109
  23. package/cjs/services/authentication.service.spec.js +904 -0
  24. package/cjs/services/branch.service.spec.js +154 -0
  25. package/cjs/services/company-selection-session.service.spec.js +90 -0
  26. package/cjs/services/company.service.spec.js +113 -0
  27. package/cjs/services/user-permission.service.spec.js +202 -0
  28. package/cjs/services/user.service.spec.js +704 -0
  29. package/cjs/strategies/jwt.strategy.js +1 -1
  30. package/cjs/strategies/jwt.strategy.spec.js +166 -0
  31. package/cjs/validators/password.validator.spec.js +161 -0
  32. package/entities/pending-registration.entity.d.ts +2 -7
  33. package/fesm/controllers/authentication.controller.spec.js +215 -0
  34. package/fesm/controllers/branch.controller.spec.js +130 -0
  35. package/fesm/controllers/company-selection.controller.spec.js +80 -0
  36. package/fesm/controllers/company.controller.spec.js +127 -0
  37. package/fesm/controllers/email-verification.controller.spec.js +138 -0
  38. package/fesm/controllers/user-permission.controller.spec.js +134 -0
  39. package/fesm/controllers/user.controller.spec.js +200 -0
  40. package/fesm/docs/auth-swagger.config.spec.js +126 -0
  41. package/fesm/entities/index.spec.js +69 -0
  42. package/fesm/helpers/auth-response.mapper.js +25 -0
  43. package/fesm/helpers/auth-response.mapper.spec.js +135 -0
  44. package/fesm/helpers/index.js +2 -0
  45. package/fesm/helpers/token.helper.js +40 -0
  46. package/fesm/helpers/token.helper.spec.js +82 -0
  47. package/fesm/index.js +1 -0
  48. package/fesm/interceptors/clear-token.interceptor.spec.js +103 -0
  49. package/fesm/interceptors/set-token.interceptor.spec.js +161 -0
  50. package/fesm/interfaces/authentication.interface.js +1 -1
  51. package/fesm/modules/auth.module.spec.js +239 -0
  52. package/fesm/services/auth-config.service.spec.js +93 -0
  53. package/fesm/services/auth-datasource.provider.spec.js +157 -0
  54. package/fesm/services/auth-email.service.spec.js +359 -0
  55. package/fesm/services/authentication.service.js +37 -109
  56. package/fesm/services/authentication.service.spec.js +859 -0
  57. package/fesm/services/branch.service.spec.js +150 -0
  58. package/fesm/services/company-selection-session.service.spec.js +86 -0
  59. package/fesm/services/company.service.spec.js +109 -0
  60. package/fesm/services/user-permission.service.spec.js +198 -0
  61. package/fesm/services/user.service.spec.js +659 -0
  62. package/fesm/strategies/jwt.strategy.js +1 -1
  63. package/fesm/strategies/jwt.strategy.spec.js +162 -0
  64. package/fesm/validators/password.validator.spec.js +157 -0
  65. package/helpers/auth-response.mapper.d.ts +22 -0
  66. package/helpers/index.d.ts +2 -0
  67. package/helpers/token.helper.d.ts +8 -0
  68. package/index.d.ts +1 -0
  69. package/interfaces/authentication.interface.d.ts +7 -0
  70. package/package.json +8 -3
  71. package/services/authentication.service.d.ts +1 -8
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _authmodule = require("./auth.module");
6
+ const _authconstants = require("../config/auth.constants");
7
+ const _controllers = require("../controllers");
8
+ const _services = require("../services");
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
22
+ function providerTokens(providers) {
23
+ return providers.map((p)=>typeof p === 'function' ? p : p.provide);
24
+ }
25
+ describe('AuthModule', ()=>{
26
+ describe('forRoot', ()=>{
27
+ it('should build a non-global module by default with the minimal feature set', ()=>{
28
+ const dynamicModule = _authmodule.AuthModule.forRoot({
29
+ bootstrapAppConfig: {
30
+ enableEmailVerification: false
31
+ }
32
+ });
33
+ expect(dynamicModule.module).toBe(_authmodule.AuthModule);
34
+ expect(dynamicModule.global).toBe(false);
35
+ expect(dynamicModule.controllers).toEqual([
36
+ _controllers.AuthenticationController,
37
+ _controllers.UserController
38
+ ]);
39
+ expect(providerTokens(dynamicModule.providers)).not.toContain(_services.AuthEmailService);
40
+ expect(providerTokens(dynamicModule.providers)).not.toContain(_services.CompanyService);
41
+ });
42
+ it('should respect global: true', ()=>{
43
+ const dynamicModule = _authmodule.AuthModule.forRoot({
44
+ global: true
45
+ });
46
+ expect(dynamicModule.global).toBe(true);
47
+ });
48
+ it('should register no controllers when includeController is false', ()=>{
49
+ const dynamicModule = _authmodule.AuthModule.forRoot({
50
+ includeController: false
51
+ });
52
+ expect(dynamicModule.controllers).toEqual([]);
53
+ });
54
+ it('should enable email verification by default (bootstrapAppConfig omitted)', ()=>{
55
+ const dynamicModule = _authmodule.AuthModule.forRoot({});
56
+ expect(dynamicModule.controllers).toContain(_controllers.EmailVerificationController);
57
+ expect(providerTokens(dynamicModule.providers)).toContain(_services.AuthEmailService);
58
+ expect(dynamicModule.exports).toContain(_services.AuthEmailService);
59
+ });
60
+ it('should omit email verification controller/provider/export when explicitly disabled', ()=>{
61
+ const dynamicModule = _authmodule.AuthModule.forRoot({
62
+ bootstrapAppConfig: {
63
+ enableEmailVerification: false
64
+ }
65
+ });
66
+ expect(dynamicModule.controllers).not.toContain(_controllers.EmailVerificationController);
67
+ expect(providerTokens(dynamicModule.providers)).not.toContain(_services.AuthEmailService);
68
+ expect(dynamicModule.exports).not.toContain(_services.AuthEmailService);
69
+ });
70
+ it('should add company controllers/providers/exports when enableCompanyFeature is true', ()=>{
71
+ const dynamicModule = _authmodule.AuthModule.forRoot({
72
+ bootstrapAppConfig: {
73
+ enableCompanyFeature: true
74
+ }
75
+ });
76
+ expect(dynamicModule.controllers).toEqual(expect.arrayContaining([
77
+ _controllers.CompanySelectionController,
78
+ _controllers.CompanyController,
79
+ _controllers.BranchController,
80
+ _controllers.UserPermissionController
81
+ ]));
82
+ expect(providerTokens(dynamicModule.providers)).toEqual(expect.arrayContaining([
83
+ _services.CompanySelectionSessionService,
84
+ _services.CompanyService,
85
+ _services.BranchService,
86
+ _services.UserPermissionService
87
+ ]));
88
+ expect(dynamicModule.exports).toEqual(expect.arrayContaining([
89
+ _services.CompanyService,
90
+ _services.BranchService,
91
+ _services.UserPermissionService
92
+ ]));
93
+ });
94
+ it('should register an AUTH_MODULE_OPTIONS provider carrying the given options', ()=>{
95
+ const options = {
96
+ bootstrapAppConfig: {
97
+ enableCompanyFeature: true
98
+ }
99
+ };
100
+ const dynamicModule = _authmodule.AuthModule.forRoot(options);
101
+ const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _authconstants.AUTH_MODULE_OPTIONS);
102
+ expect(optionsProvider.useValue).toBe(options);
103
+ });
104
+ it('should append any caller-supplied extra providers', ()=>{
105
+ const extraProvider = {
106
+ provide: 'EXTRA',
107
+ useValue: 'x'
108
+ };
109
+ const dynamicModule = _authmodule.AuthModule.forRoot({
110
+ providers: [
111
+ extraProvider
112
+ ]
113
+ });
114
+ expect(dynamicModule.providers).toEqual(expect.arrayContaining([
115
+ extraProvider
116
+ ]));
117
+ });
118
+ });
119
+ describe('forRootAsync', ()=>{
120
+ it('should default AUTH_MODULE_OPTIONS to the static options when no useFactory/useClass/useExisting is given', async ()=>{
121
+ const dynamicModule = _authmodule.AuthModule.forRootAsync({
122
+ bootstrapAppConfig: {},
123
+ global: true
124
+ });
125
+ const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _authconstants.AUTH_MODULE_OPTIONS);
126
+ expect(optionsProvider.useValue).toEqual({
127
+ global: true,
128
+ includeController: undefined,
129
+ bootstrapAppConfig: {}
130
+ });
131
+ });
132
+ it('should resolve config via useFactory and merge it with the static options', async ()=>{
133
+ const useFactory = jest.fn().mockResolvedValue({
134
+ jwtSecret: 'from-factory'
135
+ });
136
+ const dynamicModule = _authmodule.AuthModule.forRootAsync({
137
+ bootstrapAppConfig: {},
138
+ useFactory,
139
+ inject: [
140
+ 'SOME_TOKEN'
141
+ ]
142
+ });
143
+ const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _authconstants.AUTH_MODULE_OPTIONS);
144
+ expect(optionsProvider.inject).toEqual([
145
+ 'SOME_TOKEN'
146
+ ]);
147
+ const resolved = await optionsProvider.useFactory('injected-value');
148
+ expect(useFactory).toHaveBeenCalledWith('injected-value');
149
+ expect(resolved).toEqual({
150
+ global: undefined,
151
+ includeController: undefined,
152
+ bootstrapAppConfig: {},
153
+ config: {
154
+ jwtSecret: 'from-factory'
155
+ }
156
+ });
157
+ });
158
+ it('should resolve config via a useClass factory', async ()=>{
159
+ let MyOptionsFactory = class MyOptionsFactory {
160
+ constructor(){
161
+ _define_property(this, "createAuthOptions", jest.fn().mockResolvedValue({
162
+ jwtSecret: 'from-class'
163
+ }));
164
+ }
165
+ };
166
+ const dynamicModule = _authmodule.AuthModule.forRootAsync({
167
+ bootstrapAppConfig: {},
168
+ useClass: MyOptionsFactory
169
+ });
170
+ const classProvider = dynamicModule.providers.find((p)=>p.provide === MyOptionsFactory);
171
+ expect(classProvider.useClass).toBe(MyOptionsFactory);
172
+ const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _authconstants.AUTH_MODULE_OPTIONS);
173
+ expect(optionsProvider.inject).toEqual([
174
+ MyOptionsFactory
175
+ ]);
176
+ const factoryInstance = new MyOptionsFactory();
177
+ const resolved = await optionsProvider.useFactory(factoryInstance);
178
+ expect(factoryInstance.createAuthOptions).toHaveBeenCalled();
179
+ expect(resolved.config).toEqual({
180
+ jwtSecret: 'from-class'
181
+ });
182
+ });
183
+ it('should resolve config via a useExisting factory', async ()=>{
184
+ let MyOptionsFactory = class MyOptionsFactory {
185
+ constructor(){
186
+ _define_property(this, "createAuthOptions", jest.fn().mockResolvedValue({
187
+ jwtSecret: 'from-existing'
188
+ }));
189
+ }
190
+ };
191
+ const dynamicModule = _authmodule.AuthModule.forRootAsync({
192
+ bootstrapAppConfig: {},
193
+ useExisting: MyOptionsFactory
194
+ });
195
+ const optionsProvider = dynamicModule.providers.find((p)=>p.provide === _authconstants.AUTH_MODULE_OPTIONS);
196
+ expect(optionsProvider.inject).toEqual([
197
+ MyOptionsFactory
198
+ ]);
199
+ const factoryInstance = new MyOptionsFactory();
200
+ const resolved = await optionsProvider.useFactory(factoryInstance);
201
+ expect(resolved.config).toEqual({
202
+ jwtSecret: 'from-existing'
203
+ });
204
+ });
205
+ it('should forward the async `imports` array into the built module', ()=>{
206
+ let FakeImportedModule = class FakeImportedModule {
207
+ };
208
+ const dynamicModule = _authmodule.AuthModule.forRootAsync({
209
+ bootstrapAppConfig: {},
210
+ imports: [
211
+ FakeImportedModule
212
+ ]
213
+ });
214
+ expect(dynamicModule.imports).toEqual(expect.arrayContaining([
215
+ FakeImportedModule
216
+ ]));
217
+ });
218
+ it('should append any caller-supplied extra providers alongside the async options provider', ()=>{
219
+ const extraProvider = {
220
+ provide: 'EXTRA',
221
+ useValue: 'x'
222
+ };
223
+ const dynamicModule = _authmodule.AuthModule.forRootAsync({
224
+ bootstrapAppConfig: {},
225
+ providers: [
226
+ extraProvider
227
+ ]
228
+ });
229
+ expect(dynamicModule.providers).toEqual(expect.arrayContaining([
230
+ extraProvider
231
+ ]));
232
+ });
233
+ });
234
+ describe('getEntities', ()=>{
235
+ it('should delegate to getAuthEntitiesByConfig with the bootstrap flags', ()=>{
236
+ const entitiesWithDefaults = _authmodule.AuthModule.getEntities({});
237
+ const entitiesWithCompany = _authmodule.AuthModule.getEntities({
238
+ enableCompanyFeature: true
239
+ });
240
+ expect(entitiesWithDefaults.length).toBeLessThan(entitiesWithCompany.length);
241
+ });
242
+ });
243
+ });
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _common = require("@nestjs/common");
6
+ const _config = require("@flusys/nestjs-core/config");
7
+ const _authconfigservice = require("./auth-config.service");
8
+ jest.mock('@flusys/nestjs-core/config', ()=>({
9
+ envConfig: {
10
+ isProduction: jest.fn().mockReturnValue(false)
11
+ }
12
+ }));
13
+ describe('AuthConfigService', ()=>{
14
+ afterEach(()=>{
15
+ jest.clearAllMocks();
16
+ });
17
+ describe('with no injected options', ()=>{
18
+ it('defaults database mode to single and company feature to disabled', ()=>{
19
+ const service = new _authconfigservice.AuthConfigService();
20
+ expect(service.getDatabaseMode()).toBe('single');
21
+ expect(service.isMultiTenant()).toBe(false);
22
+ expect(service.isCompanyFeatureEnabled()).toBe(false);
23
+ expect(service.isEmailVerificationEnabled()).toBe(true);
24
+ expect(service.isPermissionModeFound()).toBe(false);
25
+ });
26
+ it('throws when reading the JWT secret without configuration', ()=>{
27
+ const service = new _authconfigservice.AuthConfigService();
28
+ expect(()=>service.getJwtSecret()).toThrow(_common.InternalServerErrorException);
29
+ });
30
+ it('falls back to the JWT secret for refresh token secret outside production', ()=>{
31
+ const service = new _authconfigservice.AuthConfigService({
32
+ global: false,
33
+ includeController: true,
34
+ config: {
35
+ jwtSecret: 'shared-secret'
36
+ }
37
+ });
38
+ expect(service.getRefreshTokenSecret()).toBe('shared-secret');
39
+ });
40
+ it('returns default JWT expiration and refresh token expiration', ()=>{
41
+ const service = new _authconfigservice.AuthConfigService();
42
+ expect(service.getJwtExpiration()).toBe('1h');
43
+ expect(service.getRefreshTokenExpiration()).toBe('7d');
44
+ expect(service.getRefreshTokenCookieName()).toBe('fsn_refresh_token');
45
+ });
46
+ });
47
+ describe('with injected options', ()=>{
48
+ function buildOptions(overrides = {}) {
49
+ return {
50
+ global: false,
51
+ includeController: true,
52
+ bootstrapAppConfig: {
53
+ databaseMode: 'multi-tenant',
54
+ enableCompanyFeature: true,
55
+ enableEmailVerification: false,
56
+ permissionMode: 'RBAC'
57
+ },
58
+ config: {
59
+ jwtSecret: 'jwt-secret',
60
+ jwtExpiration: '30m',
61
+ refreshTokenSecret: 'refresh-secret',
62
+ refreshTokenExpiration: '14d',
63
+ refreshTokenCookieName: 'custom_cookie'
64
+ },
65
+ ...overrides
66
+ };
67
+ }
68
+ it('reflects multi-tenant database mode', ()=>{
69
+ const service = new _authconfigservice.AuthConfigService(buildOptions());
70
+ expect(service.getDatabaseMode()).toBe('multi-tenant');
71
+ expect(service.isMultiTenant()).toBe(true);
72
+ });
73
+ it('reflects enabled company feature and email verification flags', ()=>{
74
+ const service = new _authconfigservice.AuthConfigService(buildOptions());
75
+ expect(service.isCompanyFeatureEnabled()).toBe(true);
76
+ expect(service.isEmailVerificationEnabled()).toBe(false);
77
+ expect(service.isPermissionModeFound()).toBe(true);
78
+ });
79
+ it('returns configured JWT and refresh token values', ()=>{
80
+ const service = new _authconfigservice.AuthConfigService(buildOptions());
81
+ expect(service.getJwtSecret()).toBe('jwt-secret');
82
+ expect(service.getJwtExpiration()).toBe('30m');
83
+ expect(service.getRefreshTokenSecret()).toBe('refresh-secret');
84
+ expect(service.getRefreshTokenExpiration()).toBe('14d');
85
+ expect(service.getRefreshTokenCookieName()).toBe('custom_cookie');
86
+ });
87
+ it('throws in production when refresh token secret is missing (security: prevents shared-secret fallback)', ()=>{
88
+ _config.envConfig.isProduction.mockReturnValue(true);
89
+ const service = new _authconfigservice.AuthConfigService(buildOptions({
90
+ config: {
91
+ jwtSecret: 'jwt-secret'
92
+ }
93
+ }));
94
+ expect(()=>service.getRefreshTokenSecret()).toThrow(_common.InternalServerErrorException);
95
+ });
96
+ });
97
+ });
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _nestjsshared = require("@flusys/nestjs-shared");
6
+ const _authdatasourceprovider = require("./auth-datasource.provider");
7
+ function buildOptions(overrides = {}) {
8
+ return {
9
+ global: false,
10
+ includeController: true,
11
+ bootstrapAppConfig: {
12
+ databaseMode: 'single',
13
+ enableCompanyFeature: false,
14
+ enableEmailVerification: true
15
+ },
16
+ ...overrides
17
+ };
18
+ }
19
+ describe('AuthDataSourceProvider', ()=>{
20
+ afterEach(()=>{
21
+ jest.restoreAllMocks();
22
+ });
23
+ describe('isCompanyFeatureEnabled', ()=>{
24
+ it('returns false by default when bootstrap config disables it', ()=>{
25
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions());
26
+ expect(provider.isCompanyFeatureEnabled()).toBe(false);
27
+ });
28
+ it('returns true when bootstrap config enables it', ()=>{
29
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
30
+ bootstrapAppConfig: {
31
+ databaseMode: 'single',
32
+ enableCompanyFeature: true
33
+ }
34
+ }));
35
+ expect(provider.isCompanyFeatureEnabled()).toBe(true);
36
+ });
37
+ it('prefers the tenant override over bootstrap config', ()=>{
38
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
39
+ bootstrapAppConfig: {
40
+ databaseMode: 'multi-tenant',
41
+ enableCompanyFeature: false
42
+ }
43
+ }));
44
+ expect(provider.isCompanyFeatureEnabled({
45
+ enableCompanyFeature: true
46
+ })).toBe(true);
47
+ });
48
+ it('defaults to false when no bootstrap config and no tenant override is present', ()=>{
49
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
50
+ bootstrapAppConfig: undefined
51
+ }));
52
+ expect(provider.isCompanyFeatureEnabled()).toBe(false);
53
+ });
54
+ });
55
+ describe('isEmailVerificationEnabled', ()=>{
56
+ it('returns true by default (feature defaults to enabled)', ()=>{
57
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
58
+ bootstrapAppConfig: undefined
59
+ }));
60
+ expect(provider.isEmailVerificationEnabled()).toBe(true);
61
+ });
62
+ it('returns false when bootstrap config disables it', ()=>{
63
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
64
+ bootstrapAppConfig: {
65
+ databaseMode: 'single',
66
+ enableCompanyFeature: false,
67
+ enableEmailVerification: false
68
+ }
69
+ }));
70
+ expect(provider.isEmailVerificationEnabled()).toBe(false);
71
+ });
72
+ it('prefers the tenant override over bootstrap config', ()=>{
73
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
74
+ bootstrapAppConfig: {
75
+ databaseMode: 'multi-tenant',
76
+ enableCompanyFeature: true,
77
+ enableEmailVerification: true
78
+ }
79
+ }));
80
+ expect(provider.isEmailVerificationEnabled({
81
+ enableEmailVerification: false
82
+ })).toBe(false);
83
+ });
84
+ });
85
+ describe('getAuthEntities', ()=>{
86
+ it('returns only base entities when company feature and email verification are disabled', async ()=>{
87
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
88
+ bootstrapAppConfig: {
89
+ databaseMode: 'single',
90
+ enableCompanyFeature: false,
91
+ enableEmailVerification: false
92
+ }
93
+ }));
94
+ const entities = await provider.getAuthEntities();
95
+ const names = entities.map((e)=>e.name);
96
+ expect(names).toEqual(expect.arrayContaining([
97
+ 'AppUser',
98
+ 'UserToken'
99
+ ]));
100
+ expect(names).not.toContain('Company');
101
+ expect(names).not.toContain('PendingRegistration');
102
+ });
103
+ it('includes company entities when company feature is enabled', async ()=>{
104
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
105
+ bootstrapAppConfig: {
106
+ databaseMode: 'single',
107
+ enableCompanyFeature: true,
108
+ enableEmailVerification: false
109
+ }
110
+ }));
111
+ const entities = await provider.getAuthEntities();
112
+ const names = entities.map((e)=>e.name);
113
+ expect(names).toEqual(expect.arrayContaining([
114
+ 'AppUser',
115
+ 'UserToken',
116
+ 'Company',
117
+ 'CompanyBranch',
118
+ 'UserCompanyPermission'
119
+ ]));
120
+ });
121
+ it('includes pending registration entity when email verification is enabled', async ()=>{
122
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
123
+ bootstrapAppConfig: {
124
+ databaseMode: 'single',
125
+ enableCompanyFeature: false,
126
+ enableEmailVerification: true
127
+ }
128
+ }));
129
+ const entities = await provider.getAuthEntities();
130
+ const names = entities.map((e)=>e.name);
131
+ expect(names).toContain('PendingRegistration');
132
+ });
133
+ });
134
+ describe('createDataSourceFromConfig', ()=>{
135
+ it('forwards the config and resolved auth entities to the parent implementation', async ()=>{
136
+ const fakeDataSource = {
137
+ isInitialized: true
138
+ };
139
+ const parentSpy = jest.spyOn(_nestjsshared.MultiTenantDataSourceService.prototype, 'createDataSourceFromConfig').mockResolvedValue(fakeDataSource);
140
+ const provider = new _authdatasourceprovider.AuthDataSourceProvider(buildOptions({
141
+ bootstrapAppConfig: {
142
+ databaseMode: 'single',
143
+ enableCompanyFeature: true,
144
+ enableEmailVerification: true
145
+ }
146
+ }));
147
+ const config = {
148
+ type: 'postgres',
149
+ host: 'localhost'
150
+ };
151
+ const result = await provider.createDataSourceFromConfig(config);
152
+ expect(result).toBe(fakeDataSource);
153
+ expect(parentSpy).toHaveBeenCalledWith(config, expect.any(Array));
154
+ const forwardedEntityNames = parentSpy.mock.calls[0][1].map((e)=>e.name);
155
+ expect(forwardedEntityNames).toEqual(expect.arrayContaining([
156
+ 'AppUser',
157
+ 'Company'
158
+ ]));
159
+ });
160
+ });
161
+ });