63ede5c237
- refactor: move HTTP status and DTO concerns out of model and service layers into API and handler code. - feat: add admin service boundary and route auth through services instead of direct repository access. - test: add architecture and error tests covering package boundaries, redaction, and service behavior. - docs: record the protocol-neutral boundary decision and update architecture and roadmap notes.
50 lines
1022 B
Go
50 lines
1022 B
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFileJSONOmitsInternalFields(t *testing.T) {
|
|
f := &File{
|
|
ID: "1",
|
|
UserID: "u1",
|
|
ParentID: nil,
|
|
Name: "test.txt",
|
|
Size: 100,
|
|
MimeType: "text/plain",
|
|
StoragePath: "users/u1/files/1",
|
|
Hash: "abc123",
|
|
Status: StatusActive,
|
|
IsDir: false,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
}
|
|
|
|
data, err := json.Marshal(f)
|
|
if err != nil {
|
|
t.Fatalf("json.Marshal: %v", err)
|
|
}
|
|
|
|
var result map[string]any
|
|
if err := json.Unmarshal(data, &result); err != nil {
|
|
t.Fatalf("json.Unmarshal: %v", err)
|
|
}
|
|
|
|
assertJSONKeysAbsent(t, result,
|
|
"StoragePath", "storage_path",
|
|
"Hash", "hash",
|
|
"Status", "status",
|
|
)
|
|
}
|
|
|
|
func TestStatusConstants(t *testing.T) {
|
|
if StatusActive != "active" {
|
|
t.Errorf("StatusActive = %q, want \"active\"", StatusActive)
|
|
}
|
|
if StatusUserDeleted != "user_deleted" {
|
|
t.Errorf("StatusUserDeleted = %q, want \"user_deleted\"", StatusUserDeleted)
|
|
}
|
|
}
|