Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[elixir] bug: allow empty datasets to be passed into dmap feed update #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -63,6 +63,10 @@ defmodule ExCubicIngestion.Schema.CubicDmapFeed do
Finds the dataset that was last updated and updates the feed's last updated value
"""
@spec update_last_updated_from_datasets([CubicDmapDataset.t()], t()) :: t()
def update_last_updated_from_datasets([], rec) do
rec
end

def update_last_updated_from_datasets(dataset_recs, rec) do
latest_updated_dataset_rec = Enum.max_by(dataset_recs, & &1.last_updated_at, DateTime)

Expand Down
Expand Up @@ -36,6 +36,20 @@ defmodule ExCubicIngestion.Schema.CubicDmapFeedTest do
end

describe "update_last_updated_for_feed/2" do
test "no updates are made for empty list of datasets" do
dmap_feed =
Repo.insert!(%CubicDmapFeed{
relative_url: "/controlledresearchusersapi/sample",
last_updated_at: ~U[2022-05-16 20:49:50.123456Z]
})

assert ~U[2022-05-16 20:49:50.123456Z] ==
CubicDmapFeed.update_last_updated_from_datasets(
[],
dmap_feed
).last_updated_at
end

test "update with the latest updated dataset" do
dmap_feed =
Repo.insert!(%CubicDmapFeed{
Expand Down