diff --git a/app/models/apple/podcast_delivery_file.rb b/app/models/apple/podcast_delivery_file.rb index 76c6606de..03cb535cf 100644 --- a/app/models/apple/podcast_delivery_file.rb +++ b/app/models/apple/podcast_delivery_file.rb @@ -31,7 +31,7 @@ class PodcastDeliveryFile < ApplicationRecord end end - # Apple: AppMediaAssetState + # Apple: DeliveryState delivery_state = %W[AWAITING_UPLOAD UPLOAD_COMPLETE COMPLETE FAILED].freeze delivery_state.map do |state| define_method("delivery_#{state.downcase}?") do @@ -98,17 +98,14 @@ def self.mark_uploaded(api, pdfs) episode_bridge_results end + def self.select_podcast_deliveries(episodes) + episodes.map(&:podcast_deliveries).flatten + end + def self.create_podcast_delivery_files(api, episodes) return [] if episodes.empty? - podcast_containers = episodes.map(&:podcast_container) - podcast_deliveries = podcast_containers.map do |pc| - raise("Missing podcast deliveries") if pc.podcast_deliveries.empty? - - pc.podcast_deliveries - end - - podcast_deliveries = podcast_deliveries.flatten + podcast_deliveries = select_podcast_deliveries(episodes) # filter for only the podcast deliveries that have missing podcast delivery files # podcast_delivery_files are soft deleted in rails when they are replaced diff --git a/test/models/apple/podcast_delivery_file_test.rb b/test/models/apple/podcast_delivery_file_test.rb index 2bcc9a52d..720d119a4 100644 --- a/test/models/apple/podcast_delivery_file_test.rb +++ b/test/models/apple/podcast_delivery_file_test.rb @@ -1,6 +1,21 @@ require "test_helper" class ApplePodcastDeliveryFileTest < ActiveSupport::TestCase + describe ".select_podcast_delivery_files" do + it "should return the apple_podcast_deliveries from the episodes" do + ep1 = OpenStruct.new(podcast_deliveries: [1, 2]) + ep2 = OpenStruct.new(podcast_deliveries: [3]) + ep3 = OpenStruct.new(podcast_deliveries: []) + + assert_equal [1, 2, 3], Apple::PodcastDeliveryFile.select_podcast_deliveries([ep1, ep2, ep3]) + end + + it "Operates on an array of Apple::Episodes" do + ep1 = build(:apple_episode) + assert_equal [], Apple::PodcastDeliveryFile.select_podcast_deliveries([ep1]) + end + end + describe ".get_delivery_file_bridge_params" do it "should format a single bridge param row" do assert_equal({