-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_spec.cr
More file actions
102 lines (86 loc) · 2.93 KB
/
trigger_spec.cr
File metadata and controls
102 lines (86 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require "./helper"
module PlaceOS::Model
describe Trigger do
test_round_trip(Trigger)
it "saves a trigger" do
inst = Generator.trigger.save!
Trigger.find!(inst.id.as(String)).id.should eq inst.id
end
describe "validations" do
it "validates webhook methods" do
invalid_model = Generator.trigger
invalid_model.supported_methods = ["NUGGET", "GET"]
valid_model = Generator.trigger
valid_model.supported_methods = ["POST", "GET"]
valid_model.valid?.should be_true
invalid_model.valid?.should be_false
invalid_model.errors.size.should eq 1
invalid_model.errors.first.to_s.should end_with "supported_methods contains invalid methods: NUGGET"
end
it "ensure associated authority" do
trigger = Generator.trigger
trigger.authority_id = ""
trigger.valid?.should be_false
trigger.errors.first.field.should eq :authority_id
end
end
describe Trigger::Actions do
it "validates function action" do
model = Generator.trigger
valid = Trigger::Actions::Function.new(
mod: "anthropocene",
method: "start"
)
invalid = Trigger::Actions::Function.new(
mod: "anthropocene",
)
model.actions.try &.functions = [valid, invalid]
model.valid?.should be_false
model.errors.first.to_s.should end_with "method should not be nil"
end
it "validates email action" do
model = Generator.trigger
valid = Trigger::Actions::Email.new(
emails: [Faker::Internet.email],
content: "Hi"
)
invalid = Trigger::Actions::Email.new(
content: "No email, whodis"
)
model.actions.try &.mailers = [valid, invalid]
model.valid?.should be_false
model.errors.size.should eq 1
model.errors.first.to_s.should end_with "emails is required"
end
end
describe Trigger::Conditions do
it "validates time dependent condition" do
model = Generator.trigger
valid = Trigger::Conditions::TimeDependent.new(
type: Trigger::Conditions::TimeDependent::Type::At,
time: Time.utc,
)
invalid = Trigger::Conditions::TimeDependent.new(
cron: "5 * * * *",
)
model.conditions.try &.time_dependents = [valid, invalid]
model.valid?.should be_false
model.errors.size.should eq 1
model.errors.first.to_s.should end_with "type should not be nil"
end
it "validates comparison condition" do
expect_raises(JSON::SerializableError) do
Trigger::Conditions::Comparison.from_json({
left: false,
operator: "asldkgjbn",
right: {
mod: "anthropocene",
status: "{on: true}",
keys: ["on"],
},
}.to_json)
end
end
end
end
end