defmodule GitGud.LabelsOrgInheritanceTest do
@moduledoc """
Org-scoped labels merge into the repo's pickable set (with an
`:inherited?` flag); per-repo opt-outs hide them on that repo only.
"""
use GitGud.DataCase, async: false
alias GitGud.Labels
alias GitGud.Organizations
alias GitGud.Repositories
import GitGud.AccountsFixtures
setup do
user = user_fixture()
{:ok, org} = Organizations.create_organization(user, %{"handle" => "acme-#{System.unique_integer([:positive])}"})
{:ok, repo} =
Repositories.create_repository_for_org(org, user, %{"name" => "site", "visibility" => "private"})
{:ok, other_repo} =
Repositories.create_repository_for_org(org, user, %{"name" => "api", "visibility" => "private"})
{:ok, user: user, org: org, repo: repo, other_repo: other_repo}
end
test "an org label is inherited by every repo in the org", %{
org: org,
repo: repo,
other_repo: other_repo
} do
{:ok, org_label} =
Labels.create_organization_label(org, %{
"name" => "security",
"color" => "#ef4444"
})
repo_labels = Labels.list_labels(repo)
other_labels = Labels.list_labels(other_repo)
assert Enum.any?(repo_labels, &(&1.id == org_label.id and &1.inherited?))
assert Enum.any?(other_labels, &(&1.id == org_label.id and &1.inherited?))
end
test "repo-local labels carry inherited? == false", %{repo: repo} do
{:ok, repo_label} = Labels.create_label(repo, %{"name" => "bug", "color" => "#3b82f6"})
[l] =
Labels.list_labels(repo)
|> Enum.filter(&(&1.id == repo_label.id))
refute l.inherited?
end
test "opt_out hides the inherited label from one repo only", %{
org: org,
repo: repo,
other_repo: other_repo
} do
{:ok, org_label} =
Labels.create_organization_label(org, %{"name" => "policy", "color" => "#10b981"})
{:ok, _} = Labels.opt_out(repo, org_label)
refute Enum.any?(Labels.list_labels(repo), &(&1.id == org_label.id))
assert Enum.any?(Labels.list_labels(other_repo), &(&1.id == org_label.id))
assert Labels.opted_out?(repo, org_label)
refute Labels.opted_out?(other_repo, org_label)
end
test "opt_in re-enables the inherited label", %{org: org, repo: repo} do
{:ok, org_label} =
Labels.create_organization_label(org, %{"name" => "x", "color" => "#f59e0b"})
{:ok, _} = Labels.opt_out(repo, org_label)
refute Enum.any?(Labels.list_labels(repo), &(&1.id == org_label.id))
{:ok, _} = Labels.opt_in(repo, org_label)
assert Enum.any?(Labels.list_labels(repo), &(&1.id == org_label.id))
end
test "opt_out on a non-org label is a no-op error", %{repo: repo} do
{:ok, repo_label} = Labels.create_label(repo, %{"name" => "x", "color" => "#3b82f6"})
assert {:error, :not_an_org_label} = Labels.opt_out(repo, repo_label)
end
test "list_organization_labels returns org-only entries", %{org: org, repo: repo} do
{:ok, org_label} =
Labels.create_organization_label(org, %{"name" => "o", "color" => "#000000"})
{:ok, repo_label} = Labels.create_label(repo, %{"name" => "r", "color" => "#ffffff"})
org_list = Labels.list_organization_labels(org)
assert Enum.any?(org_list, &(&1.id == org_label.id))
refute Enum.any?(org_list, &(&1.id == repo_label.id))
end
end
3.3 KiB · text
5af55d9