Skip to content

Commit 8eae74f

Browse files
committed
fix tests
1 parent 685bce8 commit 8eae74f

File tree

1 file changed

+179
-179
lines changed

1 file changed

+179
-179
lines changed
Lines changed: 179 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,179 @@
1-
// import { kcpRootOrgsPath } from '../models/constants';
2-
// import { PortalLuigiNode } from '../models/luigi-node';
3-
// import { CrdGatewayKcpPatchResolver } from './crd-gateway-kcp-patch-resolver.service';
4-
// import { TestBed } from '@angular/core/testing';
5-
// import { EnvConfigService } from '@openmfp/portal-ui-lib';
6-
// import { GatewayService } from '@platform-mesh/portal-ui-lib/services/resource';
7-
//
8-
// describe('CrdGatewayKcpPatchResolver', () => {
9-
// let resolver: CrdGatewayKcpPatchResolver;
10-
// let envConfigServiceMock: jest.Mocked<EnvConfigService>;
11-
// let gatewayServiceMock: { updateCrdGatewayUrlWithEntityPath: jest.Mock };
12-
//
13-
// beforeEach(() => {
14-
// gatewayServiceMock = { updateCrdGatewayUrlWithEntityPath: jest.fn() };
15-
// envConfigServiceMock = {
16-
// getEnvConfig: jest.fn().mockResolvedValue({ idpName: 'org1' }),
17-
// } as any;
18-
//
19-
// TestBed.configureTestingModule({
20-
// providers: [
21-
// CrdGatewayKcpPatchResolver,
22-
// { provide: EnvConfigService, useValue: envConfigServiceMock },
23-
// { provide: GatewayService, useValue: gatewayServiceMock },
24-
// ],
25-
// });
26-
// resolver = TestBed.inject(CrdGatewayKcpPatchResolver);
27-
// });
28-
//
29-
// it('should build kcpPath from entity metadata and organization, skipping non-Account types', async () => {
30-
// const node: PortalLuigiNode = {
31-
// context: {
32-
// entity: { metadata: { name: 'acc3' }, __typename: 'Account' },
33-
// },
34-
// parent: {
35-
// context: {
36-
// entity: { metadata: { name: 'proj1' }, __typename: 'Project' },
37-
// },
38-
// parent: {
39-
// context: {
40-
// entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
41-
// },
42-
// parent: {
43-
// context: {
44-
// entity: { metadata: { name: 'team1' }, __typename: 'Team' },
45-
// },
46-
// parent: {
47-
// context: {
48-
// entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
49-
// },
50-
// parent: undefined,
51-
// },
52-
// },
53-
// },
54-
// },
55-
// } as any;
56-
//
57-
// await resolver.resolveCrdGatewayKcpPath(node);
58-
//
59-
// expect(
60-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
61-
// ).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:acc3`);
62-
// });
63-
//
64-
// it('should use kcpPath from node context if provided', async () => {
65-
// const node: PortalLuigiNode = {
66-
// context: { kcpPath: 'customPath' },
67-
// parent: undefined,
68-
// } as any;
69-
//
70-
// await resolver.resolveCrdGatewayKcpPath(node);
71-
//
72-
// expect(
73-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
74-
// ).toHaveBeenCalledWith('customPath');
75-
// });
76-
//
77-
// it('should handle node without entity metadata', async () => {
78-
// const node: PortalLuigiNode = { context: {}, parent: undefined } as any;
79-
//
80-
// await resolver.resolveCrdGatewayKcpPath(node);
81-
//
82-
// expect(
83-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
84-
// ).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1`);
85-
// });
86-
//
87-
// describe('resolveCrdGatewayKcpPathForNextAccountEntity', () => {
88-
// it('should return early if kind is not Account', async () => {
89-
// const nextNode: PortalLuigiNode = {
90-
// context: {},
91-
// parent: undefined,
92-
// } as any;
93-
//
94-
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
95-
// 'leafAcc',
96-
// 'Project',
97-
// nextNode,
98-
// );
99-
//
100-
// expect(
101-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
102-
// ).not.toHaveBeenCalled();
103-
// expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
104-
// });
105-
//
106-
// it('should return early if entityId is empty', async () => {
107-
// const nextNode: PortalLuigiNode = {
108-
// context: {},
109-
// parent: undefined,
110-
// } as any;
111-
//
112-
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
113-
// '',
114-
// 'Account',
115-
// nextNode,
116-
// );
117-
//
118-
// expect(
119-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
120-
// ).not.toHaveBeenCalled();
121-
// expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
122-
// });
123-
//
124-
// it('should aggregate parent Account entities and append entityId', async () => {
125-
// const nextNode: PortalLuigiNode = {
126-
// context: {},
127-
// parent: {
128-
// context: {
129-
// entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
130-
// },
131-
// parent: {
132-
// context: {
133-
// entity: { metadata: { name: 'team1' }, __typename: 'Team' },
134-
// },
135-
// parent: {
136-
// context: {
137-
// entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
138-
// },
139-
// parent: undefined,
140-
// },
141-
// },
142-
// },
143-
// } as any;
144-
//
145-
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
146-
// 'leafAcc',
147-
// 'Account',
148-
// nextNode,
149-
// );
150-
//
151-
// expect(envConfigServiceMock.getEnvConfig).toHaveBeenCalled();
152-
// expect(
153-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
154-
// ).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:leafAcc`);
155-
// });
156-
//
157-
// it('should use kcpPath from node context if provided (override)', async () => {
158-
// const nextNode: PortalLuigiNode = {
159-
// context: { kcpPath: 'overridePath' },
160-
// parent: {
161-
// context: {
162-
// entity: { metadata: { name: 'accParent' }, __typename: 'Account' },
163-
// },
164-
// parent: undefined,
165-
// },
166-
// } as any;
167-
//
168-
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
169-
// 'leafAcc',
170-
// 'Account',
171-
// nextNode,
172-
// );
173-
//
174-
// expect(
175-
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
176-
// ).toHaveBeenCalledWith('overridePath');
177-
// });
178-
// });
179-
// });
1+
import { kcpRootOrgsPath } from '../models/constants';
2+
import { PortalLuigiNode } from '../models/luigi-node';
3+
import { CrdGatewayKcpPatchResolver } from './crd-gateway-kcp-patch-resolver.service';
4+
import { TestBed } from '@angular/core/testing';
5+
import { EnvConfigService } from '@openmfp/portal-ui-lib';
6+
import { GatewayService } from '@platform-mesh/portal-ui-lib/services/resource';
7+
8+
describe('CrdGatewayKcpPatchResolver', () => {
9+
let resolver: CrdGatewayKcpPatchResolver;
10+
let envConfigServiceMock: jest.Mocked<EnvConfigService>;
11+
let gatewayServiceMock: { updateCrdGatewayUrlWithEntityPath: jest.Mock };
12+
13+
beforeEach(() => {
14+
gatewayServiceMock = { updateCrdGatewayUrlWithEntityPath: jest.fn() };
15+
envConfigServiceMock = {
16+
getEnvConfig: jest.fn().mockResolvedValue({ idpName: 'org1' }),
17+
} as any;
18+
19+
TestBed.configureTestingModule({
20+
providers: [
21+
CrdGatewayKcpPatchResolver,
22+
{ provide: EnvConfigService, useValue: envConfigServiceMock },
23+
{ provide: GatewayService, useValue: gatewayServiceMock },
24+
],
25+
});
26+
resolver = TestBed.inject(CrdGatewayKcpPatchResolver);
27+
});
28+
29+
it('should build kcpPath from entity metadata and organization, skipping non-Account types', async () => {
30+
const node: PortalLuigiNode = {
31+
context: {
32+
entity: { metadata: { name: 'acc3' }, __typename: 'Account' },
33+
},
34+
parent: {
35+
context: {
36+
entity: { metadata: { name: 'proj1' }, __typename: 'Project' },
37+
},
38+
parent: {
39+
context: {
40+
entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
41+
},
42+
parent: {
43+
context: {
44+
entity: { metadata: { name: 'team1' }, __typename: 'Team' },
45+
},
46+
parent: {
47+
context: {
48+
entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
49+
},
50+
parent: undefined,
51+
},
52+
},
53+
},
54+
},
55+
} as any;
56+
57+
await resolver.resolveCrdGatewayKcpPath(node);
58+
59+
expect(
60+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
61+
).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:acc3`);
62+
});
63+
64+
it('should use kcpPath from node context if provided', async () => {
65+
const node: PortalLuigiNode = {
66+
context: { kcpPath: 'customPath' },
67+
parent: undefined,
68+
} as any;
69+
70+
await resolver.resolveCrdGatewayKcpPath(node);
71+
72+
expect(
73+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
74+
).toHaveBeenCalledWith('customPath');
75+
});
76+
77+
it('should handle node without entity metadata', async () => {
78+
const node: PortalLuigiNode = { context: {}, parent: undefined } as any;
79+
80+
await resolver.resolveCrdGatewayKcpPath(node);
81+
82+
expect(
83+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
84+
).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1`);
85+
});
86+
87+
describe('resolveCrdGatewayKcpPathForNextAccountEntity', () => {
88+
it('should return early if kind is not Account', async () => {
89+
const nextNode: PortalLuigiNode = {
90+
context: {},
91+
parent: undefined,
92+
} as any;
93+
94+
await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
95+
'leafAcc',
96+
'Project',
97+
nextNode,
98+
);
99+
100+
expect(
101+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
102+
).not.toHaveBeenCalled();
103+
expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
104+
});
105+
106+
it('should return early if entityId is empty', async () => {
107+
const nextNode: PortalLuigiNode = {
108+
context: {},
109+
parent: undefined,
110+
} as any;
111+
112+
await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
113+
'',
114+
'Account',
115+
nextNode,
116+
);
117+
118+
expect(
119+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
120+
).not.toHaveBeenCalled();
121+
expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
122+
});
123+
124+
it('should aggregate parent Account entities and append entityId', async () => {
125+
const nextNode: PortalLuigiNode = {
126+
context: {},
127+
parent: {
128+
context: {
129+
entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
130+
},
131+
parent: {
132+
context: {
133+
entity: { metadata: { name: 'team1' }, __typename: 'Team' },
134+
},
135+
parent: {
136+
context: {
137+
entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
138+
},
139+
parent: undefined,
140+
},
141+
},
142+
},
143+
} as any;
144+
145+
await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
146+
'leafAcc',
147+
'Account',
148+
nextNode,
149+
);
150+
151+
expect(envConfigServiceMock.getEnvConfig).toHaveBeenCalled();
152+
expect(
153+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
154+
).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:leafAcc`);
155+
});
156+
157+
it('should use kcpPath from node context if provided (override)', async () => {
158+
const nextNode: PortalLuigiNode = {
159+
context: { kcpPath: 'overridePath' },
160+
parent: {
161+
context: {
162+
entity: { metadata: { name: 'accParent' }, __typename: 'Account' },
163+
},
164+
parent: undefined,
165+
},
166+
} as any;
167+
168+
await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
169+
'leafAcc',
170+
'Account',
171+
nextNode,
172+
);
173+
174+
expect(
175+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
176+
).toHaveBeenCalledWith('overridePath');
177+
});
178+
});
179+
});

0 commit comments

Comments
 (0)