Repost
This commit is contained in:
@@ -221,6 +221,54 @@ func TestVoteRequiresAuthAndValidMode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
alice := registerAndLogin(t, srv, "alice")
|
||||
bob := registerAndLogin(t, srv, "bob")
|
||||
pid := createEntry(t, alice, srv, "bump me")
|
||||
bumpURL := fmt.Sprintf("%s/entry/%d/bump", srv.URL, pid)
|
||||
|
||||
// Anonym: 401.
|
||||
resp := postForm(t, newClient(t), bumpURL, url.Values{})
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusUnauthorized {
|
||||
t.Fatalf("anon bump: erwartet 401, bekam %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Erster Bump (bump_count 0 -> kein Cooldown): 200, danach bump_count 1.
|
||||
resp = postForm(t, alice, bumpURL, url.Values{})
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("erster bump: erwartet 200, bekam %d", resp.StatusCode)
|
||||
}
|
||||
var out struct {
|
||||
BumpCount int64 `json:"bump_count"`
|
||||
RetryAfter int64 `json:"retry_after"`
|
||||
}
|
||||
json.NewDecoder(resp.Body).Decode(&out)
|
||||
if out.BumpCount != 1 || out.RetryAfter != 86400 {
|
||||
t.Fatalf("nach erstem bump: %+v", out)
|
||||
}
|
||||
|
||||
// Cooldown gilt pro Beitrag (global): auch ein anderer Nutzer wird sofort
|
||||
// abgewiesen.
|
||||
resp = postForm(t, bob, bumpURL, url.Values{})
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusTooManyRequests {
|
||||
t.Fatalf("bump im cooldown: erwartet 429, bekam %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Gelöschter Beitrag lässt sich nicht bumpen.
|
||||
del := createEntry(t, alice, srv, "weg gleich")
|
||||
resp = postForm(t, alice, fmt.Sprintf("%s/entry/%d/delete", srv.URL, del), url.Values{})
|
||||
resp.Body.Close()
|
||||
resp = postForm(t, alice, fmt.Sprintf("%s/entry/%d/bump", srv.URL, del), url.Values{})
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusNotFound {
|
||||
t.Fatalf("bump gelöscht: erwartet 404, bekam %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// createReply erstellt eine Antwort auf parentPID und liefert deren pid.
|
||||
func createReply(t *testing.T, c *http.Client, srv *httptest.Server, content string, parentPID int64) int64 {
|
||||
t.Helper()
|
||||
|
||||
Reference in New Issue
Block a user