Skip to content

Commit

Permalink
Replace file set graphQL test
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Aug 4, 2023
1 parent b51e3c1 commit 721c3cf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 0 additions & 2 deletions app/lib/meadow/pipeline/actions/generate_poster_image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ defmodule Meadow.Pipeline.Actions.GeneratePosterImage do
alias Meadow.Repo
alias Meadow.Utils.{AWS, Lambda}

import Env

use Meadow.Pipeline.Actions.Common

@timeout 30_000
Expand Down
13 changes: 13 additions & 0 deletions app/test/gql/ReplaceFileSet.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "./FileSetFields.frag.gql"

mutation(
$id: ID!
$coreMetadata: FileSetCoreMetadataInput!
) {
replaceFileSet(
id: $id
coreMetadata: $coreMetadata
) {
...FileSetFields
}
}
57 changes: 57 additions & 0 deletions app/test/meadow_web/schema/mutation/replace_file_set_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
defmodule MeadowWeb.Schema.Mutation.ReplaceFileSetTest do
use Meadow.DataCase
use MeadowWeb.ConnCase, async: true
use Meadow.S3Case
use Wormwood.GQLCase

load_gql(MeadowWeb.Schema, "test/gql/ReplaceFileSet.gql")

@bucket @ingest_bucket
@key "create_file_set_test/file.tif"
@content "test/fixtures/coffee.tif"
@fixture %{bucket: @bucket, key: @key, content: File.read!(@content)}

@tag s3: [@fixture]
test "replaceFileSet mutation updates a FileSet's metadata", _context do
file_set = file_set_fixture()

{:ok, result} =
query_gql(
variables: %{
"id" => file_set.id,
"coreMetadata" => %{
"original_filename" => "file.tif",
"location" => "s3://#{@bucket}/#{@key}"
}
},
context: gql_context()
)

assert result.data["replaceFileSet"]
location = get_in(result, [:data, "replaceFileSet", "coreMetadata", "location"])
assert location == "s3://#{@bucket}/#{@key}"
end

describe "authorization" do
@tag s3: [@fixture]
test "viewers are not authorized to replace file sets" do
file_set = file_set_fixture()


{:ok, result} =
query_gql(
variables: %{
"id" => file_set.id,
"coreMetadata" => %{
"original_filename" => "file.tif",
"location" => "s3://#{@bucket}/#{@key}"
}
},
context: %{current_user: %{role: "User"}}
)


assert %{errors: [%{message: "Forbidden", status: 403}]} = result
end
end
end

0 comments on commit 721c3cf

Please sign in to comment.