| 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" }], |
| gio | e10ba16 | 2025-07-31 19:52:29 +0400 | [diff] [blame^] | 20 | dev: { enabled: false }, |
| gio | 9b7421a | 2025-06-18 12:31:13 +0000 | [diff] [blame] | 21 | }, |
| 22 | ], |
| 23 | }; |
| 24 | |
| 25 | const networks: Network[] = [ |
| 26 | { |
| 27 | name: "Public", |
| 28 | domain: "v1.dodo.cloud", |
| 29 | hasAuth: true, |
| 30 | }, |
| 31 | ]; |
| 32 | |
| 33 | const repos: GithubRepository[] = [ |
| 34 | { |
| 35 | id: 123, |
| 36 | name: "repo", |
| 37 | full_name: "user/repo", |
| 38 | html_url: "https://github.com/user/repo", |
| 39 | ssh_url: "git@github.com:user/repo.git", |
| 40 | }, |
| 41 | ]; |
| 42 | |
| 43 | const graph = configToGraph(config, networks, repos); |
| 44 | |
| 45 | // Expect one service node, one repo node, and one network node |
| 46 | expect(graph.nodes).toHaveLength(3); |
| 47 | |
| 48 | const serviceNode = graph.nodes.find((n) => n.type === "app"); |
| 49 | expect(serviceNode).toBeDefined(); |
| 50 | expect(serviceNode?.data.label).toBe("my-app"); |
| 51 | |
| 52 | const repoNode = graph.nodes.find((n) => n.type === "github"); |
| 53 | expect(repoNode).toBeDefined(); |
| 54 | expect(repoNode?.data.repository?.sshURL).toBe("git@github.com:user/repo.git"); |
| 55 | |
| 56 | const networkNode = graph.nodes.find((n) => n.type === "network"); |
| 57 | expect(networkNode).toBeDefined(); |
| 58 | expect(networkNode?.data.domain).toBe("v1.dodo.cloud"); |
| 59 | |
| 60 | // Expect one edge from repo to service |
| 61 | expect(graph.edges).toHaveLength(1); |
| 62 | const repoEdge = graph.edges.find((e) => e.source === repoNode?.id && e.target === serviceNode?.id); |
| 63 | expect(repoEdge).toBeDefined(); |
| 64 | console.log(JSON.stringify(graph, null, 2)); |
| 65 | }); |
| 66 | }); |