Skip to content

Commit

Permalink
Validate asset IDs in CreateStack and add test case for bad requests (#…
Browse files Browse the repository at this point in the history
…751)

* create test case for bad stack call

* fix: validate asset IDs in CreateStack and ensure at least two assets are provided

* fix: update test file paths in e2e_bad_request_test to confirm fix and continuing the upload
  • Loading branch information
simulot authored Feb 23, 2025
1 parent a953dc1 commit 7d4edc8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions immich/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ package immich

import (
"context"
"fmt"

"github.com/google/uuid"
)

// CreateStack create a stack with the given assets, the 1st asset is the cover, return the stack ID
func (ic *ImmichClient) CreateStack(ctx context.Context, ids []string) (string, error) {
// remove the empty ids
for i := 0; i < len(ids); i++ {
if ids[i] == "" {
ids = append(ids[:i], ids[i+1:]...)
i--
}
}
if len(ids) < 2 {
return "", fmt.Errorf("stack must have at least 2 assets")
}

if ic.dryRun {
return uuid.NewString(), nil
}
Expand Down
48 changes: 48 additions & 0 deletions internal/e2eTests/upload/e2e_bad_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package upload
import (
"context"
"os"
"os/exec"
"testing"

"github.com/simulot/immich-go/app/cmd"
Expand Down Expand Up @@ -121,3 +122,50 @@ func Test_BadRequest(t *testing.T) {
t.Fatal(err)
}
}

func Test_BadRequestByAzwillnj(t *testing.T) {
t.Log("Test_BadRequestByAzwillnj")

client, err := e2e.GetImmichClient()
if err != nil {
t.Fatal(err)
}

e2e.InitMyEnv()
e2e.ResetImmich(t)

ctx := context.Background()

// Upload with immich-go v0.21.1
err = exec.CommandContext(ctx, e2e.MyEnv("IMMICHGO_TESTFILES")+"/#700 Error 500 when upload/lbmh/immich-go.v0.21.1",
"upload",
"-server="+e2e.MyEnv("IMMICHGO_SERVER"),
"-key="+e2e.MyEnv("IMMICHGO_APIKEY"),
"-google-photos",
e2e.MyEnv("IMMICHGO_TESTFILES")+"/#700 Error 500 when upload/azwillnj/takeout/Photos from 2016").Run()
if err != nil {
t.Log(err)
}

e2e.WaitingForJobsEnding(ctx, client, t)

// Same upload with current immich-go
c, a := cmd.RootImmichGoCommand(ctx)
c.SetArgs([]string{
"upload", "from-google-photos",
"--server=" + e2e.MyEnv("IMMICHGO_SERVER"),
"--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"),
"--no-ui",
"--api-trace",
"--log-level=debug",
e2e.MyEnv("IMMICHGO_TESTFILES") + "/#700 Error 500 when upload/azwillnj/takeout",
})

err = c.ExecuteContext(ctx)
if err != nil && a.Log().GetSLog() != nil {
a.Log().Error(err.Error())
t.Fatal(err)
}

e2e.WaitingForJobsEnding(ctx, client, t)
}

0 comments on commit 7d4edc8

Please sign in to comment.