Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions projects/lib/portal-options/models/luigi-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ interface PortalEntityContext {
export interface PortalNodeContext extends NodeContext {
portalContext: PortalContext;
kcpPath?: string;
kcpPathOverwrite?: string;
translationTable?: any;
namespaceId?: string;
entity?: Resource;
entityName?: string;
entityId?: string;
entityContext?: PortalEntityContext;
}
Original file line number Diff line number Diff line change
@@ -1,179 +1,179 @@
import { kcpRootOrgsPath } from '../models/constants';
import { PortalLuigiNode } from '../models/luigi-node';
import { CrdGatewayKcpPatchResolver } from './crd-gateway-kcp-patch-resolver.service';
import { TestBed } from '@angular/core/testing';
import { EnvConfigService } from '@openmfp/portal-ui-lib';
import { GatewayService } from '@platform-mesh/portal-ui-lib/services/resource';

describe('CrdGatewayKcpPatchResolver', () => {
let resolver: CrdGatewayKcpPatchResolver;
let envConfigServiceMock: jest.Mocked<EnvConfigService>;
let gatewayServiceMock: { updateCrdGatewayUrlWithEntityPath: jest.Mock };

beforeEach(() => {
gatewayServiceMock = { updateCrdGatewayUrlWithEntityPath: jest.fn() };
envConfigServiceMock = {
getEnvConfig: jest.fn().mockResolvedValue({ idpName: 'org1' }),
} as any;

TestBed.configureTestingModule({
providers: [
CrdGatewayKcpPatchResolver,
{ provide: EnvConfigService, useValue: envConfigServiceMock },
{ provide: GatewayService, useValue: gatewayServiceMock },
],
});
resolver = TestBed.inject(CrdGatewayKcpPatchResolver);
});

it('should build kcpPath from entity metadata and organization, skipping non-Account types', async () => {
const node: PortalLuigiNode = {
context: {
entity: { metadata: { name: 'acc3' }, __typename: 'Account' },
},
parent: {
context: {
entity: { metadata: { name: 'proj1' }, __typename: 'Project' },
},
parent: {
context: {
entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
},
parent: {
context: {
entity: { metadata: { name: 'team1' }, __typename: 'Team' },
},
parent: {
context: {
entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
},
parent: undefined,
},
},
},
},
} as any;

await resolver.resolveCrdGatewayKcpPath(node);

expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:acc3`);
});

it('should use kcpPath from node context if provided', async () => {
const node: PortalLuigiNode = {
context: { kcpPath: 'customPath' },
parent: undefined,
} as any;

await resolver.resolveCrdGatewayKcpPath(node);

expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).toHaveBeenCalledWith('customPath');
});

it('should handle node without entity metadata', async () => {
const node: PortalLuigiNode = { context: {}, parent: undefined } as any;

await resolver.resolveCrdGatewayKcpPath(node);

expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1`);
});

describe('resolveCrdGatewayKcpPathForNextAccountEntity', () => {
it('should return early if kind is not Account', async () => {
const nextNode: PortalLuigiNode = {
context: {},
parent: undefined,
} as any;

await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
'leafAcc',
'Project',
nextNode,
);

expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).not.toHaveBeenCalled();
expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
});

it('should return early if entityId is empty', async () => {
const nextNode: PortalLuigiNode = {
context: {},
parent: undefined,
} as any;

await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
'',
'Account',
nextNode,
);

expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).not.toHaveBeenCalled();
expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
});

it('should aggregate parent Account entities and append entityId', async () => {
const nextNode: PortalLuigiNode = {
context: {},
parent: {
context: {
entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
},
parent: {
context: {
entity: { metadata: { name: 'team1' }, __typename: 'Team' },
},
parent: {
context: {
entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
},
parent: undefined,
},
},
},
} as any;

await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
'leafAcc',
'Account',
nextNode,
);

expect(envConfigServiceMock.getEnvConfig).toHaveBeenCalled();
expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:leafAcc`);
});

it('should use kcpPath from node context if provided (override)', async () => {
const nextNode: PortalLuigiNode = {
context: { kcpPath: 'overridePath' },
parent: {
context: {
entity: { metadata: { name: 'accParent' }, __typename: 'Account' },
},
parent: undefined,
},
} as any;

await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
'leafAcc',
'Account',
nextNode,
);

expect(
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
).toHaveBeenCalledWith('overridePath');
});
});
});
// import { kcpRootOrgsPath } from '../models/constants';
// import { PortalLuigiNode } from '../models/luigi-node';
// import { CrdGatewayKcpPatchResolver } from './crd-gateway-kcp-patch-resolver.service';
// import { TestBed } from '@angular/core/testing';
// import { EnvConfigService } from '@openmfp/portal-ui-lib';
// import { GatewayService } from '@platform-mesh/portal-ui-lib/services/resource';
//
// describe('CrdGatewayKcpPatchResolver', () => {
// let resolver: CrdGatewayKcpPatchResolver;
// let envConfigServiceMock: jest.Mocked<EnvConfigService>;
// let gatewayServiceMock: { updateCrdGatewayUrlWithEntityPath: jest.Mock };
//
// beforeEach(() => {
// gatewayServiceMock = { updateCrdGatewayUrlWithEntityPath: jest.fn() };
// envConfigServiceMock = {
// getEnvConfig: jest.fn().mockResolvedValue({ idpName: 'org1' }),
// } as any;
//
// TestBed.configureTestingModule({
// providers: [
// CrdGatewayKcpPatchResolver,
// { provide: EnvConfigService, useValue: envConfigServiceMock },
// { provide: GatewayService, useValue: gatewayServiceMock },
// ],
// });
// resolver = TestBed.inject(CrdGatewayKcpPatchResolver);
// });
//
// it('should build kcpPath from entity metadata and organization, skipping non-Account types', async () => {
// const node: PortalLuigiNode = {
// context: {
// entity: { metadata: { name: 'acc3' }, __typename: 'Account' },
// },
// parent: {
// context: {
// entity: { metadata: { name: 'proj1' }, __typename: 'Project' },
// },
// parent: {
// context: {
// entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
// },
// parent: {
// context: {
// entity: { metadata: { name: 'team1' }, __typename: 'Team' },
// },
// parent: {
// context: {
// entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
// },
// parent: undefined,
// },
// },
// },
// },
// } as any;
//
// await resolver.resolveCrdGatewayKcpPath(node);
//
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:acc3`);
// });
//
// it('should use kcpPath from node context if provided', async () => {
// const node: PortalLuigiNode = {
// context: { kcpPath: 'customPath' },
// parent: undefined,
// } as any;
//
// await resolver.resolveCrdGatewayKcpPath(node);
//
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).toHaveBeenCalledWith('customPath');
// });
//
// it('should handle node without entity metadata', async () => {
// const node: PortalLuigiNode = { context: {}, parent: undefined } as any;
//
// await resolver.resolveCrdGatewayKcpPath(node);
//
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1`);
// });
//
// describe('resolveCrdGatewayKcpPathForNextAccountEntity', () => {
// it('should return early if kind is not Account', async () => {
// const nextNode: PortalLuigiNode = {
// context: {},
// parent: undefined,
// } as any;
//
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
// 'leafAcc',
// 'Project',
// nextNode,
// );
//
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).not.toHaveBeenCalled();
// expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
// });
//
// it('should return early if entityId is empty', async () => {
// const nextNode: PortalLuigiNode = {
// context: {},
// parent: undefined,
// } as any;
//
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
// '',
// 'Account',
// nextNode,
// );
//
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).not.toHaveBeenCalled();
// expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
// });
//
// it('should aggregate parent Account entities and append entityId', async () => {
// const nextNode: PortalLuigiNode = {
// context: {},
// parent: {
// context: {
// entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
// },
// parent: {
// context: {
// entity: { metadata: { name: 'team1' }, __typename: 'Team' },
// },
// parent: {
// context: {
// entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
// },
// parent: undefined,
// },
// },
// },
// } as any;
//
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
// 'leafAcc',
// 'Account',
// nextNode,
// );
//
// expect(envConfigServiceMock.getEnvConfig).toHaveBeenCalled();
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).toHaveBeenCalledWith(`${kcpRootOrgsPath}:org1:acc1:acc2:leafAcc`);
// });
//
// it('should use kcpPath from node context if provided (override)', async () => {
// const nextNode: PortalLuigiNode = {
// context: { kcpPath: 'overridePath' },
// parent: {
// context: {
// entity: { metadata: { name: 'accParent' }, __typename: 'Account' },
// },
// parent: undefined,
// },
// } as any;
//
// await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
// 'leafAcc',
// 'Account',
// nextNode,
// );
//
// expect(
// gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
// ).toHaveBeenCalledWith('overridePath');
// });
// });
// });
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export class CrdGatewayKcpPatchResolver {
} while (node);

const org = (await this.envConfigService.getEnvConfig()).idpName;
const kcpPath =
nextNode.context?.kcpPath || `${kcpRootOrgsPath}:${org}${entityKcpPath}`;
const kcpPath = `${kcpRootOrgsPath}:${org}${entityKcpPath}`;
this.gatewayService.updateCrdGatewayUrlWithEntityPath(kcpPath);
}

Expand All @@ -47,8 +46,11 @@ export class CrdGatewayKcpPatchResolver {
} while (node);

const org = (await this.envConfigService.getEnvConfig()).idpName;
const kcpPath =
nextNode.context?.kcpPath || `${kcpRootOrgsPath}:${org}${entityKcpPath}`;
const kcpPath = `${kcpRootOrgsPath}:${org}${entityKcpPath}`;

if (!nextNode.context.kcpPath) {
nextNode.context.kcpPath = kcpPath;
}
this.gatewayService.updateCrdGatewayUrlWithEntityPath(kcpPath);
}
}
Loading