Skip to content

Commit

Permalink
Merge pull request #3553 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Deploy v9.0.1 to production
  • Loading branch information
mbklein authored Sep 13, 2023
2 parents caaa85c + 3b16b1e commit a693d86
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 21 deletions.
34 changes: 28 additions & 6 deletions app/assets/js/components/Work/Fileset/ActionButtons/Access.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import React, { useContext } from "react";
import PropTypes from "prop-types";

import { Button } from "@nulib/design-system";
import { IIIFContext } from "@js/components/IIIF/IIIFProvider";
import { IIIF_SIZES } from "@js/services/global-vars";
import { IconDownload } from "@js/components/Icon";
import { ImageDownloader } from "@samvera/image-downloader";
import { useWorkDispatch } from "@js/context/work-context";
import PropTypes from "prop-types";
import { toastWrapper } from "@js/services/helpers";
import useFileSet from "@js/hooks/useFileSet";
import useIsAuthorized from "@js/hooks/useIsAuthorized";
import { useWorkDispatch } from "@js/context/work-context";

function MediaButtons({ fileSet }) {
export function MediaButtons({ fileSet }) {
const { getWebVttString } = useFileSet();
const { isAuthorized } = useIsAuthorized();

const dispatch = useWorkDispatch();
const [downloadStarted, setDownloadStarted] = React.useState(false);

const handleDownloadMedia = () => {
console.log("handleDownloadMedia", handleDownloadMedia);
// TODO: Call the download media endpoint here

toastWrapper(
"is-success",
`Your media download is being prepared. You will receive an email when it is ready.`
);

setDownloadStarted(true);
};

if (!fileSet) return null;

return (
<div className="buttons is-flex is-justify-content-flex-end">
<div className="buttons is-grouped is-right">
{isAuthorized() && (
<Button
onClick={() =>
Expand All @@ -29,11 +46,16 @@ function MediaButtons({ fileSet }) {
Edit structure (vtt)
</Button>
)}
{/* //TODO: Re-enable once backend is ready to support the link *}
{/* <Button onClick={handleDownloadMedia} disabled={downloadStarted}>
<IconDownload />
Download
</Button> */}
</div>
);
}

function ImageButtons({ iiifServerUrl, fileSet }) {
export function ImageButtons({ iiifServerUrl, fileSet }) {
return (
<div className="field has-addons is-flex is-justify-content-flex-end">
<p className="control">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { render, screen } from "@testing-library/react";

import { MediaButtons } from "./Access";
import React from "react";
import { WorkProvider } from "@js/context/work-context";
import { mockUser } from "@js/components/Auth/auth.gql.mock";
import useIsAuthorized from "@js/hooks/useIsAuthorized";

jest.mock("@js/hooks/useIsAuthorized");
useIsAuthorized.mockReturnValue({
user: mockUser,
isAuthorized: () => true,
});

const mockFileSet = {
__typename: "FileSet",
id: "120da9c2-abb3-4492-a62c-e4f0beb2bb6f",
accessionNumber: "Donohue_002_01",
coreMetadata: {
__typename: "FileSetCoreMetadata",
description: "Photo, man with two children",
label: "The label",
location: "s3://testing",
mimeType: "video/x-m4v",
originalFilename: "small.m4v",
digests: {
__typename: "Digests",
md5: "a036e18dad7b0deab383454ec1d32f87",
sha1: null,
sha256: null,
},
},
extractedMetadata: "",
insertedAt: "2023-05-04T20:31:27.097298Z",
role: {
__typename: "CodedTerm",
id: "A",
label: "Access",
},
representativeImageUrl: null,
streamingUrl: "https://testings/120da9c2-abb3-4492-a62c-e4f0beb2bb6f.m4v",
structuralMetadata: {
__typename: "FileSetStructuralMetadata",
type: "WEBVTT",
value:
"WEBVTT - Translation of that film I like\n\nNOTE\nThis translation was done by Kyle so that\nsome friends can watch it with their parents.\n\n1\n00:02:15.000 --> 00:02:20.000\n- Ta en kopp varmt te.\n- Det är inte varmt.\n\n2\n00:02:20.000 --> 00:02:25.000\n- Har en kopp te.\n- Det smakar som te.\n\nNOTE This last line may not translate well.\n\n3\n00:02:25.000 --> 00:02:30.000\n- Ta en kopp",
},
updatedAt: "2023-05-04T20:32:03.571707Z",
};

const initialState = {
activeMediaFileSet: mockFileSet,
webVttModal: {
fileSetId: null,
isOpen: false,
webVttString: "",
},
workType: "VIDEO",
};

describe("MediaButtons", () => {
it("renders the Edit VTT button and Download Video button for a video mime/type Fileset", () => {
render(
<WorkProvider initialState={initialState}>
<MediaButtons fileSet={mockFileSet} />
</WorkProvider>
);

expect(screen.getByText("Edit structure (vtt)")).toBeInTheDocument();
//expect(screen.getByText("Download")).toBeInTheDocument();
});
});
7 changes: 7 additions & 0 deletions app/assets/js/hooks/useFileSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ export default function useFileSet() {
return mimeType.includes("video") || mimeType.includes("audio");
}

function isVideo(fileSet = {}) {
const mimeType = fileSet.coreMetadata?.mimeType?.toLowerCase();
if (!mimeType) return;
return mimeType.includes("video");
}

return {
filterFileSets,
getWebVttString,
isEmpty,
isImage,
isMedia,
isVideo,
};
}
2 changes: 1 addition & 1 deletion app/lib/meadow/ark_listener.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Meadow.ArkListener do
"Updating ARK metadata for work: #{work.id}, with ark: #{work.descriptive_metadata.ark}"
)

case Arks.update_ark_metatdata(work) do
case Arks.update_ark_metadata(work) do
:noop ->
:noop

Expand Down
2 changes: 1 addition & 1 deletion app/lib/meadow/utils/ark_client/mock_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ defmodule Meadow.Utils.ArkClient.MockServer do
defp send_message(message) do
case Cachex.get!(@cache, :send_to) do
nil -> :noop
process -> send(process, message)
process -> send(process, %{message: message, at: NaiveDateTime.utc_now()})
end
end

Expand Down
17 changes: 16 additions & 1 deletion app/lib/meadow/utils/arks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Meadow.Arks do
work |> initial_ark_attributes() |> Ark.from_attrs()
end

def update_ark_metatdata(%Work{} = work) do
def update_ark_metadata(%Work{} = work) do
case existing_ark(work) do
{:error, message} ->
{:error, message}
Expand All @@ -90,6 +90,21 @@ defmodule Meadow.Arks do
:noop
end

defp update_existing_ark(
work,
%{status: "reserved"} = old,
%{status: "unavailable" <> _} = new
) do
Logger.debug(
"#{new.ark} transitioning from reserved to unavailable - must go through public."
)

case update_existing_ark(work, old, %Ark{old | status: "public"}) do
{:ok, intermediate} -> update_existing_ark(work, intermediate, new)
other -> other
end
end

defp update_existing_ark(work, _, ark) do
case Ark.put(ark) do
{:ok, result} ->
Expand Down
2 changes: 1 addition & 1 deletion app/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Code.require_file("lib/env.ex")
defmodule Meadow.MixProject do
use Mix.Project

@app_version "9.0.0"
@app_version "9.0.1"

def project do
[
Expand Down
20 changes: 10 additions & 10 deletions app/test/meadow/ark_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ defmodule Meadow.ArkTest do
Enum.each(@fields, &assert(result |> Map.get(&1) |> is_nil()))
end

assert_received({:post, :credentials, {"mockuser", "mockpassword"}})
assert_received({:post, :body, "_profile: datacite\n_status: reserved"})
assert_received(%{message: {:post, :credentials, {"mockuser", "mockpassword"}}})
assert_received(%{message: {:post, :body, "_profile: datacite\n_status: reserved"}})
end

test "attribute list argument" do
Expand All @@ -73,7 +73,7 @@ defmodule Meadow.ArkTest do
Enum.each(@fields, &assert(Map.get(result, &1) == Keyword.get(source, &1)))
end

assert_received({:post, :credentials, {"mockuser", "mockpassword"}})
assert_received(%{message: {:post, :credentials, {"mockuser", "mockpassword"}}})

expected =
[
Expand All @@ -83,7 +83,7 @@ defmodule Meadow.ArkTest do
]
|> Enum.join("\n")

assert_received({:post, :body, ^expected})
assert_received(%{message: {:post, :body, ^expected}})
end

test "map argument" do
Expand All @@ -94,7 +94,7 @@ defmodule Meadow.ArkTest do
Enum.each(@fields, &assert(Map.get(result, &1) == Map.get(source, &1)))
end

assert_received({:post, :credentials, {"mockuser", "mockpassword"}})
assert_received(%{message: {:post, :credentials, {"mockuser", "mockpassword"}}})

expected =
[
Expand All @@ -104,7 +104,7 @@ defmodule Meadow.ArkTest do
]
|> Enum.join("\n")

assert_received({:post, :body, ^expected})
assert_received(%{message: {:post, :body, ^expected}})
end

test "Meadow.Ark argument" do
Expand All @@ -115,7 +115,7 @@ defmodule Meadow.ArkTest do
Enum.each(@fields, &assert(Map.get(result, &1) == Map.get(source, &1)))
end

assert_received({:post, :credentials, {"mockuser", "mockpassword"}})
assert_received(%{message: {:post, :credentials, {"mockuser", "mockpassword"}}})

expected =
[
Expand All @@ -125,7 +125,7 @@ defmodule Meadow.ArkTest do
]
|> Enum.join("\n")

assert_received({:post, :body, ^expected})
assert_received(%{message: {:post, :body, ^expected}})
end
end

Expand Down Expand Up @@ -169,7 +169,7 @@ defmodule Meadow.ArkTest do
update = Map.put(fixture, :title, "A 100% New Title for This ARK!")
assert {:ok, update} == Ark.put(update)
assert {:ok, update} == Ark.get(fixture.ark)
assert_received({:post, :credentials, {"mockuser", "mockpassword"}})
assert_received(%{message: {:post, :credentials, {"mockuser", "mockpassword"}}})

expected =
[
Expand All @@ -181,7 +181,7 @@ defmodule Meadow.ArkTest do
]
|> Enum.join("\n")

assert_received({:post, :body, ^expected})
assert_received(%{message: {:post, :body, ^expected}})
end

test "invalid ARK" do
Expand Down
54 changes: 53 additions & 1 deletion app/test/meadow/arks_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
defmodule Meadow.ArksTest do
use Meadow.DataCase

alias Meadow.Arks
alias Meadow.{Ark, Arks}
alias Meadow.Data.Works
alias Meadow.Utils.ArkClient.MockServer

describe "mint_ark/1" do
setup %{work_type: work_type} do
Expand All @@ -22,4 +24,54 @@ defmodule Meadow.ArksTest do
end
end)
end

describe "update_ark_metadata/1" do
setup do
MockServer.send_to(self())
end

setup %{visibility: visibility} do
with work <-
work_fixture(%{
published: false,
visibility: %{id: visibility, scheme: "visibility"}
})
|> Arks.mint_ark!() do
{:ok, work: work}
end
end

@tag visibility: "OPEN"
test "correctly transitions from reserved to public when published", %{work: work} do
assert {:ok, %Ark{status: "reserved"}} = Arks.existing_ark(work)

work
|> Works.update_work!(%{published: true})
|> Arks.update_ark_metadata()

assert {:ok, %Ark{status: "public"}} = Arks.existing_ark(work)
end

@tag visibility: "RESTRICTED"
test "correctly transitions from reserved to unavailable when published", %{work: work} do
assert_received(%{message: {:post, :body, anvl}, at: reserved_time})
assert String.contains?(anvl, "_status: reserved")
assert {:ok, %Ark{status: "reserved"}} = Arks.existing_ark(work)

work
|> Works.update_work!(%{published: true})
|> Arks.update_ark_metadata()

assert_received(%{message: {:post, :body, anvl}, at: public_time})
assert String.contains?(anvl, "_status: public")

assert_received(%{message: {:post, :body, anvl}, at: unavailable_time})
assert String.contains?(anvl, "_status: unavailable | restricted")

assert reserved_time < public_time
assert public_time < unavailable_time

assert {:ok, %Ark{status: "unavailable | restricted"}} = Arks.existing_ark(work)
end
end
end

0 comments on commit a693d86

Please sign in to comment.