-
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.
Add specs for GitHubActionsHelper and AsanaExtractTaskAssigneeAction
- Loading branch information
Showing
9 changed files
with
148 additions
and
38 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 |
---|---|---|
|
@@ -10,3 +10,4 @@ fastlane/README.md | |
fastlane/report.xml | ||
coverage | ||
test-results | ||
.DS_Store |
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
30 changes: 17 additions & 13 deletions
30
lib/fastlane/plugin/ddg_apple_automation/helper/ddg_apple_automation_helper.rb
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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
require "fastlane_core/configuration/config_item" | ||
require 'fastlane_core/ui/ui' | ||
|
||
module Fastlane | ||
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI) | ||
|
||
module Helper | ||
class DdgAppleAutomationHelper | ||
# class methods that you define here become available in your action | ||
# as `Helper::DdgAppleAutomationHelper.your_method` | ||
# | ||
|
||
ASANA_API_URL = "https://app.asana.com/api/1.0" | ||
ERROR_ASANA_ACCESS_TOKEN_NOT_SET = "ASANA_ACCESS_TOKEN is not set" | ||
end | ||
end | ||
end | ||
|
||
def self.show_message | ||
UI.message("Hello from the ddg_apple_automation plugin helper!") | ||
end | ||
|
||
def self.fetch_asana_token | ||
ENV.fetch("ASANA_ACCESS_TOKEN") | ||
rescue KeyError | ||
UI.user_error!("ASANA_ACCESS_TOKEN is not set") | ||
end | ||
module FastlaneCore | ||
class ConfigItem | ||
def self.asana_access_token | ||
FastlaneCore::ConfigItem.new(key: :asana_access_token, | ||
env_name: "ASANA_ACCESS_TOKEN", | ||
description: "Asana access token", | ||
optional: false, | ||
sensitive: true, | ||
type: String, | ||
verify_block: proc do |value| | ||
UI.user_error!(Fastlane::Helper::DdgAppleAutomationHelper::ERROR_ASANA_ACCESS_TOKEN_NOT_SET) if value.to_s.length == 0 | ||
end) | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Fastlane | ||
module DdgAppleAutomation | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end | ||
end |
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,57 @@ | ||
describe Fastlane::Actions::AsanaExtractTaskAssigneeAction do | ||
describe "#run" do | ||
it "returns the assignee ID when Asana task is assigned" do | ||
expect(HTTParty).to receive(:get).and_return( | ||
double( | ||
success?: true, | ||
parsed_response: { 'data' => { 'assignee' => { 'gid' => '67890' } } } | ||
) | ||
) | ||
|
||
expect(test_action("12345")).to eq("67890") | ||
end | ||
|
||
it "returns nil when Asana task is not assigned" do | ||
expect(HTTParty).to receive(:get).and_return( | ||
double( | ||
success?: true, | ||
parsed_response: { 'data' => { 'assignee' => nil } } | ||
) | ||
) | ||
|
||
expect(test_action("12345")).to eq(nil) | ||
end | ||
|
||
it "shows error when failed to fetch task assignee" do | ||
expect(HTTParty).to receive(:get).and_return( | ||
double( | ||
success?: false, | ||
code: 401, | ||
message: "Unauthorized" | ||
) | ||
) | ||
|
||
expect(Fastlane::UI).to receive(:user_error!).with("Failed to fetch task assignee: (401 Unauthorized)") | ||
|
||
test_action("12345") | ||
end | ||
|
||
it "sets GHA output" do | ||
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output) | ||
|
||
expect(HTTParty).to receive(:get).and_return( | ||
double( | ||
success?: true, | ||
parsed_response: { 'data' => { 'assignee' => { 'gid' => '67890' } } } | ||
) | ||
) | ||
|
||
expect(test_action("12345")).to eq("67890") | ||
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("asana_assignee_id", "67890") | ||
end | ||
end | ||
|
||
def test_action(task_id) | ||
Fastlane::Actions::AsanaExtractTaskAssigneeAction.run(task_id: task_id) | ||
end | ||
end |
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,58 @@ | ||
describe Fastlane::Helper::GitHubActionsHelper do | ||
describe "#set_output" do | ||
it "sets output when in CI and value is not empty" do | ||
allow(Fastlane::Helper).to receive(:is_ci?).and_return(true) | ||
allow(Fastlane::Action).to receive(:sh) | ||
allow(ENV).to receive(:fetch).with("GITHUB_OUTPUT", "/dev/null").and_return("/dev/null") | ||
|
||
set_output("foo", "bar") | ||
expect(Fastlane::Action).to have_received(:sh).with("echo 'foo=bar' >> /dev/null") | ||
end | ||
|
||
it "honors GITHUB_OUTPUT environment variable when in CI" do | ||
allow(Fastlane::Helper).to receive(:is_ci?).and_return(true) | ||
allow(Fastlane::Action).to receive(:sh) | ||
allow(ENV).to receive(:fetch).with("GITHUB_OUTPUT", "/dev/null").and_return("/tmp/github_output") | ||
|
||
set_output("foo", "bar") | ||
expect(Fastlane::Action).to have_received(:sh).with("echo 'foo=bar' >> /tmp/github_output") | ||
end | ||
|
||
it "does not set output when in CI and value is empty" do | ||
allow(Fastlane::Helper).to receive(:is_ci?).and_return(true) | ||
allow(Fastlane::Action).to receive(:sh) | ||
|
||
set_output("foo", "") | ||
expect(Fastlane::Action).not_to have_received(:sh) | ||
end | ||
|
||
it "does not set output when in CI and value is nil" do | ||
allow(Fastlane::Helper).to receive(:is_ci?).and_return(true) | ||
allow(Fastlane::Action).to receive(:sh) | ||
|
||
set_output("foo", nil) | ||
expect(Fastlane::Action).not_to have_received(:sh) | ||
end | ||
|
||
it "does not set output when not in CI" do | ||
allow(Fastlane::Helper).to receive(:is_ci?).and_return(false) | ||
allow(Fastlane::Action).to receive(:sh) | ||
|
||
set_output("foo", "bar") | ||
expect(Fastlane::Action).not_to have_received(:sh) | ||
end | ||
|
||
it "fails when key is empty" do | ||
allow(Fastlane::Helper).to receive(:is_ci?).and_return(true) | ||
allow(Fastlane::Action).to receive(:sh) | ||
expect(Fastlane::UI).to receive(:user_error!).with("Key cannot be empty") | ||
|
||
set_output("", "bar") | ||
expect(Fastlane::Action).not_to have_received(:sh) | ||
end | ||
end | ||
|
||
def set_output(key, value) | ||
Fastlane::Helper::GitHubActionsHelper.set_output(key, value) | ||
end | ||
end |