fix(canvas): 资源引用 - 校验递归素材并修复断链
This commit is contained in:
1 parent
5bbd208bef
commit
117fa7d70b
24 files changed
+697
-218
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package assets
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCollectDocumentResourceReferencesIncludesNestedVideoPreview(t *testing.T) {
|
||||
raw := `{"nodes":[{"id":"node-video","metadata":{"videoPreview":{"storageKey":"resource:poster-1","source":{"id":"nested-not-node","url":"/api/resources/poster-2/file"}}}}]}`
|
||||
refs, err := CollectDocumentResourceReferences(raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]DocumentResourceReference{}
|
||||
for _, ref := range refs {
|
||||
got[ref.ResourceID] = ref
|
||||
}
|
||||
if ref := got["poster-1"]; ref.Path != "nodes[node-video].metadata.videoPreview.storageKey" || ref.NodeID != "node-video" || ref.ReferenceType != "storageKey" {
|
||||
t.Fatalf("nested storageKey reference = %#v", ref)
|
||||
}
|
||||
if ref := got["poster-2"]; ref.Path != "nodes[node-video].metadata.videoPreview.source.url" || ref.NodeID != "node-video" {
|
||||
t.Fatalf("nested URL reference = %#v", ref)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectDocumentResourceReferencesUsesExplicitFieldsOnly(t *testing.T) {
|
||||
raw := `{"nodes":[{"id":"node-1","metadata":{"label":"resource:not-a-reference","videoPreview":{"resourceId":"poster-3"}}}],"log":"/api/resources/log-1/file"}`
|
||||
refs, err := CollectDocumentResourceReferences(raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(refs) != 1 || refs[0].ResourceID != "poster-3" || refs[0].NodeID != "node-1" || refs[0].ReferenceType != "resourceId" {
|
||||
t.Fatalf("references = %#v", refs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectDocumentResourceReferencesReportsInvalidJSON(t *testing.T) {
|
||||
if _, err := CollectDocumentResourceReferences(`{"nodes":`); err == nil {
|
||||
t.Fatal("expected malformed document to be rejected")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user