Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from zendesk/ytang/rule-helper-methods
Add helper methods for configuring Views
- Loading branch information
Showing
5 changed files
with
324 additions
and
0 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,81 @@ | ||
require 'core/spec_helper' | ||
|
||
describe ZendeskAPI::Automation do | ||
def valid_attributes | ||
{ | ||
:title => "my test automation", | ||
:conditions => { | ||
:any => [{ :field => "assignee_id", :operator => "is", :value => 1}], | ||
:all => [{ :field => "status", :operator => "is", :value => "open" }] | ||
}, | ||
:actions => [{ :field => "priority", :value => "urgent" }], | ||
} | ||
end | ||
|
||
subject do | ||
described_class.new(double, valid_attributes) | ||
end | ||
|
||
describe "#all_conditions=" do | ||
it "should assign new values to all conditions" do | ||
new_conditions = [ | ||
{ "field" => "type", "operator" => "is", "value" => "question" }, | ||
{ "field" => "status", "operator" => "less_than", "value" => "solved" } | ||
] | ||
subject.all_conditions = new_conditions | ||
|
||
expect(subject.conditions[:all]).to eq(new_conditions) | ||
end | ||
end | ||
|
||
describe "#any_conditions=" do | ||
it "should assign new values to any conditions" do | ||
new_conditions = [ | ||
{ "field" => "type", "operator" => "is", "value" => "question" }, | ||
{ "field" => "status", "operator" => "less_than", "value" => "solved" } | ||
] | ||
subject.any_conditions = new_conditions | ||
|
||
expect(subject.conditions[:any]).to eq(new_conditions) | ||
end | ||
end | ||
|
||
describe "#add_all_condition" do | ||
it "should add a condition to all condition" do | ||
new_condition = { :field => "type", :operator => "is", :value => "problem" } | ||
existing_conditions = subject.conditions[:all] | ||
|
||
expect(existing_conditions).not_to include(new_condition) | ||
|
||
subject.add_all_condition("type", "is", "problem") | ||
|
||
expect(subject.conditions[:all]).to eq(existing_conditions << new_condition) | ||
end | ||
end | ||
|
||
describe "#add_any_condition" do | ||
it "should add a condition to any condition" do | ||
new_condition = { :field => "type", :operator => "is", :value => "task" } | ||
existing_conditions = subject.conditions[:any] | ||
|
||
expect(existing_conditions).not_to include(new_condition) | ||
|
||
subject.add_any_condition("type", "is", "task") | ||
|
||
expect(subject.conditions[:any]).to eq(existing_conditions << new_condition) | ||
end | ||
end | ||
|
||
describe "#add_action" do | ||
it "should add an action to the current actions" do | ||
new_action = { :field => "status", :value => "solved" } | ||
existing_actions = subject.actions | ||
|
||
expect(existing_actions).not_to include(new_action) | ||
|
||
subject.add_action("status", "solved") | ||
|
||
expect(subject.actions).to eq(existing_actions << new_action) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'core/spec_helper' | ||
|
||
describe ZendeskAPI::Macro do | ||
def valid_attributes | ||
{ | ||
:title => "my test macro", | ||
:actions => [{ :field => "priority", :value => "urgent" }], | ||
} | ||
end | ||
|
||
subject do | ||
described_class.new(double, valid_attributes) | ||
end | ||
|
||
describe "#add_action" do | ||
it "should add an action to the current actions" do | ||
new_action = { :field => "status", :value => "solved" } | ||
existing_actions = subject.actions | ||
|
||
expect(existing_actions).not_to include(new_action) | ||
|
||
subject.add_action("status", "solved") | ||
|
||
expect(subject.actions).to eq(existing_actions << new_action) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'core/spec_helper' | ||
|
||
describe ZendeskAPI::Trigger do | ||
def valid_attributes | ||
{ | ||
:title => "my test trigger", | ||
:conditions => { | ||
:any => [{ :field => "assignee_id", :operator => "is", :value => 1}], | ||
:all => [{ :field => "status", :operator => "is", :value => "open" }] | ||
}, | ||
} | ||
end | ||
|
||
subject do | ||
described_class.new(double, valid_attributes) | ||
end | ||
|
||
describe "#all_conditions=" do | ||
it "should assign new values to all conditions" do | ||
new_conditions = [ | ||
{ "field" => "type", "operator" => "is", "value" => "question" }, | ||
{ "field" => "status", "operator" => "less_than", "value" => "solved" } | ||
] | ||
subject.all_conditions = new_conditions | ||
|
||
expect(subject.conditions[:all]).to eq(new_conditions) | ||
end | ||
end | ||
|
||
describe "#any_conditions=" do | ||
it "should assign new values to any conditions" do | ||
new_conditions = [ | ||
{ "field" => "type", "operator" => "is", "value" => "question" }, | ||
{ "field" => "status", "operator" => "less_than", "value" => "solved" } | ||
] | ||
subject.any_conditions = new_conditions | ||
|
||
expect(subject.conditions[:any]).to eq(new_conditions) | ||
end | ||
end | ||
|
||
describe "#add_all_condition" do | ||
it "should add a condition to all condition" do | ||
new_condition = { :field => "type", :operator => "is", :value => "problem" } | ||
existing_conditions = subject.conditions[:all] | ||
|
||
expect(existing_conditions).not_to include(new_condition) | ||
|
||
subject.add_all_condition("type", "is", "problem") | ||
|
||
expect(subject.conditions[:all]).to eq(existing_conditions << new_condition) | ||
end | ||
end | ||
|
||
describe "#add_any_condition" do | ||
it "should add a condition to any condition" do | ||
new_condition = { :field => "type", :operator => "is", :value => "task" } | ||
existing_conditions = subject.conditions[:any] | ||
|
||
expect(existing_conditions).not_to include(new_condition) | ||
|
||
subject.add_any_condition("type", "is", "task") | ||
|
||
expect(subject.conditions[:any]).to eq(existing_conditions << new_condition) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'core/spec_helper' | ||
|
||
describe ZendeskAPI::View do | ||
def valid_attributes | ||
{ | ||
:title => "my test view", | ||
:conditions => { | ||
:any => [{ :field => "assignee_id", :operator => "is", :value => 1}], | ||
:all => [{ :field => "status", :operator => "is", :value => "open" }] | ||
}, | ||
:execution => { | ||
:columns => [:id => "status", :title=> "Status"] | ||
} | ||
} | ||
end | ||
|
||
subject do | ||
described_class.new(double, valid_attributes) | ||
end | ||
|
||
describe "#columns=" do | ||
it "should add a single column" do | ||
new_column = ["priority"] | ||
subject.columns = new_column | ||
|
||
expect(subject.output["columns"]).to eq(new_column) | ||
end | ||
|
||
it "should set columns on output" do | ||
new_columns = ["type", "priority"] | ||
subject.columns = new_columns | ||
|
||
expect(subject.output["columns"]).to eq(new_columns) | ||
end | ||
end | ||
|
||
describe "#add_column" do | ||
it "should add a column to the existing columns" do | ||
existing_columns = subject.execution.columns.map {|c| c["id"]} | ||
expect(existing_columns.include?("type")).to eq(false) | ||
|
||
subject.add_column("type") | ||
|
||
expect(subject.output["columns"]).to eq(existing_columns << "type") | ||
end | ||
end | ||
|
||
describe "#all_conditions=" do | ||
it "should assign new values to all conditions" do | ||
new_conditions = [ | ||
{ "field" => "type", "operator" => "is", "value" => "question" }, | ||
{ "field" => "status", "operator" => "less_than", "value" => "solved" } | ||
] | ||
subject.all_conditions = new_conditions | ||
|
||
expect(subject.conditions[:all]).to eq(new_conditions) | ||
end | ||
end | ||
|
||
describe "#any_conditions=" do | ||
it "should assign new values to any conditions" do | ||
new_conditions = [ | ||
{ "field" => "type", "operator" => "is", "value" => "question" }, | ||
{ "field" => "status", "operator" => "less_than", "value" => "solved" } | ||
] | ||
subject.any_conditions = new_conditions | ||
|
||
expect(subject.conditions[:any]).to eq(new_conditions) | ||
end | ||
end | ||
|
||
describe "#add_all_condition" do | ||
it "should add a condition to all condition" do | ||
new_condition = { :field => "type", :operator => "is", :value => "problem" } | ||
existing_conditions = subject.conditions[:all] | ||
|
||
expect(existing_conditions).not_to include(new_condition) | ||
|
||
subject.add_all_condition("type", "is", "problem") | ||
|
||
expect(subject.conditions[:all]).to eq(existing_conditions << new_condition) | ||
end | ||
end | ||
|
||
describe "#add_any_condition" do | ||
it "should add a condition to any condition" do | ||
new_condition = { :field => "type", :operator => "is", :value => "task" } | ||
existing_conditions = subject.conditions[:any] | ||
|
||
expect(existing_conditions).not_to include(new_condition) | ||
|
||
subject.add_any_condition("type", "is", "task") | ||
|
||
expect(subject.conditions[:any]).to eq(existing_conditions << new_condition) | ||
end | ||
end | ||
end |