|
| 1 | +package csapi_tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/matrix-org/complement/internal/b" |
| 9 | + "github.com/matrix-org/complement/internal/client" |
| 10 | + "github.com/matrix-org/complement/internal/data" |
| 11 | + "github.com/matrix-org/complement/runtime" |
| 12 | +) |
| 13 | + |
| 14 | +func TestAsyncUpload(t *testing.T) { |
| 15 | + runtime.SkipIf(t, runtime.Dendrite) // Dendrite doesn't support async uploads |
| 16 | + |
| 17 | + deployment := Deploy(t, b.BlueprintAlice) |
| 18 | + defer deployment.Destroy(t) |
| 19 | + |
| 20 | + alice := deployment.Client(t, "hs1", "@alice:hs1") |
| 21 | + |
| 22 | + var mxcURI, mediaID string |
| 23 | + t.Run("Create media", func(t *testing.T) { |
| 24 | + mxcURI = alice.CreateMedia(t) |
| 25 | + parts := strings.Split(mxcURI, "/") |
| 26 | + mediaID = parts[len(parts)-1] |
| 27 | + }) |
| 28 | + |
| 29 | + origin, mediaID := client.SplitMxc(mxcURI) |
| 30 | + |
| 31 | + t.Run("Not yet uploaded", func(t *testing.T) { |
| 32 | + // Check that the media is not yet uploaded |
| 33 | + res := alice.DoFunc(t, "GET", []string{"_matrix", "media", "v3", "download", origin, mediaID}) |
| 34 | + if res.StatusCode != http.StatusGatewayTimeout { |
| 35 | + t.Fatalf("Expected 504 response code, got %d", res.StatusCode) |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + t.Run("Upload media", func(t *testing.T) { |
| 40 | + alice.UploadMediaAsync(t, origin, mediaID, data.MatrixPng, "test.png", "image/png") |
| 41 | + }) |
| 42 | + |
| 43 | + t.Run("Cannot upload to a media ID that has already been uploaded to", func(t *testing.T) { |
| 44 | + alice.UploadMediaAsync(t, origin, mediaID, data.MatrixPng, "test.png", "image/png") |
| 45 | + }) |
| 46 | +} |
0 commit comments