-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
208 additions
and
21 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
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,164 @@ | ||
describe Fastlane::Actions::AsanaFindReleaseTaskAction do | ||
describe "#run" do | ||
describe "when it finds the release task" do | ||
it "returns release task ID, URL and release branch" do | ||
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:find_latest_marketing_version).and_return("1.0.0") | ||
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:find_release_task).and_return("1234567890") | ||
allow(Fastlane::UI).to receive(:success) | ||
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output) | ||
|
||
expect(test_action("ios")).to eq({ | ||
release_task_id: "1234567890", | ||
release_task_url: "https://app.asana.com/0/0/1234567890/f", | ||
release_branch: "release/1.0.0" | ||
}) | ||
|
||
expect(Fastlane::UI).to have_received(:success).with("Found 1.0.0 release task: https://app.asana.com/0/0/1234567890/f") | ||
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_branch", "release/1.0.0") | ||
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_task_id", "1234567890") | ||
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("release_task_url", "https://app.asana.com/0/0/1234567890/f") | ||
end | ||
end | ||
|
||
def test_action(platform) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.run(platform: platform) | ||
end | ||
end | ||
|
||
describe "#find_latest_marketing_version" do | ||
it "returns the latest marketing version" do | ||
client = double | ||
allow(Octokit::Client).to receive(:new).and_return(client) | ||
allow(client).to receive(:releases).and_return([double(tag_name: '1.0.0')]) | ||
|
||
expect(test_action).to eq("1.0.0") | ||
end | ||
|
||
describe "when there is no latest release" do | ||
it "shows error" do | ||
client = double | ||
allow(Octokit::Client).to receive(:new).and_return(client) | ||
allow(client).to receive(:releases).and_return([]) | ||
allow(Fastlane::UI).to receive(:user_error!) | ||
|
||
test_action | ||
|
||
expect(Fastlane::UI).to have_received(:user_error!).with("Failed to find latest marketing version") | ||
end | ||
end | ||
|
||
describe "when latest release is not a valid semver" do | ||
it "shows error" do | ||
client = double | ||
allow(Octokit::Client).to receive(:new).and_return(client) | ||
allow(client).to receive(:releases).and_return([double(tag_name: '1.0')]) | ||
allow(Fastlane::UI).to receive(:user_error!) | ||
|
||
test_action | ||
|
||
expect(Fastlane::UI).to have_received(:user_error!).with("Invalid marketing version: 1.0, expected format: MAJOR.MINOR.PATCH") | ||
end | ||
end | ||
|
||
def test_action | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.find_latest_marketing_version("token") | ||
end | ||
end | ||
|
||
describe "#extract_version_from_tag_name" do | ||
it "returns the version from the tag name" do | ||
expect(test_action("1.0.0")).to eq("1.0.0") | ||
expect(test_action("v1.0.0")).to eq("v1.0.0") | ||
expect(test_action("1.105.0-251")).to eq("1.105.0") | ||
end | ||
|
||
def test_action(tag_name) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.extract_version_from_tag_name(tag_name) | ||
end | ||
end | ||
|
||
describe "#validate_semver" do | ||
it "validates semantic version" do | ||
expect(test_action("1.0.0")).to be_truthy | ||
expect(test_action("0.0.0")).to be_truthy | ||
expect(test_action("7.136.1")).to be_truthy | ||
|
||
expect(test_action("v1.0.0")).to be_falsy | ||
expect(test_action("7.1")).to be_falsy | ||
expect(test_action("1.105.0-251")).to be_falsy | ||
expect(test_action("1005")).to be_falsy | ||
end | ||
|
||
def test_action(version) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.validate_semver(version) | ||
end | ||
end | ||
|
||
describe "#find_release_task" do | ||
before do | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.setup_constants("ios") | ||
end | ||
|
||
describe "when release task is found" do | ||
before do | ||
expect(HTTParty).to receive(:get).and_return( | ||
double( | ||
success?: true, | ||
parsed_response: { 'data' => {}, 'next_page' => nil } | ||
) | ||
) | ||
end | ||
|
||
it "returns the release task ID" do | ||
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:find_hotfix_task_in_response) | ||
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).to receive(:find_release_task_in_response).and_return("1234567890") | ||
|
||
expect(test_action("1.0.0")).to eq("1234567890") | ||
end | ||
end | ||
|
||
describe "when fetching tasks in section fails" do | ||
before do | ||
expect(HTTParty).to receive(:get).and_return( | ||
double( | ||
success?: false, | ||
code: 401, | ||
message: "Unauthorized" | ||
) | ||
) | ||
end | ||
|
||
it "shows error" do | ||
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).not_to receive(:find_hotfix_task_in_response) | ||
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).not_to receive(:find_release_task_in_response) | ||
allow(Fastlane::UI).to receive(:user_error!) | ||
|
||
test_action("1.0.0") | ||
|
||
expect(Fastlane::UI).to have_received(:user_error!).with("Failed to fetch release task: (401 Unauthorized)") | ||
end | ||
end | ||
|
||
def test_action(version) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.find_release_task(version, "token") | ||
end | ||
end | ||
|
||
describe "#find_release_task_in_response" do | ||
def test_action(response, release_task_name) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.find_release_task_in_response(response, release_task_name) | ||
end | ||
end | ||
|
||
describe "#ensure_task_not_too_old" do | ||
def test_action(version, platform) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.ensure_task_not_too_old(version, platform, "token") | ||
end | ||
end | ||
|
||
describe "#find_hotfix_task_in_response" do | ||
def test_action(response) | ||
Fastlane::Actions::AsanaFindReleaseTaskAction.find_hotfix_task_in_response(response) | ||
end | ||
end | ||
end |