Skip to content

Commit

Permalink
[spaceship] validate the status of app version to be ready_for_review…
Browse files Browse the repository at this point in the history
… before submitting the app (#20515)

* validate the status of app version to be ready_for_review before submitting the app

* only retries at most 10 times
  • Loading branch information
404pilot committed Sep 7, 2023
1 parent 6627c28 commit 871eb67
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions deliver/lib/deliver/submit_for_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ def create_review_submission(options, app, version, platform)
end

submission.add_app_store_version_to_review_items(app_store_version_id: version.id)

10.times do
version_with_latest_info = Spaceship::ConnectAPI::AppStoreVersion.get(app_store_version_id: version.id)

if version_with_latest_info.app_store_state == Spaceship::ConnectAPI::AppStoreVersion::AppStoreState::READY_FOR_REVIEW
break
end

UI.message("Waiting for the state of the version to become #{Spaceship::ConnectAPI::AppStoreVersion::AppStoreState::READY_FOR_REVIEW}...")

sleep(15)
end

submission.submit_for_review
end

Expand Down
47 changes: 47 additions & 0 deletions deliver/spec/submit_for_review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
id: '1',
version_string: "1.0.0")
end
let(:ready_for_review_version) do
double('ready_for_review_version',
id: '1',
app_store_state: "READY_FOR_REVIEW",
version_string: "1.0.0")
end
let(:prepare_for_submission_version) do
double('prepare_for_submission_version',
id: '1',
app_store_state: "PREPARE_FOR_SUBMISSION",
version_string: "1.0.0")
end
let(:selected_build) { double('selected_build') }
let(:idfa_declaration) { double('idfa_declaration') }

Expand Down Expand Up @@ -118,6 +130,7 @@
expect(app).not_to receive(:create_review_submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down Expand Up @@ -146,6 +159,34 @@
end
end

context 'it still tries to submit for review if the version state is not expected' do
it 'retires to get the version state at most 10 times' do
options = {
platform: Spaceship::ConnectAPI::Platform::IOS
}

expect(app).to receive(:get_edit_app_store_version).and_return(edit_version)
expect(review_submitter).to receive(:select_build).and_return(selected_build)

expect(selected_build).to receive(:uses_non_exempt_encryption).and_return(false)

expect(edit_version).to receive(:fetch_idfa_declaration).and_return(nil)
expect(edit_version).to receive(:uses_idfa).and_return(false)

expect(app).to receive(:get_in_progress_review_submission).and_return(nil)
expect(app).to receive(:get_ready_review_submission).and_return(submission)
expect(submission).to receive(:items).and_return([])
expect(app).not_to receive(:create_review_submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
allow_any_instance_of(Deliver::SubmitForReview).to receive(:sleep)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).exactly(10).times.and_return(prepare_for_submission_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
end
end

context 'export_compliance_uses_encryption' do
it 'sets to false' do
options = {
Expand All @@ -170,6 +211,7 @@
expect(app).to receive(:create_review_submission).and_return(submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down Expand Up @@ -202,6 +244,7 @@
expect(app).to receive(:create_review_submission).and_return(submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down Expand Up @@ -231,6 +274,7 @@
expect(app).to receive(:create_review_submission).and_return(submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down Expand Up @@ -259,6 +303,7 @@
expect(app).to receive(:create_review_submission).and_return(submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down Expand Up @@ -298,6 +343,7 @@
expect(app).to receive(:create_review_submission).and_return(submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down Expand Up @@ -337,6 +383,7 @@
expect(app).to receive(:create_review_submission).and_return(submission)

expect(submission).to receive(:add_app_store_version_to_review_items).with(app_store_version_id: edit_version.id)
expect(Spaceship::ConnectAPI::AppStoreVersion).to receive(:get).and_return(ready_for_review_version)
expect(submission).to receive(:submit_for_review)

review_submitter.submit!(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AppStoreVersion

module AppStoreState
READY_FOR_SALE = "READY_FOR_SALE"
READY_FOR_REVIEW = "READY_FOR_REVIEW"
PROCESSING_FOR_APP_STORE = "PROCESSING_FOR_APP_STORE"
PENDING_DEVELOPER_RELEASE = "PENDING_DEVELOPER_RELEASE"
PENDING_APPLE_RELEASE = "PENDING_APPLE_RELEASE"
Expand Down

0 comments on commit 871eb67

Please sign in to comment.