a8078f787c
Add Status field (gorm, indexed, default active) to both User and File models. Add User status constants: StatusActive, StatusAdminDeleted. Add File status constant: StatusUserDeleted. Add tests verifying Status field is excluded from JSON serialization. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFile_StatusExcludedFromJSON(t *testing.T) {
|
|
f := &File{
|
|
ID: "1",
|
|
UserID: "u1",
|
|
ParentID: nil,
|
|
Name: "test.txt",
|
|
Size: 100,
|
|
MimeType: "text/plain",
|
|
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)
|
|
}
|
|
|
|
if _, ok := result["status"]; ok {
|
|
t.Errorf("Status field should be excluded from JSON (json:\"-\"), but it appeared in output")
|
|
}
|
|
|
|
if _, ok := result["hash"]; ok {
|
|
t.Errorf("Hash field should be excluded from JSON (json:\"-\"), but it appeared in output")
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|