53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"hfb_sys/backend/internal/model"
|
|
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
func TestCanonicalKeysHandlesJSONScalarAndInvalidReferences(t *testing.T) {
|
|
row := sourceRow{
|
|
Keys: datatypes.JSON([]byte(`[
|
|
"/api/files/object?key=listing%2Fa.webp",
|
|
"listing/a.webp",
|
|
"https://external.example.com/file.webp"
|
|
]`)),
|
|
ScalarKey: "/api/files/object?key=listing%2Fb.webp",
|
|
}
|
|
keys, malformed, invalid := canonicalKeys(row)
|
|
if malformed != 0 || invalid != 1 {
|
|
t.Fatalf("malformed=%d invalid=%d, want 0/1", malformed, invalid)
|
|
}
|
|
if len(keys) != 2 || keys[0] != "listing/a.webp" || keys[1] != "listing/b.webp" {
|
|
t.Fatalf("keys = %#v", keys)
|
|
}
|
|
}
|
|
|
|
func TestCanonicalKeysReportsMalformedJSON(t *testing.T) {
|
|
keys, malformed, invalid := canonicalKeys(sourceRow{
|
|
Keys: datatypes.JSON([]byte(`{"bad":true}`)),
|
|
})
|
|
if len(keys) != 0 || malformed != 1 || invalid != 0 {
|
|
t.Fatalf("keys=%#v malformed=%d invalid=%d", keys, malformed, invalid)
|
|
}
|
|
}
|
|
|
|
func TestBindingTargetForConversationQrCode(t *testing.T) {
|
|
conversationID := uint64(88)
|
|
resourceType, resourceID, scope, ownerUserID, tenantID := bindingTarget("chat_qrcode_pool", sourceRow{
|
|
ResourceID: 9,
|
|
TenantID: 101,
|
|
ConversationID: &conversationID,
|
|
})
|
|
if resourceType != model.FileResourceChatConversation ||
|
|
resourceID != conversationID ||
|
|
scope != model.FileScopeQrCodeParticipant ||
|
|
ownerUserID != 0 ||
|
|
tenantID != 101 {
|
|
t.Fatalf("target = %s/%d/%s owner=%d tenant=%d", resourceType, resourceID, scope, ownerUserID, tenantID)
|
|
}
|
|
}
|