Skip to content
quarry Artifact [427abb856b]
Login

Artifact [427abb856b]

Artifact 427abb856b2313db4bb71e210eec9495ba6fe924742d79f98c8398dd57a98efb:


package oltp

import "testing"

// A rejection reaches its author, carrying the reason and their text.
//
// The half of G-118 that outlived the first fix. Approval announces
// itself — the post appears in the forum — so the author learns the
// outcome by seeing it. A rejection announced nothing: the row left
// this listing, the post had never been in the DAG, and the REASON was
// written to a public modlog the author was never pointed at. A
// stranger reading that log knew why the post was refused; its author
// did not know it had been decided at all.
//
// So the rejected row stays, with the moderator's reason on it and the
// body the author wrote. The body matters on its own: the text existed
// nowhere the author could reach, so a rejection took their writing
// with it.
func TestARejectionReachesItsAuthor(t *testing.T) {
	db := testDB(t)
	id, err := db.StagePost("r", "post", "", "eve's post", "the body eve wrote", "text/x-markdown", "eve")
	if err != nil {
		t.Fatal(err)
	}
	if err := db.ResolveStaged("r", id, "rejected"); err != nil {
		t.Fatal(err)
	}
	if err := db.AppendModLog("r", "mo", "reject", "staged:1", "off topic", "jan"); err != nil {
		t.Fatal(err)
	}

	mine, err := db.StagedMine("r", "eve")
	if err != nil {
		t.Fatal(err)
	}
	if len(mine) != 1 {
		t.Fatalf("FAIL: a rejected submission is invisible to its author: %+v", mine)
	}
	got := mine[0]
	if got.State != "rejected" {
		t.Errorf("FAIL: state = %q, want rejected", got.State)
	}
	if got.Reason != "off topic" {
		t.Errorf("FAIL: the moderator's reason did not reach the author: %q", got.Reason)
	}
	if got.Body != "the body eve wrote" {
		t.Errorf("FAIL: the author's own text was not handed back: %q", got.Body)
	}

	// Still not a queue read: somebody else's rejection stays theirs,
	// reason and all.
	if other, err := db.StagedMine("r", "jan"); err != nil || len(other) != 0 {
		t.Errorf("FAIL: jan was shown eve's rejection: %+v (err=%v)", other, err)
	}

	// A rejection with no reason recorded is still announced. Saying
	// nothing is the bug; an empty reason is only a thin answer.
	id2, err := db.StagePost("r", "post", "", "second", "more text", "text/x-markdown", "eve")
	if err != nil {
		t.Fatal(err)
	}
	if err := db.ResolveStaged("r", id2, "rejected"); err != nil {
		t.Fatal(err)
	}
	mine, err = db.StagedMine("r", "eve")
	if err != nil {
		t.Fatal(err)
	}
	if len(mine) != 2 {
		t.Fatalf("FAIL: a rejection with no modlog entry vanished: %+v", mine)
	}
}