-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require "test_helper" | ||
|
||
class AppleDeliveryTest < ActiveSupport::TestCase | ||
let(:episode) { create(:episode_with_media) } | ||
|
||
describe "#apple_episode" do | ||
let(:episode) { create(:episode) } | ||
it "gets nil for no apple episode" do | ||
assert_nil episode.apple_episode | ||
end | ||
end | ||
|
||
describe "#apple_needs_delivery?" do | ||
let(:episode) { create(:episode) } | ||
it "is true by default" do | ||
refute episode.apple_episode_delivery_status.persisted? | ||
assert episode.apple_needs_delivery? | ||
end | ||
|
||
it "can be set to false" do | ||
episode.apple_has_delivery! | ||
refute episode.apple_needs_delivery? | ||
end | ||
|
||
it "can be set to true" do | ||
episode.apple_has_delivery! | ||
refute episode.apple_needs_delivery? | ||
|
||
# now set it to true | ||
episode.apple_needs_delivery! | ||
assert episode.apple_needs_delivery? | ||
end | ||
end | ||
|
||
describe "#increment_asset_wait" do | ||
let(:episode) { create(:episode) } | ||
|
||
it "creates a new status with incremented asset_processing_attempts" do | ||
assert_difference -> { episode.apple_episode_delivery_statuses.count }, 1 do | ||
new_status = episode.apple_status.increment_asset_wait | ||
assert_equal 1, new_status.asset_processing_attempts | ||
end | ||
end | ||
|
||
it "increments existing asset_processing_attempts" do | ||
create(:apple_episode_delivery_status, episode: episode, asset_processing_attempts: 2) | ||
new_status = episode.apple_status.increment_asset_wait | ||
assert_equal 3, new_status.asset_processing_attempts | ||
end | ||
|
||
it "maintains other attributes when incrementing" do | ||
create(:apple_episode_delivery_status, | ||
episode: episode, | ||
delivered: true, | ||
source_url: "http://example.com/audio.mp3", | ||
asset_processing_attempts: 1) | ||
|
||
new_status = episode.apple_status.increment_asset_wait | ||
assert_equal 2, new_status.asset_processing_attempts | ||
assert new_status.delivered | ||
assert_equal "http://example.com/audio.mp3", new_status.source_url | ||
end | ||
|
||
it "creates a new status with asset_processing_attempts set to 1 if no previous status exists" do | ||
episode.apple_episode_delivery_statuses.destroy_all | ||
assert_difference -> { episode.apple_episode_delivery_statuses.count }, 1 do | ||
new_status = episode.apple_status.increment_asset_wait | ||
assert_equal 1, new_status.asset_processing_attempts | ||
end | ||
end | ||
|
||
it "returns the new status" do | ||
result = episode.apple_status.increment_asset_wait | ||
assert_instance_of Apple::EpisodeDeliveryStatus, result | ||
assert_equal episode.apple_episode_delivery_statuses.last, result | ||
end | ||
end | ||
end |