Skip to content

Commit

Permalink
Merge pull request #789 from PRX/fix-no-delivery-files-if-no-delivery
Browse files Browse the repository at this point in the history
Fix: no delivery files are expected if there is no delivery
  • Loading branch information
svevang authored Aug 18, 2023
2 parents e9a81b5 + 675c427 commit b5b410b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 6 additions & 9 deletions app/models/apple/podcast_delivery_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/models/apple/podcast_delivery_file_test.rb
Original file line number Diff line number Diff line change
@@ -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({
Expand Down

0 comments on commit b5b410b

Please sign in to comment.