-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
app/test/meadow_web/schema/mutation/replace_file_set_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |