fix validate inputs
This commit is contained in:
parent
9ec98132f3
commit
f940606886
|
@ -5,9 +5,11 @@ class MergeBrachService
|
|||
TYPE_NOW = "now".freeze
|
||||
|
||||
def self.validate_inputs!(target_branch:, type:, label_name:)
|
||||
raise "Invalid type" if type != TYPE_LABELED || type != TYPE_NOW
|
||||
raise "Empty target branch" if target_branch
|
||||
raise "Empty target label name" if type == TYPE_LABELED && label_name
|
||||
raise "Invalid type" unless [TYPE_LABELED, TYPE_NOW].include?(type)
|
||||
raise "Empty target branch" unless target_branch
|
||||
if type == TYPE_LABELED
|
||||
raise "Empty target label name" unless label_name
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(inputs, github_event)
|
||||
|
|
|
@ -19,6 +19,20 @@ describe MergeBrachService do
|
|||
{ type: 'labeled', target_branch: target_branch, label_name: label_name }
|
||||
}
|
||||
|
||||
context "with valid inputs" do
|
||||
it ".validate_inputs!" do
|
||||
expect{ MergeBrachService.validate_inputs!(inputs) }.to_not raise_error()
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid label name" do
|
||||
let(:label_name) { nil }
|
||||
|
||||
it ".validate_inputs!" do
|
||||
expect{ MergeBrachService.validate_inputs!(inputs) }.to raise_error()
|
||||
end
|
||||
end
|
||||
|
||||
context "not match label" do
|
||||
let(:event) { { 'action' => 'labeled', 'label' => { 'name' => 'other label' } } }
|
||||
|
||||
|
|
Loading…
Reference in New Issue