Files
moteva/server/internal/logic/save_canvas_logic_test.go
T

88 lines
2.4 KiB
Go
Raw Normal View History

package logic
import (
"context"
"testing"
"time"
"img_infinite_canvas/internal/application"
"img_infinite_canvas/internal/domain/design"
"img_infinite_canvas/internal/infrastructure/memory"
"img_infinite_canvas/internal/svc"
"img_infinite_canvas/internal/types"
)
func TestSaveCanvasReturnsSaveProjectMetadata(t *testing.T) {
ctx := context.Background()
repo := memory.NewProjectRepository()
service := application.NewDesignService(repo, nil, nil, nil, nil)
project := design.Project{
ID: "project-save-metadata",
Title: "Save metadata",
Status: design.StatusReady,
UpdatedAt: time.Unix(100, 0).UTC(),
Version: "100000",
SnapshotID: "snapshot-old",
Viewport: design.Viewport{K: 1},
}
if err := repo.Save(ctx, project); err != nil {
t.Fatal(err)
}
logic := NewSaveCanvasLogic(ctx, &svc.ServiceContext{DesignService: service})
resp, err := logic.SaveCanvas(&types.SaveCanvasRequest{
Id: project.ID,
Version: project.Version,
Viewport: types.CanvasViewport{
K: 1,
},
})
if err != nil {
t.Fatal(err)
}
if resp.Code != 0 || resp.Msg != nil {
t.Fatalf("unexpected wrapper: %#v", resp)
}
if resp.Data.ProjectId != project.ID || resp.Data.NewCreated || !resp.Data.ValidProjectId || resp.Data.Version == "" {
t.Fatalf("unexpected save project data: %#v", resp.Data)
}
}
func TestSaveProjectReturnsSaveProjectMetadata(t *testing.T) {
ctx := context.Background()
repo := memory.NewProjectRepository()
service := application.NewDesignService(repo, nil, nil, nil, nil)
project := design.Project{
ID: "project-lovart-save",
Title: "Lovart save",
Status: design.StatusReady,
UpdatedAt: time.Unix(100, 0).UTC(),
Version: "100000",
SnapshotID: "snapshot-old",
Viewport: design.Viewport{K: 1},
}
if err := repo.Save(ctx, project); err != nil {
t.Fatal(err)
}
logic := NewSaveProjectLogic(ctx, &svc.ServiceContext{DesignService: service})
resp, err := logic.SaveProject(&types.SaveProjectRequest{
ProjectId: project.ID,
Version: project.Version,
Viewport: types.CanvasViewport{
K: 1,
},
})
if err != nil {
t.Fatal(err)
}
if resp.Code != 0 || resp.Msg != nil {
t.Fatalf("unexpected wrapper: %#v", resp)
}
if resp.Data.ProjectId != project.ID || resp.Data.NewCreated || !resp.Data.ValidProjectId || resp.Data.Version == "" {
t.Fatalf("unexpected save project data: %#v", resp.Data)
}
}