Skip to content

Commit d4ca31e

Browse files
committed
feat: add test & rename folder & rename route
1 parent d44aed8 commit d4ca31e

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

projects/lib/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
coverageThreshold: {
77
global: {
88
branches: 67,
9-
functions: 90,
9+
functions: 95,
1010
lines: 91,
1111
statements: -16,
1212
},
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { ApplicationInitStatus } from '@angular/core';
3+
import { Router } from '@angular/router';
4+
import { EnvConfigService } from '@openmfp/portal-ui-lib';
5+
import { organizationInitializer } from './organization-initializer';
6+
7+
describe('organizationInitializer', () => {
8+
let envMock: jest.Mocked<EnvConfigService>;
9+
let routerMock: jest.Mocked<Router>;
10+
11+
beforeEach(() => {
12+
envMock = {
13+
getEnvConfig: jest.fn(),
14+
} as unknown as jest.Mocked<EnvConfigService>;
15+
16+
routerMock = {
17+
navigate: jest.fn(),
18+
} as unknown as jest.Mocked<Router>;
19+
20+
TestBed.configureTestingModule({
21+
providers: [
22+
organizationInitializer(),
23+
{ provide: EnvConfigService, useValue: envMock },
24+
{ provide: Router, useValue: routerMock },
25+
],
26+
});
27+
});
28+
29+
it('should call getEnvConfig and not navigate on success', async () => {
30+
envMock.getEnvConfig.mockResolvedValueOnce(undefined as any);
31+
32+
await TestBed.inject(ApplicationInitStatus).donePromise;
33+
34+
expect(envMock.getEnvConfig).toHaveBeenCalledTimes(1);
35+
expect(routerMock.navigate).not.toHaveBeenCalled();
36+
});
37+
38+
it('should navigate to "welcome" when getEnvConfig throws', async () => {
39+
envMock.getEnvConfig.mockRejectedValueOnce(new Error('fail'));
40+
41+
await TestBed.inject(ApplicationInitStatus).donePromise;
42+
43+
expect(envMock.getEnvConfig).toHaveBeenCalledTimes(1);
44+
expect(routerMock.navigate).toHaveBeenCalledWith(['welcome']);
45+
});
46+
});

projects/lib/initializers/initializers/organization-initializer.ts renamed to projects/lib/organization/initializers/organization-initializer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ export const organizationInitializer = () => {
66
return provideAppInitializer(async () => {
77
const envService = inject(EnvConfigService)
88
const router = inject(Router)
9-
console.log('Running organization initializer');
109

1110
try {
1211
await envService.getEnvConfig()
1312
} catch {
14-
router.navigate(['new-organization']);
13+
router.navigate(['welcome']);
1514
}
1615
});
1716
};
File renamed without changes.

0 commit comments

Comments
 (0)