removed all "paid" features - no more stars, gifts, or grams
This commit is contained in:
parent
d4451d753c
commit
21d8e91756
165 changed files with 318 additions and 40948 deletions
|
|
@ -144,92 +144,6 @@ func TestModerationReadAPIDisablesBrowserCaching(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStarGiftRowJSONPreservesInt64AsDecimalStrings(t *testing.T) {
|
||||
const maxInt64 = int64(9223372036854775807)
|
||||
raw, err := json.Marshal(StarGiftRow{
|
||||
GiftID: maxInt64,
|
||||
RevisionID: maxInt64,
|
||||
Stars: maxInt64,
|
||||
ConvertStars: maxInt64,
|
||||
DocumentID: maxInt64,
|
||||
AnimationSize: maxInt64,
|
||||
ReceivedCount: maxInt64,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal star gift row: %v", err)
|
||||
}
|
||||
var got map[string]any
|
||||
if err := json.Unmarshal(raw, &got); err != nil {
|
||||
t.Fatalf("unmarshal star gift row: %v", err)
|
||||
}
|
||||
for _, field := range []string{"GiftID", "RevisionID", "Stars", "ConvertStars", "DocumentID", "AnimationSize", "ReceivedCount"} {
|
||||
if got[field] != "9223372036854775807" {
|
||||
t.Fatalf("%s = %#v, want exact decimal string", field, got[field])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultGiftImportActionDecodes(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/actions/import-default-gift", strings.NewReader(`{
|
||||
"command_id":"c1","reason":"demo","confirm":true,"id":3,"enabled":true
|
||||
}`))
|
||||
var got importDefaultStarGiftAPIRequest
|
||||
if err := decodeJSON(req, &got); err != nil {
|
||||
t.Fatalf("decode default gift action: %v", err)
|
||||
}
|
||||
if got.ID != 3 || got.CommandID != "c1" || !got.Confirm || !got.Enabled {
|
||||
t.Fatalf("decoded default gift action = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOfficialGiftActionDecimalStringDecodingPreservesInt64(t *testing.T) {
|
||||
const maxInt64 = int64(9223372036854775807)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/actions/import-official-gift", strings.NewReader(`{
|
||||
"source_gift_id":"5895603153683874485",
|
||||
"gift_id":"9223372036854775807",
|
||||
"stars":"9223372036854775807",
|
||||
"convert_stars":"9223372036854775807",
|
||||
"upgrade_stars":"9223372036854775807"
|
||||
}`))
|
||||
var got importOfficialStarGiftAPIRequest
|
||||
if err := decodeJSON(req, &got); err != nil {
|
||||
t.Fatalf("decode official gift action: %v", err)
|
||||
}
|
||||
if got.GiftID != maxInt64 || got.Stars != maxInt64 || got.ConvertStars != maxInt64 || got.UpgradeStars != maxInt64 {
|
||||
t.Fatalf("decoded official gift action = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStarGiftEnabledBFFForwardsExactInt64(t *testing.T) {
|
||||
const maxInt64 = int64(9223372036854775807)
|
||||
var got admin.SetStarGiftEnabledRequest
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/gifts/set-enabled" || r.Header.Get("Authorization") != "Bearer secret" {
|
||||
t.Fatalf("upstream request path=%q authorization=%q", r.URL.Path, r.Header.Get("Authorization"))
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(admin.CommandResult{CommandID: got.CommandID, Status: "completed", DryRun: got.DryRun})
|
||||
}))
|
||||
defer upstream.Close()
|
||||
|
||||
srv := &server{cfg: uiConfig{AdminAPIURL: upstream.URL, AdminAPIToken: "secret"}}
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/actions/set-gift-enabled", strings.NewReader(`{
|
||||
"reason":"precision regression","confirm":false,
|
||||
"gift_id":"9223372036854775807","enabled":false
|
||||
}`))
|
||||
req = req.WithContext(context.WithValue(req.Context(), actorKey{}, "operator"))
|
||||
rec := httptest.NewRecorder()
|
||||
srv.handleSetStarGiftEnabledAPI(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if got.GiftID != maxInt64 || got.Actor != "operator" || !got.DryRun {
|
||||
t.Fatalf("forwarded gift request = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMintCollectibleUsernameBFFForwardsActorAndTolerantScalars(t *testing.T) {
|
||||
const maxInt64 = int64(9223372036854775807)
|
||||
var got admin.MintCollectibleUsernameRequest
|
||||
|
|
@ -268,33 +182,6 @@ func TestMintCollectibleUsernameBFFForwardsActorAndTolerantScalars(t *testing.T)
|
|||
}
|
||||
}
|
||||
|
||||
func TestAdjustAccountRatingBFFForwardsNumericPayload(t *testing.T) {
|
||||
var got admin.AdjustAccountRatingRequest
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/account-ratings/adjust" {
|
||||
t.Fatalf("upstream path=%q", r.URL.Path)
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(admin.CommandResult{CommandID: got.CommandID, Status: "completed"})
|
||||
}))
|
||||
defer upstream.Close()
|
||||
|
||||
srv := &server{cfg: uiConfig{AdminAPIURL: upstream.URL, AdminAPIToken: "secret"}}
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/actions/adjust-account-rating", strings.NewReader(
|
||||
`{"reason":"manual penalty","confirm":true,"user_id":1001,"amount":-2500}`))
|
||||
req = req.WithContext(context.WithValue(req.Context(), actorKey{}, "operator"))
|
||||
rec := httptest.NewRecorder()
|
||||
srv.handleAdjustAccountRatingAPI(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if got.Actor != "operator" || got.UserID != 1001 || got.Amount != -2500 || got.DryRun {
|
||||
t.Fatalf("forwarded adjust request = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevokeCollectibleUsernameBFFRejectsUnknownFields(t *testing.T) {
|
||||
srv := &server{cfg: uiConfig{AdminAPIURL: "http://127.0.0.1:1", AdminAPIToken: "secret"}}
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/actions/revoke-collectible-username", strings.NewReader(
|
||||
|
|
@ -307,7 +194,7 @@ func TestRevokeCollectibleUsernameBFFRejectsUnknownFields(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCollectibleUsernameAndRatingRowsJSONPreserveInt64AsDecimalStrings(t *testing.T) {
|
||||
func TestCollectibleUsernameRowsJSONPreserveInt64AsDecimalStrings(t *testing.T) {
|
||||
const maxInt64 = int64(9223372036854775807)
|
||||
raw, err := json.Marshal(CollectibleUsernameRow{
|
||||
ID: maxInt64, OwnerPeerID: maxInt64, Amount: maxInt64, CryptoAmount: maxInt64,
|
||||
|
|
@ -326,30 +213,6 @@ func TestCollectibleUsernameAndRatingRowsJSONPreserveInt64AsDecimalStrings(t *te
|
|||
}
|
||||
}
|
||||
|
||||
raw, err = json.Marshal(AccountRatingRow{
|
||||
UserID: maxInt64, Stars: maxInt64, CurrentLevelStars: maxInt64, NextLevelStars: maxInt64,
|
||||
StarsComponent: maxInt64, ActivityComponent: maxInt64, PenaltyComponent: maxInt64,
|
||||
ManualComponent: -maxInt64, PendingStars: maxInt64, Version: maxInt64,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal account rating row: %v", err)
|
||||
}
|
||||
var rating map[string]any
|
||||
if err := json.Unmarshal(raw, &rating); err != nil {
|
||||
t.Fatalf("unmarshal account rating row: %v", err)
|
||||
}
|
||||
for _, field := range []string{
|
||||
"UserID", "Stars", "CurrentLevelStars", "NextLevelStars",
|
||||
"StarsComponent", "ActivityComponent", "PenaltyComponent", "PendingStars", "Version",
|
||||
} {
|
||||
if rating[field] != "9223372036854775807" {
|
||||
t.Fatalf("rating %s = %#v, want exact decimal string", field, rating[field])
|
||||
}
|
||||
}
|
||||
if rating["ManualComponent"] != "-9223372036854775807" {
|
||||
t.Fatalf("rating ManualComponent = %#v, want signed decimal string", rating["ManualComponent"])
|
||||
}
|
||||
|
||||
transfer, err := json.Marshal(CollectibleUsernameTransferRow{
|
||||
ID: maxInt64, CollectibleID: maxInt64, FromPeerID: maxInt64, ToPeerID: maxInt64, Amount: maxInt64,
|
||||
})
|
||||
|
|
@ -381,26 +244,9 @@ func TestFlexScalarsAcceptNumbersStringsAndBlanks(t *testing.T) {
|
|||
body.PurchaseDate.Unix() != time.Date(2026, 7, 26, 0, 0, 0, 0, time.UTC).Unix() {
|
||||
t.Fatalf("decoded mint action = %+v", body)
|
||||
}
|
||||
|
||||
var rating adjustAccountRatingAPIRequest
|
||||
numeric := httptest.NewRequest(http.MethodPost, "/api/actions/adjust-account-rating", strings.NewReader(
|
||||
`{"user_id":1001,"amount":-2500}`))
|
||||
if err := decodeJSON(numeric, &rating); err != nil {
|
||||
t.Fatalf("decode adjust action: %v", err)
|
||||
}
|
||||
if rating.UserID.Int64() != 1001 || rating.Amount.Int64() != -2500 {
|
||||
t.Fatalf("decoded adjust action = %+v", rating)
|
||||
}
|
||||
|
||||
var broken adjustAccountRatingAPIRequest
|
||||
invalid := httptest.NewRequest(http.MethodPost, "/api/actions/adjust-account-rating", strings.NewReader(
|
||||
`{"user_id":"not-a-number"}`))
|
||||
if err := decodeJSON(invalid, &broken); err == nil {
|
||||
t.Fatal("decoded a non-numeric user_id")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewCollectibleAndRatingRoutesRequireSession(t *testing.T) {
|
||||
func TestNewCollectibleRoutesRequireSession(t *testing.T) {
|
||||
srv, err := newServer(uiConfig{SessionKey: []byte("01234567890123456789012345678901")}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("newServer: %v", err)
|
||||
|
|
@ -411,13 +257,9 @@ func TestNewCollectibleAndRatingRoutesRequireSession(t *testing.T) {
|
|||
}{
|
||||
{http.MethodGet, "/api/collectible-usernames"},
|
||||
{http.MethodGet, "/api/collectible-usernames/7"},
|
||||
{http.MethodGet, "/api/account-ratings"},
|
||||
{http.MethodGet, "/api/account-ratings/7"},
|
||||
{http.MethodPost, "/api/actions/mint-collectible-username"},
|
||||
{http.MethodPost, "/api/actions/transfer-collectible-username"},
|
||||
{http.MethodPost, "/api/actions/revoke-collectible-username"},
|
||||
{http.MethodPost, "/api/actions/recompute-account-rating"},
|
||||
{http.MethodPost, "/api/actions/adjust-account-rating"},
|
||||
}
|
||||
for _, item := range cases {
|
||||
req := httptest.NewRequest(item.method, item.path, strings.NewReader(`{}`))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue