|
398 | 398 | end |
399 | 399 | end |
400 | 400 |
|
| 401 | + describe "#verify_publishing_state!" do |
| 402 | + let(:episode1) { build(:uploaded_apple_episode, show: apple_publisher.show, api_response: build(:apple_episode_api_response, publishing_state: "DRAFTING")) } |
| 403 | + let(:episode2) { build(:uploaded_apple_episode, show: apple_publisher.show, api_response: build(:apple_episode_api_response, publishing_state: "DRAFTING")) } |
| 404 | + let(:episodes) { [episode1, episode2] } |
| 405 | + |
| 406 | + it "should not raise error when episodes remain in same state" do |
| 407 | + apple_publisher.stub(:poll_episodes!, nil) do |
| 408 | + result = apple_publisher.verify_publishing_state!(episodes) |
| 409 | + assert result == true |
| 410 | + end |
| 411 | + end |
| 412 | + |
| 413 | + it "should raise RetryPublishingError when state drift is detected" do |
| 414 | + # Simulate state change during poll - episode1 starts DRAFTING but becomes PUBLISHED after poll |
| 415 | + apple_publisher.stub(:poll_episodes!, proc { |
| 416 | + episode1.api_response["api_response"]["val"]["data"]["attributes"]["publishingState"] = "PUBLISHED" |
| 417 | + }) do |
| 418 | + error = assert_raises(Apple::RetryPublishingError) do |
| 419 | + apple_publisher.verify_publishing_state!(episodes) |
| 420 | + end |
| 421 | + assert_match(/Detected 1 episodes with publishing state drift/, error.message) |
| 422 | + end |
| 423 | + end |
| 424 | + |
| 425 | + it "should detect drift and raise error even with non-DRAFTING episodes" do |
| 426 | + # episode1 starts in PUBLISHED state, then drifts to ARCHIVED |
| 427 | + episode1.api_response["api_response"]["val"]["data"]["attributes"]["publishingState"] = "PUBLISHED" |
| 428 | + |
| 429 | + apple_publisher.stub(:poll_episodes!, proc { |
| 430 | + episode1.api_response["api_response"]["val"]["data"]["attributes"]["publishingState"] = "ARCHIVED" |
| 431 | + }) do |
| 432 | + error = assert_raises(Apple::RetryPublishingError) do |
| 433 | + apple_publisher.verify_publishing_state!(episodes) |
| 434 | + end |
| 435 | + assert_match(/Detected 1 episodes with publishing state drift/, error.message) |
| 436 | + end |
| 437 | + end |
| 438 | + |
| 439 | + it "should raise error with count when multiple episodes drift" do |
| 440 | + apple_publisher.stub(:poll_episodes!, proc { |
| 441 | + episode1.api_response["api_response"]["val"]["data"]["attributes"]["publishingState"] = "PUBLISHED" |
| 442 | + episode2.api_response["api_response"]["val"]["data"]["attributes"]["publishingState"] = "ARCHIVED" |
| 443 | + }) do |
| 444 | + error = assert_raises(Apple::RetryPublishingError) do |
| 445 | + apple_publisher.verify_publishing_state!(episodes) |
| 446 | + end |
| 447 | + assert_match(/Detected 2 episodes with publishing state drift/, error.message) |
| 448 | + end |
| 449 | + end |
| 450 | + end |
| 451 | + |
401 | 452 | describe "#publish_drafting!" do |
402 | 453 | let(:episode1) { build(:uploaded_apple_episode, show: apple_publisher.show, api_response: build(:apple_episode_api_response, publishing_state: "DRAFTING")) } |
403 | 454 | let(:episode2) { build(:uploaded_apple_episode, show: apple_publisher.show, api_response: build(:apple_episode_api_response, publishing_state: "DRAFTING")) } |
|
407 | 458 | mock = Minitest::Mock.new |
408 | 459 | mock.expect(:call, [], [Apple::Api, Apple::Show, episodes]) |
409 | 460 |
|
410 | | - Apple::Episode.stub(:publish, mock) do |
411 | | - apple_publisher.publish_drafting!(episodes) |
| 461 | + apple_publisher.stub(:verify_publishing_state!, nil) do |
| 462 | + Apple::Episode.stub(:publish, mock) do |
| 463 | + apple_publisher.publish_drafting!(episodes) |
| 464 | + end |
412 | 465 | end |
413 | 466 |
|
414 | 467 | assert mock.verify |
|
656 | 709 |
|
657 | 710 | apple_publisher.stub(:upload_media!, upload_mock) do |
658 | 711 | apple_publisher.stub(:process_delivery!, ->(*) {}) do |
659 | | - apple_publisher.upload_and_process!([episode]) |
| 712 | + apple_publisher.stub(:verify_publishing_state!, nil) do |
| 713 | + apple_publisher.upload_and_process!([episode]) |
| 714 | + end |
660 | 715 | end |
661 | 716 | end |
662 | 717 |
|
|
670 | 725 | mock.expect(:call, nil, [[episode]]) |
671 | 726 | apple_publisher.stub(:upload_media!, mock) do |
672 | 727 | apple_publisher.stub(:process_delivery!, ->(*) {}) do |
673 | | - apple_publisher.upload_and_process!([episode]) |
| 728 | + apple_publisher.stub(:verify_publishing_state!, nil) do |
| 729 | + apple_publisher.upload_and_process!([episode]) |
| 730 | + end |
674 | 731 | end |
675 | 732 | end |
676 | 733 |
|
|
815 | 872 | apple_publisher.stub(:increment_asset_wait!, increment_mock) do |
816 | 873 | apple_publisher.stub(:wait_for_upload_processing, wait_upload_mock) do |
817 | 874 | apple_publisher.stub(:wait_for_asset_state, wait_for_asset_state_stub) do |
818 | | - Apple::Episode.stub(:probe_asset_state, probe_mock) do |
819 | | - apple_publisher.stub(:mark_as_delivered!, mark_delivered_mock) do |
820 | | - apple_publisher.process_delivery!([episode]) |
| 875 | + apple_publisher.stub(:verify_publishing_state!, ->(*) {}) do |
| 876 | + Apple::Episode.stub(:probe_asset_state, probe_mock) do |
| 877 | + apple_publisher.stub(:mark_as_delivered!, mark_delivered_mock) do |
| 878 | + apple_publisher.process_delivery!([episode]) |
| 879 | + end |
821 | 880 | end |
822 | 881 | end |
823 | 882 | end |
|
896 | 955 | apple_publisher.stub(:wait_for_upload_processing, ->(*) {}) do |
897 | 956 | apple_publisher.stub(:wait_for_asset_state, wait_for_asset_state_stub) do |
898 | 957 | apple_publisher.stub(:check_for_stuck_episodes, ->(*) {}) do |
899 | | - Apple::Episode.stub(:probe_asset_state, probe_mock) do |
900 | | - apple_publisher.stub(:mark_as_delivered!, ->(*) {}) do |
901 | | - apple_publisher.stub(:log_asset_wait_duration!, ->(*) {}) do |
902 | | - apple_publisher.process_delivery!([episode]) |
| 958 | + apple_publisher.stub(:verify_publishing_state!, ->(*) {}) do |
| 959 | + Apple::Episode.stub(:probe_asset_state, probe_mock) do |
| 960 | + apple_publisher.stub(:mark_as_delivered!, ->(*) {}) do |
| 961 | + apple_publisher.stub(:log_asset_wait_duration!, ->(*) {}) do |
| 962 | + apple_publisher.process_delivery!([episode]) |
| 963 | + end |
903 | 964 | end |
904 | 965 | end |
905 | 966 | end |
|
938 | 999 | apple_publisher.stub(:increment_asset_wait!, ->(*) {}) do |
939 | 1000 | apple_publisher.stub(:wait_for_upload_processing, ->(*) {}) do |
940 | 1001 | apple_publisher.stub(:wait_for_asset_state, wait_for_asset_state_stub) do |
941 | | - Apple::Episode.stub(:probe_asset_state, probe_mock) do |
942 | | - apple_publisher.stub(:mark_as_delivered!, ->(*) {}) do |
943 | | - apple_publisher.stub(:log_asset_wait_duration!, ->(*) {}) do |
944 | | - apple_publisher.process_delivery!(episodes) |
| 1002 | + apple_publisher.stub(:verify_publishing_state!, ->(*) {}) do |
| 1003 | + Apple::Episode.stub(:probe_asset_state, probe_mock) do |
| 1004 | + apple_publisher.stub(:mark_as_delivered!, ->(*) {}) do |
| 1005 | + apple_publisher.stub(:log_asset_wait_duration!, ->(*) {}) do |
| 1006 | + apple_publisher.process_delivery!(episodes) |
| 1007 | + end |
945 | 1008 | end |
946 | 1009 | end |
947 | 1010 | end |
|
996 | 1059 | apple_publisher.stub(:wait_for_upload_processing, ->(*) {}) do |
997 | 1060 | apple_publisher.stub(:wait_for_asset_state, wait_for_asset_state_stub) do |
998 | 1061 | apple_publisher.stub(:check_for_stuck_episodes, ->(*) {}) do |
999 | | - Apple::Episode.stub(:probe_asset_state, probe_mock) do |
1000 | | - apple_publisher.stub(:mark_as_delivered!, mark_delivered_mock) do |
1001 | | - apple_publisher.process_delivery!([episode1, episode2, episode3]) |
| 1062 | + apple_publisher.stub(:verify_publishing_state!, ->(*) {}) do |
| 1063 | + Apple::Episode.stub(:probe_asset_state, probe_mock) do |
| 1064 | + apple_publisher.stub(:mark_as_delivered!, mark_delivered_mock) do |
| 1065 | + apple_publisher.process_delivery!([episode1, episode2, episode3]) |
| 1066 | + end |
1002 | 1067 | end |
1003 | 1068 | end |
1004 | 1069 | end |
|
1047 | 1112 | apple_publisher.stub(:wait_for_upload_processing, ->(*) {}) do |
1048 | 1113 | apple_publisher.stub(:wait_for_asset_state, wait_for_asset_state_stub) do |
1049 | 1114 | apple_publisher.stub(:check_for_stuck_episodes, ->(*) {}) do |
1050 | | - Apple::Episode.stub(:probe_asset_state, probe_mock) do |
1051 | | - apple_publisher.stub(:mark_as_delivered!, mark_delivered_mock) do |
1052 | | - apple_publisher.stub(:log_asset_wait_duration!, ->(*) {}) do |
1053 | | - # Should raise timeout error when timeout is reached |
1054 | | - error = assert_raises(Apple::AssetStateTimeoutError) do |
1055 | | - apple_publisher.process_delivery!([episode1, episode2]) |
| 1115 | + apple_publisher.stub(:verify_publishing_state!, ->(*) {}) do |
| 1116 | + Apple::Episode.stub(:probe_asset_state, probe_mock) do |
| 1117 | + apple_publisher.stub(:mark_as_delivered!, mark_delivered_mock) do |
| 1118 | + apple_publisher.stub(:log_asset_wait_duration!, ->(*) {}) do |
| 1119 | + # Should raise timeout error when timeout is reached |
| 1120 | + error = assert_raises(Apple::AssetStateTimeoutError) do |
| 1121 | + apple_publisher.process_delivery!([episode1, episode2]) |
| 1122 | + end |
| 1123 | + |
| 1124 | + assert_equal 2, error.episodes.length, "Error should contain both episodes" |
1056 | 1125 | end |
1057 | | - |
1058 | | - assert_equal 2, error.episodes.length, "Error should contain both episodes" |
1059 | 1126 | end |
1060 | 1127 | end |
1061 | 1128 | end |
|
0 commit comments