Skip to content

Commit

Permalink
Merge pull request #1015 from PRX/fix/update_apple_drafting
Browse files Browse the repository at this point in the history
Update episodes still drafting in Apple
  • Loading branch information
kookster committed May 7, 2024
2 parents d3a83e2 + 7c6b8f8 commit 6a6fcbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/models/apple/publisher.rb
Expand Up @@ -252,14 +252,20 @@ def sync_episodes!(eps)
poll_episodes!(eps)

create_apple_episodes = eps.select(&:apple_new?)
# NOTE: We don't attempt to update the remote state of episodes. Once
# apple has parsed the feed, it will not allow changing any attributes.
Apple::Episode.create_episodes(api, create_apple_episodes)
Rails.logger.info("Created remote episodes", {count: create_apple_episodes.length})

# NOTE: We don't attempt to update the remote state of published episodes.
# Once apple has parsed the feed, it will not allow changing any attributes.
#
# It's assumed that the episodes are created solely by the PRX web UI (not
# on Podcasts Connect).
Apple::Episode.create_episodes(api, create_apple_episodes)

Rails.logger.info("Created remote episodes", {count: create_apple_episodes.length})
# However, if the episode is drafting state,
# then we can try to update the episode attributes
draft_apple_episodes = eps.select(&:drafting?)
Apple::Episode.update_episodes(api, draft_apple_episodes)
Rails.logger.info("Updated remote episodes", {count: draft_apple_episodes.length})

show.reload
end
Expand All @@ -275,7 +281,7 @@ def poll_podcast_containers!(eps)
def sync_podcast_containers!(eps)
Rails.logger.tagged("##{__method__}") do
# TODO: right now we only create one delivery per container,
# Apple RSS scaping means we don't need deliveries for freemium episode images
# Apple RSS scraping means we don't need deliveries for freemium episode images
# But we do need asset deliveries for apple-only (non-rss) images

Rails.logger.info("Starting podcast container sync")
Expand Down
24 changes: 24 additions & 0 deletions test/models/apple/publisher_test.rb
Expand Up @@ -96,6 +96,30 @@
end
end

describe "#sync_episodes!" do
it "should create new episodes" do
apple_publisher.stub(:poll_episodes!, []) do
new_ep = OpenStruct.new(drafting?: false, apple_new?: true)
mock = Minitest::Mock.new
mock.expect(:call, [], [apple_publisher.api, [new_ep]])
Apple::Episode.stub(:create_episodes, mock) do
apple_publisher.sync_episodes!([new_ep])
end
end
end

it "should update draft episodes" do
apple_publisher.stub(:poll_episodes!, []) do
draft_ep = OpenStruct.new(drafting?: true, apple_new?: false)
mock = Minitest::Mock.new
mock.expect(:call, [], [apple_publisher.api, [draft_ep]])
Apple::Episode.stub(:update_episodes, mock) do
apple_publisher.sync_episodes!([draft_ep])
end
end
end
end

describe "Archive and Unarchive flows" do
let(:podcast) { create(:podcast) }
let(:public_feed) { podcast.default_feed }
Expand Down

0 comments on commit 6a6fcbd

Please sign in to comment.