add document service and acitons
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"mediarr/ident"
|
||||
)
|
||||
|
||||
func TestListLibraries(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
ctx := context.Background()
|
||||
owner := mustUser(t, service, "owner")
|
||||
|
||||
mustLibrary(t, service, owner, "Photos")
|
||||
mustLibrary(t, service, owner, "Films")
|
||||
|
||||
libraries, err := service.ListLibraries(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("ListLibraries : %v", err)
|
||||
}
|
||||
if len(libraries) != 2 {
|
||||
t.Fatalf("bibliothèques = %d, attendu 2", len(libraries))
|
||||
}
|
||||
if libraries[0].Name != "Films" || libraries[1].Name != "Photos" {
|
||||
t.Fatalf("ordre = %q, %q", libraries[0].Name, libraries[1].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListChildren(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
ctx := context.Background()
|
||||
owner := mustUser(t, service, "owner")
|
||||
library := mustLibrary(t, service, owner, "Photos")
|
||||
|
||||
mustFolder(t, service, owner, library.ID, "B")
|
||||
a := mustFolder(t, service, owner, library.ID, "A")
|
||||
|
||||
children, err := service.ListChildren(ctx, library.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("ListChildren : %v", err)
|
||||
}
|
||||
if len(children) != 2 || children[0].Name != "A" || children[1].Name != "B" {
|
||||
t.Fatalf("enfants = %+v", children)
|
||||
}
|
||||
|
||||
if _, err := service.Trash(ctx, a.ID, owner.ID); err != nil {
|
||||
t.Fatalf("Trash : %v", err)
|
||||
}
|
||||
|
||||
children, err = service.ListChildren(ctx, library.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("ListChildren après trash : %v", err)
|
||||
}
|
||||
if len(children) != 1 || children[0].Name != "B" {
|
||||
t.Fatalf("enfants après trash = %+v", children)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDeletedDocument(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
ctx := context.Background()
|
||||
owner := mustUser(t, service, "owner")
|
||||
library := mustLibrary(t, service, owner, "Photos")
|
||||
|
||||
if _, err := service.Trash(ctx, library.ID, owner.ID); err != nil {
|
||||
t.Fatalf("Trash : %v", err)
|
||||
}
|
||||
|
||||
deleted, err := service.Get(ctx, library.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("Get : %v", err)
|
||||
}
|
||||
if deleted.DeletedAt == nil {
|
||||
t.Fatal("deleted_at non renseigné")
|
||||
}
|
||||
if deleted.DeletedBy == nil || *deleted.DeletedBy != owner.ID {
|
||||
t.Fatalf("deleted_by = %v, attendu %s", deleted.DeletedBy, owner.ID)
|
||||
}
|
||||
if len(deleted.TrashBatch) == 0 {
|
||||
t.Fatal("trash_batch non renseigné")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMissingDocument(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
missing, err := ident.NewV7()
|
||||
if err != nil {
|
||||
t.Fatalf("NewV7 : %v", err)
|
||||
}
|
||||
|
||||
_, err = service.Get(context.Background(), missing)
|
||||
if !errors.Is(err, ErrDocumentNotFound) {
|
||||
t.Fatalf("erreur = %v, attendu ErrDocumentNotFound", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListChildrenMissingParent(t *testing.T) {
|
||||
service := newTestService(t)
|
||||
missing, err := ident.NewV7()
|
||||
if err != nil {
|
||||
t.Fatalf("NewV7 : %v", err)
|
||||
}
|
||||
|
||||
_, err = service.ListChildren(context.Background(), missing)
|
||||
if !errors.Is(err, ErrDocumentNotFound) {
|
||||
t.Fatalf("erreur = %v, attendu ErrDocumentNotFound", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user