package api
import (
"context"
"testing"
"craftdesign.group/quarry/internal/ops"
)
// The home's list marks a repository private or mirrored from the same
// answers repo.list gives, so the page filters on them without asking
// again. A detached mirror is native again, as it is there.
func TestMeReposCarriesPrivateAndMirror(t *testing.T) {
ms := memMirrors{}
_ = ms.SetMirror("tracked", "https://upstream.example/x", 3600)
_ = ms.SetMirror("gone", "https://upstream.example/y", 3600)
_ = ms.DetachMirror("gone")
r := ops.NewRegistry()
if err := RegisterAll(r, Deps{Version: "v",
Repos: NewRepos(map[string]*Repo{
"tracked": forumRepoAt(t, "a", "2026-09-01T10:00:00", "x"),
"gone": forumRepoAt(t, "b", "2026-09-02T10:00:00", "y"),
"secret": forumRepoAt(t, "c", "2026-09-03T10:00:00", "z"),
}),
Mirrors: ms,
Private: func() map[string]bool { return map[string]bool{"secret": true} },
Accounts: stubAccounts{grants: map[string]map[string]string{
"dan": {"tracked": "admin", "gone": "admin", "secret": "admin"},
}}}); err != nil {
t.Fatal(err)
}
got, err := r.Invoke(ops.WithUser(context.Background(), "dan"), "me.repos", meReposIn{})
if err != nil {
t.Fatal(err)
}
rows := map[string]meReposRow{}
for _, row := range got.(meReposOut).Repos {
rows[row.Name] = row
}
if len(rows) != 3 {
t.Fatalf("FAIL: %d rows, want 3", len(rows))
}
for name, want := range map[string][2]bool{"tracked": {false, true}, "gone": {false, false}, "secret": {true, false}} {
if rows[name].Private != want[0] || rows[name].Mirror != want[1] {
t.Errorf("FAIL: %s private=%v mirror=%v, want private=%v mirror=%v",
name, rows[name].Private, rows[name].Mirror, want[0], want[1])
}
}
}