release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- The like/unlike story runs as one sequence that checks the rows after each step. - The invite-only sign-up cases are one test, which now also checks that a refused sign-up creates no account. - Demoting an admin, and stopping at the last one, is one test. - A wrong password and an unknown user are one test, which now also checks that the two refusals are identical. - The cover-path resolver tests repeated the cover handler's tests branch for branch; the handler tests stay. - The Range-from-start stream test only re-checked http.ServeContent. - The APK's nil-user 401 is covered by the mounted-route walk. - 68 copies of the MINSTREL_TEST_DATABASE_URL skip go: every one of those tests reaches dbtest.Pool, which already skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
|
)
|
|
|
|
func newMeTimezoneRouter(h *handlers) chi.Router {
|
|
r := chi.NewRouter()
|
|
r.Put("/api/me/timezone", h.handlePutTimezone)
|
|
return r
|
|
}
|
|
|
|
func TestPutTimezone_ValidIANA(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "tz1", "irrelevant1", false)
|
|
|
|
body := bytes.NewBufferString(`{"timezone":"America/New_York"}`)
|
|
req := httptest.NewRequest(http.MethodPut, "/api/me/timezone", body)
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req = withUser(req, user)
|
|
rec := httptest.NewRecorder()
|
|
newMeTimezoneRouter(h).ServeHTTP(rec, req)
|
|
|
|
if rec.Code != http.StatusNoContent {
|
|
t.Fatalf("status = %d, want 204; body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
|
|
// Verify the DB row was updated.
|
|
got, err := dbq.New(pool).GetUserByID(context.Background(), user.ID)
|
|
if err != nil {
|
|
t.Fatalf("GetUserByID: %v", err)
|
|
}
|
|
if got.Timezone != "America/New_York" {
|
|
t.Errorf("timezone = %q, want %q", got.Timezone, "America/New_York")
|
|
}
|
|
if !got.TimezoneUpdatedAt.Valid {
|
|
t.Errorf("expected timezone_updated_at to be set after PUT")
|
|
}
|
|
}
|
|
|
|
func TestPutTimezone_InvalidIANA(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "tz2", "irrelevant1", false)
|
|
|
|
body := bytes.NewBufferString(`{"timezone":"Not/A/Real/Zone"}`)
|
|
req := httptest.NewRequest(http.MethodPut, "/api/me/timezone", body)
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req = withUser(req, user)
|
|
rec := httptest.NewRecorder()
|
|
newMeTimezoneRouter(h).ServeHTTP(rec, req)
|
|
|
|
if rec.Code != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400; body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
|
|
// Error envelope is nested: {"error":{"code":...}} (matches the
|
|
// rest of /api/*), not a top-level {"code":...}.
|
|
var errResp struct {
|
|
Error struct {
|
|
Code string `json:"code"`
|
|
} `json:"error"`
|
|
}
|
|
if err := json.NewDecoder(rec.Body).Decode(&errResp); err != nil {
|
|
t.Fatalf("decode err response: %v", err)
|
|
}
|
|
if errResp.Error.Code != "invalid_timezone" {
|
|
t.Errorf("error code = %q, want invalid_timezone", errResp.Error.Code)
|
|
}
|
|
}
|
|
|
|
func TestPutTimezone_EmptyTimezone(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "tz3", "irrelevant1", false)
|
|
|
|
body := bytes.NewBufferString(`{"timezone":""}`)
|
|
req := httptest.NewRequest(http.MethodPut, "/api/me/timezone", body)
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req = withUser(req, user)
|
|
rec := httptest.NewRecorder()
|
|
newMeTimezoneRouter(h).ServeHTTP(rec, req)
|
|
|
|
if rec.Code != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400", rec.Code)
|
|
}
|
|
}
|