package atlas_test import ( "testing" "git.d-ma.be/mathias/cad-atlas/internal/atlas" ) // A Gitea /user/repos response, trimmed to the fields RepoNodes reads. const repoList = `[ {"name":"cad-atlas","full_name":"mathias/cad-atlas","description":"Visualising the CAD workflow","html_url":"https://git.d-ma.be/mathias/cad-atlas","archived":false,"language":"Go"}, {"name":"dispatch","full_name":"mathias/dispatch","description":"","html_url":"https://git.d-ma.be/mathias/dispatch","archived":false,"language":""}, {"name":"old-thing","full_name":"mathias/old-thing","description":"retired","html_url":"https://git.d-ma.be/mathias/old-thing","archived":true,"language":"Go"} ]` func TestRepoNodes_OneNodePerRepoWithDescriptionAndURL(t *testing.T) { nodes, err := atlas.RepoNodes([]byte(repoList)) if err != nil { t.Fatalf("RepoNodes: %v", err) } if len(nodes) != 2 { t.Fatalf("want 2 nodes (archived excluded), got %d", len(nodes)) } if nodes[0].Title != "cad-atlas" { t.Fatalf("title = %q, want %q", nodes[0].Title, "cad-atlas") } if nodes[0].URL != "https://git.d-ma.be/mathias/cad-atlas" { t.Fatalf("url = %q", nodes[0].URL) } if nodes[0].Desc != "Visualising the CAD workflow" { t.Fatalf("desc = %q", nodes[0].Desc) } } // Mirrors IssueNodes' tagging so the two live slices read identically on stage. func TestRepoNodes_TagsCarryLiveMarkerAndLanguage(t *testing.T) { nodes, err := atlas.RepoNodes([]byte(repoList)) if err != nil { t.Fatalf("RepoNodes: %v", err) } if len(nodes) < 2 { t.Fatalf("want at least 2 nodes, got %d", len(nodes)) } if len(nodes[0].Tags) != 2 || nodes[0].Tags[0] != "live · Gitea" || nodes[0].Tags[1] != "Go" { t.Fatalf("tags = %v, want [live · Gitea Go]", nodes[0].Tags) } // A repo with no language must not emit an empty tag pill. if len(nodes[1].Tags) != 1 || nodes[1].Tags[0] != "live · Gitea" { t.Fatalf("tags = %v, want [live · Gitea]", nodes[1].Tags) } } // Load-bearing: archived repos are explicitly out of scope per the issue. func TestRepoNodes_ExcludesArchived(t *testing.T) { nodes, err := atlas.RepoNodes([]byte(repoList)) if err != nil { t.Fatalf("RepoNodes: %v", err) } for _, n := range nodes { if n.Title == "old-thing" { t.Fatalf("archived repo surfaced: %+v", n) } } } func TestRepoNodes_EmptyListReturnsEmptyNotNil(t *testing.T) { nodes, err := atlas.RepoNodes([]byte(`[]`)) if err != nil { t.Fatalf("RepoNodes: %v", err) } if nodes == nil || len(nodes) != 0 { t.Fatalf("nodes = %+v, want empty non-nil slice", nodes) } } func TestRepoNodes_MalformedJSONErrors(t *testing.T) { if _, err := atlas.RepoNodes([]byte(`{`)); err == nil { t.Fatal("want an error for malformed JSON, got nil") } }