Skip to content
quarry Artifact [4874ac225f]
Login

Artifact [4874ac225f]

Artifact 4874ac225f65cc0ea0f1cc125f70d4bedbe033b04e1e600fa3f706fa4d040dcb:


package api

import (
	"context"
	"strings"
	"testing"
)

// A failed import tells the person who asked, and names no repository
// in its payload: there is none to read, and the delivery-time read
// check would otherwise drop the notice. It links the progress page,
// which keeps the reason.
func TestImportFailureTellsWhoAskedWithoutARepository(t *testing.T) {
	fn := &fakeNotify{}
	// Nobody can read a repository that does not exist.
	d := Deps{Notify: fn, CanRead: func(context.Context, string) bool { return false }}
	d.NotifyImportEnded("linux", "dan", "2026-10-24 14:45:00", "zit import-git: refused (preflight_failed): import failed: Malformed")
	ev := waitNotify(fn, 1)[0]
	if ev.To != "dan" || ev.Workflow != "quarry-landing" {
		t.Fatalf("FAIL: to %q on %q", ev.To, ev.Workflow)
	}
	if _, ok := ev.Payload["repo"]; ok {
		t.Errorf("FAIL: a failed import's notice names a repo: %v", ev.Payload)
	}
	if link, _ := ev.Payload["link"].(string); !strings.HasSuffix(link, "/new/progress/linux") {
		t.Errorf("FAIL: link = %q, want the progress page", link)
	}
	if s, _ := ev.Payload["summary"].(string); !strings.Contains(s, "Malformed") {
		t.Errorf("FAIL: summary %q does not carry the reason", s)
	}
}

func TestImportFinishedLinksTheRepository(t *testing.T) {
	fn := &fakeNotify{}
	d := Deps{Notify: fn}
	d.NotifyImportEnded("linux", "dan", "2026-10-24 14:45:00", "")
	ev := waitNotify(fn, 1)[0]
	if ev.Payload["repo"] != "linux" {
		t.Errorf("FAIL: payload repo = %v", ev.Payload["repo"])
	}
	if link, _ := ev.Payload["link"].(string); !strings.HasSuffix(link, "/r/linux") {
		t.Errorf("FAIL: link = %q", link)
	}
}

// A topic is nobody: an import owned by no person tells no one.
func TestImportEndedSkipsATopic(t *testing.T) {
	fn := &fakeNotify{}
	Deps{Notify: fn}.NotifyImportEnded("linux", "admins", "", "x")
	Deps{Notify: fn}.NotifyImportEnded("linux", "", "", "x")
	if n := len(fn.snapshot()); n != 0 {
		t.Fatalf("FAIL: %d notices for no person", n)
	}
}