|
| 1 | +import { AssetRegistryDescriptor } from "../../../src/commands/asset-registry/asset-registry.interfaces"; |
| 2 | +import { mockAxiosGet } from "../../utls/http-requests-mock"; |
| 3 | +import { AssetRegistryService } from "../../../src/commands/asset-registry/asset-registry.service"; |
| 4 | +import { testContext } from "../../utls/test-context"; |
| 5 | +import { loggingTestTransport, mockWriteFileSync } from "../../jest.setup"; |
| 6 | +import { FileService } from "../../../src/core/utils/file-service"; |
| 7 | +import * as path from "path"; |
| 8 | + |
| 9 | +describe("Asset registry get", () => { |
| 10 | + const boardDescriptor: AssetRegistryDescriptor = { |
| 11 | + assetType: "BOARD_V2", |
| 12 | + displayName: "View", |
| 13 | + description: null, |
| 14 | + group: "DASHBOARDS", |
| 15 | + assetSchema: { version: "2.1.0" }, |
| 16 | + service: { basePath: "/blueprint/api" }, |
| 17 | + endpoints: { |
| 18 | + schema: "/schema/board_v2", |
| 19 | + validate: "/validate/board_v2", |
| 20 | + methodology: "/methodology/board_v2", |
| 21 | + examples: "/examples/board_v2", |
| 22 | + }, |
| 23 | + contributions: { pigEntityTypes: [], dataPipelineEntityTypes: [], actionTypes: [] }, |
| 24 | + }; |
| 25 | + |
| 26 | + it("Should get a specific asset type", async () => { |
| 27 | + mockAxiosGet("https://myTeam.celonis.cloud/pacman/api/core/asset-registry/types/BOARD_V2", boardDescriptor); |
| 28 | + |
| 29 | + await new AssetRegistryService(testContext).getType("BOARD_V2", false); |
| 30 | + |
| 31 | + const messages = loggingTestTransport.logMessages.map((m) => m.message); |
| 32 | + expect(messages).toEqual( |
| 33 | + expect.arrayContaining([ |
| 34 | + expect.stringContaining("BOARD_V2"), |
| 35 | + expect.stringContaining("View"), |
| 36 | + expect.stringContaining("DASHBOARDS"), |
| 37 | + expect.stringContaining("/blueprint/api"), |
| 38 | + expect.stringContaining("/schema/board_v2"), |
| 39 | + expect.stringContaining("/validate/board_v2"), |
| 40 | + ]) |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it("Should get a specific asset type as JSON", async () => { |
| 45 | + mockAxiosGet("https://myTeam.celonis.cloud/pacman/api/core/asset-registry/types/BOARD_V2", boardDescriptor); |
| 46 | + |
| 47 | + await new AssetRegistryService(testContext).getType("BOARD_V2", true); |
| 48 | + |
| 49 | + const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1]; |
| 50 | + expect(mockWriteFileSync).toHaveBeenCalledWith( |
| 51 | + path.resolve(process.cwd(), expectedFileName), |
| 52 | + expect.any(String), |
| 53 | + { encoding: "utf-8" } |
| 54 | + ); |
| 55 | + |
| 56 | + const written = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as AssetRegistryDescriptor; |
| 57 | + expect(written.assetType).toBe("BOARD_V2"); |
| 58 | + expect(written.displayName).toBe("View"); |
| 59 | + expect(written.service.basePath).toBe("/blueprint/api"); |
| 60 | + }); |
| 61 | + |
| 62 | + it("Should include optional endpoints when present", async () => { |
| 63 | + mockAxiosGet("https://myTeam.celonis.cloud/pacman/api/core/asset-registry/types/BOARD_V2", boardDescriptor); |
| 64 | + |
| 65 | + await new AssetRegistryService(testContext).getType("BOARD_V2", false); |
| 66 | + |
| 67 | + const messages = loggingTestTransport.logMessages.map((m) => m.message); |
| 68 | + expect(messages).toEqual( |
| 69 | + expect.arrayContaining([ |
| 70 | + expect.stringContaining("/methodology/board_v2"), |
| 71 | + expect.stringContaining("/examples/board_v2"), |
| 72 | + ]) |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + it("Should omit optional endpoints when absent", async () => { |
| 77 | + const descriptorWithoutOptionals: AssetRegistryDescriptor = { |
| 78 | + ...boardDescriptor, |
| 79 | + endpoints: { |
| 80 | + schema: "/schema/board_v2", |
| 81 | + validate: "/validate/board_v2", |
| 82 | + }, |
| 83 | + }; |
| 84 | + mockAxiosGet("https://myTeam.celonis.cloud/pacman/api/core/asset-registry/types/BOARD_V2", descriptorWithoutOptionals); |
| 85 | + |
| 86 | + await new AssetRegistryService(testContext).getType("BOARD_V2", false); |
| 87 | + |
| 88 | + const messages = loggingTestTransport.logMessages.map((m) => m.message).join("\n"); |
| 89 | + expect(messages).not.toContain("methodology"); |
| 90 | + expect(messages).not.toContain("examples"); |
| 91 | + }); |
| 92 | +}); |
0 commit comments