Skip to content
quarry Artifact [cf433d7102]
Login

Artifact [cf433d7102]

Artifact cf433d71025b45adfc61449d7b984d44ef9e2e467b761170a82ba46794ebd33c:


package api

import (
	"context"
	"testing"

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

// Before filing, the likely duplicates: tickets sharing enough of the
// title's significant words, open ones first, with their links. A
// title about something else finds nothing.
func TestTicketSimilarFindsTheLikelyTwins(t *testing.T) {
	r, _ := idemRegistry(t)
	ctx := ops.WithUser(context.Background(), "dan")
	file := func(title, status string) string {
		out, err := r.Invoke(ctx, "ticket.intake", ticketIntakeIn{Repo: "test", Title: title, Status: status})
		if err != nil {
			t.Fatal(err)
		}
		return out.(ticketIntakeOut).ID
	}
	closed := file("Configuration export refused for the shun area", "Closed")
	open := file("Settings export link answers 400 for shun", "Open")
	file("Chat bridge drops messages after a restart", "Open")

	out, err := r.Invoke(ctx, "ticket.similar", ticketSimilarIn{Repo: "test", Title: "Export of the shun area answers 400"})
	if err != nil {
		t.Fatal(err)
	}
	got := out.(ticketSimilarOut).Tickets
	if len(got) != 2 || got[0].ID != open || got[1].ID != closed || !got[0].Local || got[0].URL != "https://forge.example/r/test/ticket/"+open {
		t.Fatalf("FAIL: similar = %+v, want the open export ticket then the closed one", got)
	}
	none, _ := r.Invoke(ctx, "ticket.similar", ticketSimilarIn{Repo: "test", Title: "Landing page typography"})
	if n := len(none.(ticketSimilarOut).Tickets); n != 0 {
		t.Fatalf("FAIL: an unrelated title matched %d tickets", n)
	}
	t.Log("ok: the open export ticket first, the closed one after, the chat one not at all; an unrelated title finds none")
}