Skip to content
quarry Artifact [0a0a828355]
Login

Artifact [0a0a828355]

Artifact 0a0a828355b4ee482395d4b6d1d5360449ed9618212e7d26d09be381db4cb162:


package api

import (
	"testing"

	"craftdesign.group/quarry/internal/oltp"
	"craftdesign.group/quarry/internal/ops"
	"craftdesign.group/quarry/internal/zitcli"
)

// A landing accepted on a login token is the person's accept: the merge
// is theirs, not an agent's, and the call carries the token's id as via.
func TestALandingAcceptedOnALoginTokenIsThePersonsAccept(t *testing.T) {
	dir, ids, ix, pipeSync := premergeStore(t)
	root := ztip(t, dir, "trunk")
	ci := &mergeRuns{pairRuns: &pairRuns{runs: map[string][]CIRun{}}}
	ci.green(ztip(t, dir, "one"), root)
	d := Deps{Version: "v", Checks: mergeChecks{}, CI: ci, Repos: NewRepos(map[string]*Repo{
		"test": {Chat: "test", Index: ix, Zit: zitcli.New(dir), Sync: pipeSync}})}
	// A token with no ceiling holds its person's own letters.
	login := ops.TokenAuth{ID: "login-token-1", Caps: func(string) ops.Caps { return oltp.CapSet("oi") }}
	ctx := ops.WithToken(ops.WithUser(t.Context(), "dan"), login)
	if got := ops.Via(ctx); got != "login-token-1" {
		t.Errorf("FAIL: via is %q, want the token's id", got)
	}
	if _, err := d.landingSay(ctx, landingSayIn{Repo: "test", ID: ids[0]}, "accept"); err != nil {
		t.Fatal(err)
	}
	merges, err := ix.MergesForLandings([]string{ids[0]})
	if err != nil {
		t.Fatal(err)
	}
	if m := merges[ids[0]]; m.User != "dan" {
		t.Errorf("FAIL: the merge is by %q, want the person", m.User)
	}
	if l, ok, _ := ix.LandingByPrefix(ids[0]); !ok || l.State != "accepted" {
		t.Errorf("FAIL: the landing is %+v", l)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}