| gio | 9b7421a | 2025-06-18 12:31:13 +0000 | [diff] [blame] | 1 | import { configToGraph } from "./config.js"; |
| 2 | import { Config } from "./types.js"; |
| 3 | import { Network } from "./graph.js"; |
| 4 | import { GithubRepository } from "./github.js"; |
| 5 | |
| 6 | describe("configToGraph", () => { |
| 7 | it("should create a simple graph from a basic service configuration", () => { |
| 8 | const config: Config = { |
| 9 | service: [ |
| 10 | { |
| 11 | nodeId: "service-1", |
| 12 | name: "my-app", |
| 13 | type: "nodejs:24.0.2", |
| 14 | source: { |
| 15 | repository: "git@github.com:user/repo.git", |
| 16 | branch: "main", |
| 17 | rootDir: "/", |
| 18 | }, |
| 19 | ports: [{ name: "http", value: 3000, protocol: "TCP" }], |
| 20 | }, |
| 21 | ], |
| 22 | }; |
| 23 | |
| 24 | const networks: Network[] = [ |
| 25 | { |
| 26 | name: "Public", |
| 27 | domain: "v1.dodo.cloud", |
| 28 | hasAuth: true, |
| 29 | }, |
| 30 | ]; |
| 31 | |
| 32 | const repos: GithubRepository[] = [ |
| 33 | { |
| 34 | id: 123, |
| 35 | name: "repo", |
| 36 | full_name: "user/repo", |
| 37 | html_url: "https://github.com/user/repo", |
| 38 | ssh_url: "git@github.com:user/repo.git", |
| 39 | }, |
| 40 | ]; |
| 41 | |
| 42 | const graph = configToGraph(config, networks, repos); |
| 43 | |
| 44 | // Expect one service node, one repo node, and one network node |
| 45 | expect(graph.nodes).toHaveLength(3); |
| 46 | |
| 47 | const serviceNode = graph.nodes.find((n) => n.type === "app"); |
| 48 | expect(serviceNode).toBeDefined(); |
| 49 | expect(serviceNode?.data.label).toBe("my-app"); |
| 50 | |
| 51 | const repoNode = graph.nodes.find((n) => n.type === "github"); |
| 52 | expect(repoNode).toBeDefined(); |
| 53 | expect(repoNode?.data.repository?.sshURL).toBe("git@github.com:user/repo.git"); |
| 54 | |
| 55 | const networkNode = graph.nodes.find((n) => n.type === "network"); |
| 56 | expect(networkNode).toBeDefined(); |
| 57 | expect(networkNode?.data.domain).toBe("v1.dodo.cloud"); |
| 58 | |
| 59 | // Expect one edge from repo to service |
| 60 | expect(graph.edges).toHaveLength(1); |
| 61 | const repoEdge = graph.edges.find((e) => e.source === repoNode?.id && e.target === serviceNode?.id); |
| 62 | expect(repoEdge).toBeDefined(); |
| 63 | console.log(JSON.stringify(graph, null, 2)); |
| 64 | }); |
| 65 | }); |