ingest documents
This commit is contained in:
@@ -280,3 +280,111 @@ func TestCreateFolderRejectsDuplicateSibling(t *testing.T) {
|
||||
t.Fatalf("erreur = %v, attendu ErrNameTaken", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateChild(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
ctx := context.Background()
|
||||
owner := mustUser(t, service, "owner")
|
||||
library := mustLibrary(t, service, owner, "Photos")
|
||||
|
||||
video, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: KindVideo,
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "film.mkv",
|
||||
Metadata: `{"source_path":"film.mkv"}`,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateChild(video) : %v", err)
|
||||
}
|
||||
if video.Kind != KindVideo {
|
||||
t.Fatalf("kind = %q, attendu %q", video.Kind, KindVideo)
|
||||
}
|
||||
if video.ParentID == nil || *video.ParentID != library.ID {
|
||||
t.Fatalf("parent = %v, attendu %s", video.ParentID, library.ID)
|
||||
}
|
||||
if video.Depth != library.Depth+1 {
|
||||
t.Fatalf("depth = %d, attendu %d", video.Depth, library.Depth+1)
|
||||
}
|
||||
if video.Metadata != `{"source_path":"film.mkv"}` {
|
||||
t.Fatalf("metadata = %q", video.Metadata)
|
||||
}
|
||||
|
||||
folder, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: KindFolder,
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "Extras",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateChild(folder) : %v", err)
|
||||
}
|
||||
if folder.Kind != KindFolder {
|
||||
t.Fatalf("kind = %q, attendu %q", folder.Kind, KindFolder)
|
||||
}
|
||||
if folder.Metadata != "{}" {
|
||||
t.Fatalf("metadata = %q, attendu {}", folder.Metadata)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateChildRejectsInvalidInputs(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
ctx := context.Background()
|
||||
owner := mustUser(t, service, "owner")
|
||||
other := mustUser(t, service, "other")
|
||||
library := mustLibrary(t, service, owner, "Photos")
|
||||
|
||||
if _, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: KindVideo,
|
||||
OwnerID: other.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "film.mkv",
|
||||
}); !errors.Is(err, ErrPermissionDenied) {
|
||||
t.Fatalf("owner usurpé : erreur = %v, attendu ErrPermissionDenied", err)
|
||||
}
|
||||
|
||||
if _, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: "inconnu",
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "film.mkv",
|
||||
}); !errors.Is(err, ErrInvalidKind) {
|
||||
t.Fatalf("kind invalide : erreur = %v, attendu ErrInvalidKind", err)
|
||||
}
|
||||
|
||||
if _, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: KindVideo,
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "film.mkv",
|
||||
Metadata: "{",
|
||||
}); !errors.Is(err, ErrInvalidMetadata) {
|
||||
t.Fatalf("metadata invalide : erreur = %v, attendu ErrInvalidMetadata", err)
|
||||
}
|
||||
|
||||
video, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: KindVideo,
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "film.mkv",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateChild(video) : %v", err)
|
||||
}
|
||||
|
||||
if _, err := service.CreateChild(ctx, owner.ID, CreateChildParams{
|
||||
Kind: KindVideo,
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: video.ID,
|
||||
Name: "enfant.mkv",
|
||||
}); !errors.Is(err, ErrInvalidParent) {
|
||||
t.Fatalf("parent non conteneur : erreur = %v, attendu ErrInvalidParent", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user