Skip to content

Commit

Permalink
The empty set of delivery files is settled
Browse files Browse the repository at this point in the history
  • Loading branch information
svevang committed Aug 3, 2023
1 parent a50e7ff commit 30ddd1f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
13 changes: 6 additions & 7 deletions app/models/apple/podcast_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def missing_podcast_audio?
end

def delivered?
return false if podcast_delivery_files.length == 0
# because we cannot infer if the podcast delivery files have expired
return true if podcast_delivery_files.length == 0

(podcast_delivery_files.all?(&:delivered?) &&
podcast_delivery_files.all?(&:processed?))
Expand All @@ -262,15 +263,9 @@ def processed_errors?
end

def delivery_settled?
return false if podcast_delivery_files.length == 0

delivered? && !processed_errors?
end

def skip_delivery?
container_upload_satisfied?
end

def container_upload_satisfied?
# Sets us up for a retry if something prevented the audio from being
# marked as uploaded and then processed and validated. Assuming that we
Expand All @@ -279,6 +274,10 @@ def container_upload_satisfied?
has_podcast_audio? && delivery_settled?
end

def skip_delivery?
container_upload_satisfied?
end

def needs_delivery?
!skip_delivery?
end
Expand Down
4 changes: 2 additions & 2 deletions test/models/apple/episode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
assert_equal true, apple_episode.waiting_for_asset_state?
end

it "should be false if there are no podcast delivery files" do
it "should be true if there are no podcast delivery files and the asset state is UNSPECIFIED" do
apple_episode.podcast_container.stub(:podcast_delivery_files, []) do
assert_equal false, apple_episode.waiting_for_asset_state?
assert_equal true, apple_episode.waiting_for_asset_state?
end
end

Expand Down
25 changes: 25 additions & 0 deletions test/models/apple/podcast_container_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,31 @@ class Apple::PodcastContainerTest < ActiveSupport::TestCase
end
end

describe "retry sentinals and gatekeeping" do
let(:container) { Apple::PodcastContainer.new }
describe "#delivery_settled?" do
it "should be settled if there are no delivery files" do
container.stub(:podcast_delivery_files, []) do
assert container.delivery_settled?
assert container.delivered?
end
end
end

describe "#container_upload_satisfied?" do
it "should be satisfied with podcast files and a settled delivery" do
container.stub(:files, [
{status: Apple::PodcastContainer::FILE_STATUS_SUCCESS,
assetRole: Apple::PodcastContainer::FILE_ASSET_ROLE_PODCAST_AUDIO}.with_indifferent_access
]) do
container.stub(:podcast_delivery_files, []) do
assert container.container_upload_satisfied?
end
end
end
end
end

describe "#destroy" do
it "should destroy the podcast container and cascade to the delivery and delivery file" do
apple_episode.stub(:apple_id, apple_episode_id) do
Expand Down

0 comments on commit 30ddd1f

Please sign in to comment.