Skip to content

Commit

Permalink
Fixup factory initialization ep uploaded state
Browse files Browse the repository at this point in the history
  • Loading branch information
svevang committed Nov 26, 2024
1 parent 77a9750 commit ab2a038
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
21 changes: 16 additions & 5 deletions test/factories/apple_episode_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
factory :uploaded_apple_episode do
feeder_episode do
ep = create(:episode)
ep.apple_mark_as_delivered!
ep
end
transient do
Expand All @@ -36,11 +35,23 @@
api_marked_as_uploaded: true,
upload_operations_complete: true)

create(:content, episode: apple_episode.feeder_episode, position: 1, status: "complete")
create(:content, episode: apple_episode.feeder_episode, position: 2, status: "complete")
v1 = apple_episode.feeder_episode.cut_media_version!
feeder_episode = apple_episode.feeder_episode

apple_episode.delivery_status.update!(delivered: true, source_media_version_id: v1.id)
# The content model calls Episode#publish!
# and that triggers a call to Episode#apple_mark_for_reupload!
# This modifies state to indicate that the episode needs to be reuploaded
create(:content, episode: feeder_episode, position: 1, status: "complete")
create(:content, episode: feeder_episode, position: 2, status: "complete")
v1 = feeder_episode.cut_media_version!

# Now model the case where the episode is uploaded.
# First we've gathered file metadata from the CDN
feeder_episode.apple_update_delivery_status(source_size: 1.megabyte,
source_url: "https://cdn.example.com/episode.mp3",
source_media_version_id: v1.id)

# Then we've uploaded as delivered (and necessarily uploaded)
feeder_episode.apple_mark_as_delivered!
end
end

Expand Down
14 changes: 9 additions & 5 deletions test/models/apple/publisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@
end

describe "#increment_asset_wait!" do
let(:episode1) { build(:uploaded_apple_episode, show: apple_publisher.show) }
let(:episode2) { build(:uploaded_apple_episode, show: apple_publisher.show) }
let(:episode1) { build(:apple_episode, show: apple_publisher.show) }
let(:episode2) { build(:apple_episode, show: apple_publisher.show) }
let(:episodes) { [episode1, episode2] }

it "should increment asset wait count for each episode" do
Expand Down Expand Up @@ -527,19 +527,21 @@
end

describe "#mark_as_uploaded!" do
let(:episode1) { build(:uploaded_apple_episode, show: apple_publisher.show) }
let(:episode2) { build(:uploaded_apple_episode, show: apple_publisher.show) }
let(:episode1) { build(:apple_episode, show: apple_publisher.show) }
let(:episode2) { build(:apple_episode, show: apple_publisher.show) }
let(:episodes) { [episode1, episode2] }

it "marks episodes as uploaded" do
episodes.each do |ep|
refute ep.delivery_status.uploaded
refute ep.delivery_status.delivered
end

apple_publisher.mark_as_uploaded!(episodes)

episodes.each do |ep|
assert ep.delivery_status.uploaded
refute ep.delivery_status.delivered
end
end
end
Expand All @@ -551,12 +553,14 @@

it "marks episodes as delivered" do
episodes.each do |ep|
refute ep.delivery_status.uploaded
refute ep.delivery_status.delivered
end

apple_publisher.mark_as_delivered!(episodes)

episodes.each do |ep|
assert ep.delivery_status.uploaded
assert ep.delivery_status.delivered
end
end
Expand All @@ -580,7 +584,7 @@
end

describe "#deliver_and_publish!" do
let(:episode) { build(:uploaded_apple_episode, show: apple_publisher.show) }
let(:episode) { build(:apple_episode, show: apple_publisher.show) }

it "skips upload for already uploaded episodes" do
episode.feeder_episode.apple_mark_as_uploaded!
Expand Down

0 comments on commit ab2a038

Please sign in to comment.