Skip to content
quarry Artifact [9231f5131f]
Login

Artifact [9231f5131f]

Artifact 9231f5131f1b80c40444307c9176ca9d867e8b5bce2b740424ea7bd28ab21535:


package api

import (
	"strings"
	"testing"
)

// The author is told what became of their held submission.
//
// This is the piece jva called the sharpest thing in their report: the
// rejection reason exists, is addressed to everyone through the public
// modlog, and is addressed to nobody in particular. A rejected forum
// post never entered the DAG and a rejected attachment has been
// removed, so there is no page to find and no absence to notice — the
// notification is the only way the person learns (b32aeba12bc6).
func TestAModerationDecisionAddressesItsAuthor(t *testing.T) {
	e, ok := moderationEvent("alpha", "jan", "jva", "post", "rejected",
		"How do I clone this?", "off topic — use the chat", "", "staged:7")
	if !ok {
		t.Fatal("FAIL: no event raised — the author was not told")
	}
	if e.To != "jan" {
		t.Errorf("FAIL: addressed to %q, want the author jan", e.To)
	}
	if e.Workflow != "quarry-moderation" {
		t.Errorf("FAIL: workflow %q", e.Workflow)
	}
	title, _ := e.Payload["title"].(string)
	text, _ := e.Payload["text"].(string)
	// WHICH submission, and WHY. A person with several held things
	// learns nothing from "a post was rejected".
	if !strings.Contains(text, "How do I clone this?") {
		t.Errorf("FAIL: the message does not name the submission: %q", text)
	}
	if !strings.Contains(text, "off topic") {
		t.Errorf("FAIL: the message does not carry the reason: %q", text)
	}
	if !strings.Contains(title, "rejected") || !strings.Contains(title, "alpha") {
		t.Errorf("FAIL: the title says neither what happened nor where: %q", title)
	}
	t.Logf("ok: %q / %q", title, text)
}

// A moderator resolving their OWN submission is not told about
// themselves, and an anonymous submission has nobody to tell.
func TestAModerationDecisionIsSilentWhenThereIsNobodyToTell(t *testing.T) {
	for _, c := range []struct{ what, author, moderator string }{
		{"the moderator is the author", "jva", "jva"},
		{"anonymous submission", "", "jva"},
	} {
		if _, ok := moderationEvent("alpha", c.author, c.moderator, "post", "rejected",
			"something", "a reason", "", "staged:1"); ok {
			t.Errorf("FAIL: %s raised an event, want none", c.what)
			continue
		}
		t.Logf("ok: %s is silent", c.what)
	}
}

// A decision with no reason still tells the author. Losing the message
// because the reason was empty would restore the silence this fixes.
func TestAReasonlessDecisionStillReachesTheAuthor(t *testing.T) {
	e, ok := moderationEvent("alpha", "jan", "jva", "attachment", "rejected",
		"crash.png", "", "", "attachment:abc")
	if !ok {
		t.Fatal("FAIL: no event, want one")
	}
	text, _ := e.Payload["text"].(string)
	if !strings.Contains(text, "crash.png") {
		t.Errorf("FAIL: the message does not name the file: %q", text)
	}
	t.Logf("ok: %q", text)
}