Files
filebrowser/backend/internal/database/activity/activity_test.go
T
+10 3c02eedca6 Beta/v2.0.0 (#2746)
Co-authored-by: Kevin B. <kurami32_kbm@proton.me>
Co-authored-by: Gabriel Górski <me@glaeqen.eu>
Co-authored-by: Joel Godfrey <82655889+BaccanoMob@users.noreply.github.com>
Co-authored-by: Shane Chiu <71911511+pwn2ooown@users.noreply.github.com>
Co-authored-by: carloda <35763669+carloda@users.noreply.github.com>
Co-authored-by: Taufik Hidayat <taufikdev88@gmail.com>
Co-authored-by: Stephan Paternotte <Stephan-P@users.noreply.github.com>
Co-authored-by: SIDDHU SINGH <siddhu3116@gmail.com>
Co-authored-by: Gaurav Kalal <117557391+Gorupa@users.noreply.github.com>
Co-authored-by: Nebula <40148908+nebula-it@users.noreply.github.com>
Co-authored-by: Juan Soler <juansoler@gmail.com>
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
Co-authored-by: Anatolii Prylutskyi <anpryl@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Graham Steffaniak <graham@debian-lake.ghome.net>
Co-authored-by: Neil <kylelzzz02@icloud.com>
Co-authored-by: Graham <info@quantumx-apps.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 16:24:38 -05:00

84 lines
1.9 KiB
Go

package activity
import (
"encoding/json"
"testing"
)
func TestPrepForFrontendPromotesAuthWithoutDuplicatingDetails(t *testing.T) {
entry := Entry{
ID: 1,
CreatedAt: 1700000000,
EventType: EventUserUpdate,
Details: Details{
TargetUsername: "admin",
TokenName: "unique",
AuthMethod: "apiKey",
Changes: []FieldChange{{
Field: "quickDownload",
From: "true",
To: "false",
}},
},
}
fe := entry.PrepForFrontend("admin")
if fe.TokenName != "unique" {
t.Fatalf("TokenName = %q, want unique", fe.TokenName)
}
if fe.AuthMethod != "apiKey" {
t.Fatalf("AuthMethod = %q, want apiKey", fe.AuthMethod)
}
detailsJSON, err := json.Marshal(fe.Details)
if err != nil {
t.Fatal(err)
}
var details map[string]any
if err := json.Unmarshal(detailsJSON, &details); err != nil {
t.Fatal(err)
}
if _, ok := details["tokenName"]; ok {
t.Fatalf("details must not include tokenName: %s", detailsJSON)
}
if _, ok := details["authMethod"]; ok {
t.Fatalf("details must not include authMethod: %s", detailsJSON)
}
if len(fe.Details.Changes) != 1 {
t.Fatalf("expected 1 change in details, got %d", len(fe.Details.Changes))
}
}
func TestPrepForFrontendPromotesShareHashWithoutDuplicatingDetails(t *testing.T) {
entry := Entry{
ID: 2,
CreatedAt: 1700000001,
EventType: EventShareUpdate,
Details: Details{
Source: "default",
Path: "/shared",
ShareHash: "abc123",
Changes: []FieldChange{{
Field: "title",
From: "before",
To: "after",
}},
},
}
fe := entry.PrepForFrontend("owner")
if fe.ShareHash != "abc123" {
t.Fatalf("ShareHash = %q, want abc123", fe.ShareHash)
}
detailsJSON, err := json.Marshal(fe.Details)
if err != nil {
t.Fatal(err)
}
var details map[string]any
if err := json.Unmarshal(detailsJSON, &details); err != nil {
t.Fatal(err)
}
if _, ok := details["shareHash"]; ok {
t.Fatalf("details must not include shareHash: %s", detailsJSON)
}
}