flapjack-diner 2.0.0.pre.alpha.2 → 2.0.0.pre.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +214 -89
- data/lib/flapjack-diner.rb +3 -3
- data/lib/flapjack-diner/resources/{blackholes.rb → acceptors.rb} +20 -16
- data/lib/flapjack-diner/resources/media.rb +2 -2
- data/lib/flapjack-diner/resources/{rules.rb → rejectors.rb} +20 -16
- data/lib/flapjack-diner/resources/relationships.rb +35 -23
- data/lib/flapjack-diner/resources/tags.rb +2 -2
- data/lib/flapjack-diner/version.rb +1 -1
- data/spec/resources/acceptors_spec.rb +278 -0
- data/spec/resources/contacts_spec.rb +8 -8
- data/spec/resources/rejectors_spec.rb +278 -0
- data/spec/resources/relationships_spec.rb +5 -5
- data/spec/support/fixture_data.rb +95 -71
- metadata +8 -8
- data/spec/resources/blackholes_spec.rb +0 -278
- data/spec/resources/rules_spec.rb +0 -278
@@ -8,62 +8,66 @@ require 'flapjack-diner/argument_validator'
|
|
8
8
|
module Flapjack
|
9
9
|
module Diner
|
10
10
|
module Resources
|
11
|
-
module
|
11
|
+
module Acceptors
|
12
12
|
|
13
|
-
def
|
13
|
+
def create_acceptors(*args)
|
14
14
|
data = unwrap_data(*args)
|
15
15
|
validate_params(data) do
|
16
16
|
validate :query => :id, :as => :uuid
|
17
|
-
|
17
|
+
validate :query => :name, :as => :string
|
18
|
+
validate :query => :all, :as => :boolean
|
18
19
|
validate :query => :conditions_list, :as => :string
|
20
|
+
# TODO proper validation of time_restrictions field
|
19
21
|
validate :query => :contact, :as => [:singular_link_uuid, :required]
|
20
22
|
validate :query => :media, :as => :multiple_link_uuid
|
21
23
|
validate :query => :tags, :as => :multiple_link
|
22
24
|
end
|
23
|
-
|
24
|
-
perform_post(:
|
25
|
+
_acceptors_validate_association(data)
|
26
|
+
perform_post(:acceptors, '/acceptors', data)
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def acceptors(*args)
|
28
30
|
ids, data = unwrap_uuids(*args), unwrap_data(*args)
|
29
31
|
validate_params(data) do
|
30
32
|
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
31
33
|
validate :query => :filter, :as => :hash
|
32
34
|
validate :query => [:page, :per_page], :as => :positive_integer
|
33
35
|
end
|
34
|
-
perform_get('/
|
36
|
+
perform_get('/acceptors', ids, data)
|
35
37
|
end
|
36
38
|
|
37
|
-
def
|
39
|
+
def update_acceptors(*args)
|
38
40
|
data = unwrap_data(*args)
|
39
41
|
validate_params(data) do
|
40
42
|
validate :query => :id, :as => [:uuid, :required]
|
41
|
-
|
43
|
+
validate :query => :name, :as => :string
|
44
|
+
validate :query => :all, :as => :boolean
|
42
45
|
validate :query => :conditions_list, :as => :string
|
46
|
+
# TODO proper validation of time_restrictions field
|
43
47
|
validate :query => :media, :as => :multiple_link_uuid
|
44
48
|
validate :query => :tags, :as => :multiple_link
|
45
49
|
end
|
46
|
-
perform_patch(:
|
50
|
+
perform_patch(:acceptors, "/acceptors", data)
|
47
51
|
end
|
48
52
|
|
49
|
-
def
|
50
|
-
raise "'
|
51
|
-
perform_delete(:
|
53
|
+
def delete_acceptors(*ids)
|
54
|
+
raise "'delete_acceptors' requires at least one acceptor id parameter" if ids.nil? || ids.empty?
|
55
|
+
perform_delete(:acceptors, '/acceptors', *ids)
|
52
56
|
end
|
53
57
|
|
54
58
|
private
|
55
59
|
|
56
|
-
def
|
60
|
+
def _acceptors_validate_association(data)
|
57
61
|
case data
|
58
62
|
when Array
|
59
63
|
data.each do |d|
|
60
64
|
unless d.has_key?(:contact)
|
61
|
-
raise ArgumentError.new("Contact association must be provided for all
|
65
|
+
raise ArgumentError.new("Contact association must be provided for all acceptors")
|
62
66
|
end
|
63
67
|
end
|
64
68
|
when Hash
|
65
69
|
unless data.has_key?(:contact)
|
66
|
-
raise ArgumentError.new("Contact association must be provided for
|
70
|
+
raise ArgumentError.new("Contact association must be provided for acceptor")
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|
@@ -19,7 +19,7 @@ module Flapjack
|
|
19
19
|
validate :query => [:interval, :rollup_threshold,
|
20
20
|
:pagerduty_ack_duration], :as => :positive_integer
|
21
21
|
validate :query => :contact, :as => [:singular_link_uuid, :required]
|
22
|
-
validate :query => :
|
22
|
+
validate :query => [:acceptors, :rejectors], :as => :multiple_link_uuid
|
23
23
|
end
|
24
24
|
perform_post(:media, "/media", data)
|
25
25
|
end
|
@@ -42,7 +42,7 @@ module Flapjack
|
|
42
42
|
:pagerduty_token], :as => :non_empty_string
|
43
43
|
validate :query => [:interval, :rollup_threshold,
|
44
44
|
:pagerduty_ack_duration], :as => :positive_integer
|
45
|
-
validate :query => :
|
45
|
+
validate :query => [:acceptors, :rejectors], :as => :multiple_link_uuid
|
46
46
|
end
|
47
47
|
perform_patch(:media, "/media", data)
|
48
48
|
end
|
@@ -8,62 +8,66 @@ require 'flapjack-diner/argument_validator'
|
|
8
8
|
module Flapjack
|
9
9
|
module Diner
|
10
10
|
module Resources
|
11
|
-
module
|
11
|
+
module Rejectors
|
12
12
|
|
13
|
-
def
|
13
|
+
def create_rejectors(*args)
|
14
14
|
data = unwrap_data(*args)
|
15
15
|
validate_params(data) do
|
16
16
|
validate :query => :id, :as => :uuid
|
17
|
-
|
17
|
+
validate :query => :name, :as => :string
|
18
|
+
validate :query => :all, :as => :boolean
|
18
19
|
validate :query => :conditions_list, :as => :string
|
20
|
+
# TODO proper validation of time_restrictions field
|
19
21
|
validate :query => :contact, :as => [:singular_link_uuid, :required]
|
20
22
|
validate :query => :media, :as => :multiple_link_uuid
|
21
23
|
validate :query => :tags, :as => :multiple_link
|
22
24
|
end
|
23
|
-
|
24
|
-
perform_post(:
|
25
|
+
_rejectors_validate_association(data)
|
26
|
+
perform_post(:rejectors, '/rejectors', data)
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
29
|
+
def rejectors(*args)
|
28
30
|
ids, data = unwrap_uuids(*args), unwrap_data(*args)
|
29
31
|
validate_params(data) do
|
30
32
|
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
31
33
|
validate :query => :filter, :as => :hash
|
32
34
|
validate :query => [:page, :per_page], :as => :positive_integer
|
33
35
|
end
|
34
|
-
perform_get('/
|
36
|
+
perform_get('/rejectors', ids, data)
|
35
37
|
end
|
36
38
|
|
37
|
-
def
|
39
|
+
def update_rejectors(*args)
|
38
40
|
data = unwrap_data(*args)
|
39
41
|
validate_params(data) do
|
40
42
|
validate :query => :id, :as => [:uuid, :required]
|
41
|
-
|
43
|
+
validate :query => :name, :as => :string
|
44
|
+
validate :query => :all, :as => :boolean
|
42
45
|
validate :query => :conditions_list, :as => :string
|
46
|
+
# TODO proper validation of time_restrictions field
|
43
47
|
validate :query => :media, :as => :multiple_link_uuid
|
44
48
|
validate :query => :tags, :as => :multiple_link
|
45
49
|
end
|
46
|
-
perform_patch(:
|
50
|
+
perform_patch(:rejectors, "/rejectors", data)
|
47
51
|
end
|
48
52
|
|
49
|
-
def
|
50
|
-
raise "'
|
51
|
-
perform_delete(:
|
53
|
+
def delete_rejectors(*ids)
|
54
|
+
raise "'delete_rejectors' requires at least one rejector id parameter" if ids.nil? || ids.empty?
|
55
|
+
perform_delete(:rejectors, '/rejectors', *ids)
|
52
56
|
end
|
53
57
|
|
54
58
|
private
|
55
59
|
|
56
|
-
def
|
60
|
+
def _rejectors_validate_association(data)
|
57
61
|
case data
|
58
62
|
when Array
|
59
63
|
data.each do |d|
|
60
64
|
unless d.has_key?(:contact)
|
61
|
-
raise ArgumentError.new("Contact association must be provided for all
|
65
|
+
raise ArgumentError.new("Contact association must be provided for all rejectors")
|
62
66
|
end
|
63
67
|
end
|
64
68
|
when Hash
|
65
69
|
unless data.has_key?(:contact)
|
66
|
-
raise ArgumentError.new("Contact association must be provided for
|
70
|
+
raise ArgumentError.new("Contact association must be provided for rejector")
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|
@@ -11,12 +11,12 @@ module Flapjack
|
|
11
11
|
module Relationships
|
12
12
|
|
13
13
|
TYPES = {
|
14
|
+
:acceptors => 'acceptor',
|
14
15
|
:acknowledgements => 'acknowledgement',
|
15
|
-
:blackholes => 'blackhole',
|
16
16
|
:checks => 'check',
|
17
17
|
:contacts => 'contact',
|
18
18
|
:media => 'medium',
|
19
|
-
:
|
19
|
+
:rejectors => 'rejector',
|
20
20
|
:scheduled_maintenances => 'scheduled_maintenance',
|
21
21
|
:states => 'state',
|
22
22
|
:tags => 'tag',
|
@@ -28,17 +28,7 @@ module Flapjack
|
|
28
28
|
|
29
29
|
# extracted from flapjack data models' "jsonapi_associations" class method
|
30
30
|
ASSOCIATIONS = {
|
31
|
-
:
|
32
|
-
:check => {
|
33
|
-
:post => true,
|
34
|
-
:number => :singular, :link => false, :includable => false
|
35
|
-
},
|
36
|
-
:tag => {
|
37
|
-
:post => true,
|
38
|
-
:number => :singular, :link => false, :includable => false
|
39
|
-
}
|
40
|
-
},
|
41
|
-
:blackholes => {
|
31
|
+
:acceptors => {
|
42
32
|
:contact => {
|
43
33
|
:post => true, :get => true,
|
44
34
|
:number => :singular, :link => true, :includable => true
|
@@ -52,6 +42,16 @@ module Flapjack
|
|
52
42
|
:number => :multiple, :link => true, :includable => true
|
53
43
|
}
|
54
44
|
},
|
45
|
+
:acknowledgements => {
|
46
|
+
:check => {
|
47
|
+
:post => true,
|
48
|
+
:number => :singular, :link => false, :includable => false
|
49
|
+
},
|
50
|
+
:tag => {
|
51
|
+
:post => true,
|
52
|
+
:number => :singular, :link => false, :includable => false
|
53
|
+
}
|
54
|
+
},
|
55
55
|
:checks => {
|
56
56
|
:alerting_media => {
|
57
57
|
:get => true,
|
@@ -95,7 +95,7 @@ module Flapjack
|
|
95
95
|
}
|
96
96
|
},
|
97
97
|
:contacts => {
|
98
|
-
:
|
98
|
+
:acceptors => {
|
99
99
|
:get => true,
|
100
100
|
:number => :multiple, :link => true, :includable => true
|
101
101
|
},
|
@@ -107,30 +107,30 @@ module Flapjack
|
|
107
107
|
:get => true,
|
108
108
|
:number => :multiple, :link => true, :includable => true
|
109
109
|
},
|
110
|
-
:
|
110
|
+
:rejectors => {
|
111
111
|
:get => :true,
|
112
112
|
:number => :multiple, :link => true, :includable => true
|
113
113
|
}
|
114
114
|
},
|
115
115
|
:media => {
|
116
|
-
:
|
117
|
-
:get => true,
|
116
|
+
:acceptors => {
|
117
|
+
:post => true, :get => true, :patch => true, :delete => true,
|
118
118
|
:number => :multiple, :link => true, :includable => true
|
119
119
|
},
|
120
|
-
:
|
121
|
-
:
|
120
|
+
:alerting_checks => {
|
121
|
+
:get => true,
|
122
122
|
:number => :multiple, :link => true, :includable => true
|
123
123
|
},
|
124
124
|
:contact => {
|
125
125
|
:post => true, :get => true,
|
126
126
|
:number => :singular, :link => true, :includable => true
|
127
127
|
},
|
128
|
-
:
|
128
|
+
:rejectors => {
|
129
129
|
:post => true, :get => true, :patch => true, :delete => true,
|
130
130
|
:number => :multiple, :link => true, :includable => true
|
131
131
|
}
|
132
132
|
},
|
133
|
-
:
|
133
|
+
:rejectors => {
|
134
134
|
:contact => {
|
135
135
|
:post => true, :get => true,
|
136
136
|
:number => :singular, :link => true, :includable => true
|
@@ -161,7 +161,7 @@ module Flapjack
|
|
161
161
|
}
|
162
162
|
},
|
163
163
|
:tags => {
|
164
|
-
:
|
164
|
+
:acceptors => {
|
165
165
|
:post => true, :get => true, :patch => true, :delete => true,
|
166
166
|
:number => :multiple, :link => true, :includable => true
|
167
167
|
},
|
@@ -169,9 +169,21 @@ module Flapjack
|
|
169
169
|
:post => true, :get => true, :patch => true, :delete => true,
|
170
170
|
:number => :multiple, :link => true, :includable => true
|
171
171
|
},
|
172
|
-
:
|
172
|
+
:rejectors => {
|
173
173
|
:post => true, :get => true, :patch => true, :delete => true,
|
174
174
|
:number => :multiple, :link => true, :includable => true
|
175
|
+
},
|
176
|
+
:scheduled_maintenances => {
|
177
|
+
:get => true,
|
178
|
+
:number => :multiple, :link => true, :includable => false
|
179
|
+
},
|
180
|
+
:states => {
|
181
|
+
:get => true,
|
182
|
+
:number => :multiple, :link => true, :includable => false
|
183
|
+
},
|
184
|
+
:unscheduled_maintenances => {
|
185
|
+
:get => true,
|
186
|
+
:number => :multiple, :link => true, :includable => false
|
175
187
|
}
|
176
188
|
},
|
177
189
|
:test_notifications => {
|
@@ -13,7 +13,7 @@ module Flapjack
|
|
13
13
|
data = unwrap_data(*args)
|
14
14
|
validate_params(data) do
|
15
15
|
validate :query => :name, :as => [:required, :non_empty_string]
|
16
|
-
validate :query => [:checks, :
|
16
|
+
validate :query => [:checks, :acceptors, :rejectors], :as => :multiple_link_uuid
|
17
17
|
end
|
18
18
|
perform_post(:tags, '/tags', data)
|
19
19
|
end
|
@@ -31,7 +31,7 @@ module Flapjack
|
|
31
31
|
def update_tags(*args)
|
32
32
|
data = unwrap_data(*args)
|
33
33
|
validate_params(data) do
|
34
|
-
validate :query => [:checks, :
|
34
|
+
validate :query => [:checks, :acceptors, :rejectors], :as => :multiple_link_uuid
|
35
35
|
end
|
36
36
|
perform_patch(:tags, "/tags", data)
|
37
37
|
end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack-diner'
|
3
|
+
|
4
|
+
describe Flapjack::Diner::Resources::Acceptors, :pact => true do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Flapjack::Diner.base_uri('localhost:19081')
|
8
|
+
Flapjack::Diner.logger = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'create' do
|
12
|
+
|
13
|
+
it "submits a POST request for an acceptor" do
|
14
|
+
req_data = acceptor_json(acceptor_data).merge(
|
15
|
+
:relationships => {
|
16
|
+
:contact => {
|
17
|
+
:data => {
|
18
|
+
:type => 'contact',
|
19
|
+
:id => contact_data[:id]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
)
|
24
|
+
resp_data = acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data))
|
25
|
+
|
26
|
+
flapjack.given("a contact exists").
|
27
|
+
upon_receiving("a POST request with one acceptor").
|
28
|
+
with(:method => :post, :path => '/acceptors',
|
29
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
30
|
+
:body => {:data => req_data}).
|
31
|
+
will_respond_with(
|
32
|
+
:status => 201,
|
33
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
34
|
+
:body => {:data => resp_data}
|
35
|
+
)
|
36
|
+
|
37
|
+
result = Flapjack::Diner.create_acceptors(acceptor_data.merge(:contact => contact_data[:id]))
|
38
|
+
expect(result).not_to be_nil
|
39
|
+
expect(result).to eq(resultify(resp_data))
|
40
|
+
end
|
41
|
+
|
42
|
+
it "submits a POST request for several acceptors" do
|
43
|
+
req_data = [acceptor_json(acceptor_data).merge(
|
44
|
+
:relationships => {
|
45
|
+
:contact => {
|
46
|
+
:data => {
|
47
|
+
:type => 'contact',
|
48
|
+
:id => contact_data[:id]
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
), acceptor_json(acceptor_2_data).merge(
|
53
|
+
:relationships => {
|
54
|
+
:contact => {
|
55
|
+
:data => {
|
56
|
+
:type => 'contact',
|
57
|
+
:id => contact_data[:id]
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
)]
|
62
|
+
resp_data = [
|
63
|
+
acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data)),
|
64
|
+
acceptor_json(acceptor_2_data).merge(:relationships => acceptor_rel(acceptor_2_data))
|
65
|
+
]
|
66
|
+
|
67
|
+
flapjack.given("a contact exists").
|
68
|
+
upon_receiving("a POST request with two acceptors").
|
69
|
+
with(:method => :post, :path => '/acceptors',
|
70
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
71
|
+
:body => {:data => req_data}).
|
72
|
+
will_respond_with(
|
73
|
+
:status => 201,
|
74
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
75
|
+
:body => {:data => resp_data}
|
76
|
+
)
|
77
|
+
|
78
|
+
result = Flapjack::Diner.create_acceptors(acceptor_data.merge(:contact => contact_data[:id]),
|
79
|
+
acceptor_2_data.merge(:contact => contact_data[:id]))
|
80
|
+
expect(result).not_to be_nil
|
81
|
+
expect(result).to eq(resultify(resp_data))
|
82
|
+
end
|
83
|
+
|
84
|
+
# TODO error due to invalid data
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'read' do
|
89
|
+
|
90
|
+
it "submits a GET request for all acceptors" do
|
91
|
+
resp_data = [acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data))]
|
92
|
+
|
93
|
+
flapjack.given("an acceptor exists").
|
94
|
+
upon_receiving("a GET request for all acceptors").
|
95
|
+
with(:method => :get, :path => '/acceptors').
|
96
|
+
will_respond_with(
|
97
|
+
:status => 200,
|
98
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
99
|
+
:body => {:data => resp_data} )
|
100
|
+
|
101
|
+
result = Flapjack::Diner.acceptors
|
102
|
+
expect(result).not_to be_nil
|
103
|
+
expect(result).to eq(resultify(resp_data))
|
104
|
+
end
|
105
|
+
|
106
|
+
it "submits a GET request for one acceptor" do
|
107
|
+
resp_data = acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data))
|
108
|
+
|
109
|
+
flapjack.given("an acceptor exists").
|
110
|
+
upon_receiving("a GET request for a single acceptor").
|
111
|
+
with(:method => :get, :path => "/acceptors/#{acceptor_data[:id]}").
|
112
|
+
will_respond_with(
|
113
|
+
:status => 200,
|
114
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
115
|
+
:body => {:data => resp_data}
|
116
|
+
)
|
117
|
+
|
118
|
+
result = Flapjack::Diner.acceptors(acceptor_data[:id])
|
119
|
+
expect(result).not_to be_nil
|
120
|
+
expect(result).to eq(resultify(resp_data))
|
121
|
+
end
|
122
|
+
|
123
|
+
it "submits a GET request for several acceptors" do
|
124
|
+
resp_data = [
|
125
|
+
acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data)),
|
126
|
+
acceptor_json(acceptor_2_data).merge(:relationships => acceptor_rel(acceptor_2_data))
|
127
|
+
]
|
128
|
+
|
129
|
+
acceptors_data = [acceptor_data.merge(:type => 'acceptor'), acceptor_2_data.merge(:type => 'acceptor')]
|
130
|
+
|
131
|
+
flapjack.given("two acceptors exist").
|
132
|
+
upon_receiving("a GET request for two acceptors").
|
133
|
+
with(:method => :get, :path => "/acceptors",
|
134
|
+
:query => "filter%5B%5D=id%3A#{acceptor_data[:id]}%7C#{acceptor_2_data[:id]}").
|
135
|
+
will_respond_with(
|
136
|
+
:status => 200,
|
137
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
138
|
+
:body => {:data => resp_data} )
|
139
|
+
|
140
|
+
result = Flapjack::Diner.acceptors(acceptor_data[:id], acceptor_2_data[:id])
|
141
|
+
expect(result).not_to be_nil
|
142
|
+
expect(result).to eq(resultify(resp_data))
|
143
|
+
end
|
144
|
+
|
145
|
+
it "can't find the acceptor to read" do
|
146
|
+
flapjack.given("no data exists").
|
147
|
+
upon_receiving("a GET request for a single acceptor").
|
148
|
+
with(:method => :get, :path => "/acceptors/#{acceptor_data[:id]}").
|
149
|
+
will_respond_with(
|
150
|
+
:status => 404,
|
151
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
152
|
+
:body => {:errors => [{
|
153
|
+
:status => '404',
|
154
|
+
:detail => "could not find Acceptor record, id: '#{acceptor_data[:id]}'"
|
155
|
+
}]}
|
156
|
+
)
|
157
|
+
|
158
|
+
result = Flapjack::Diner.acceptors(acceptor_data[:id])
|
159
|
+
expect(result).to be_nil
|
160
|
+
expect(Flapjack::Diner.last_error).to eq([{:status => '404',
|
161
|
+
:detail => "could not find Acceptor record, id: '#{acceptor_data[:id]}'"}])
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
# # Not immediately relevant, no data fields to update until time_restrictions are fixed
|
167
|
+
# context 'update' do
|
168
|
+
# it 'submits a PUT request for an acceptor' do
|
169
|
+
# flapjack.given("an acceptor exists").
|
170
|
+
# upon_receiving("a PUT request for a single acceptor").
|
171
|
+
# with(:method => :put,
|
172
|
+
# :path => "/acceptors/#{acceptor_data[:id]}",
|
173
|
+
# :body => {:acceptors => {:id => acceptor_data[:id], :time_restrictions => []}},
|
174
|
+
# :headers => {'Content-Type' => 'application/vnd.api+json'}).
|
175
|
+
# will_respond_with(
|
176
|
+
# :status => 204,
|
177
|
+
# :body => '' )
|
178
|
+
|
179
|
+
# result = Flapjack::Diner.update_acceptors(:id => acceptor_data[:id], :time_restrictions => [])
|
180
|
+
# expect(result).to be_a(TrueClass)
|
181
|
+
# end
|
182
|
+
|
183
|
+
# it 'submits a PUT request for several acceptors' do
|
184
|
+
# flapjack.given("two acceptors exist").
|
185
|
+
# upon_receiving("a PUT request for two acceptors").
|
186
|
+
# with(:method => :put,
|
187
|
+
# :path => "/acceptors/#{acceptor_data[:id]},#{acceptor_2_data[:id]}",
|
188
|
+
# :body => {:acceptors => [{:id => acceptor_data[:id], :time_restrictions => []},
|
189
|
+
# {:id => acceptor_2_data[:id], :enabled => true}]},
|
190
|
+
# :headers => {'Content-Type' => 'application/vnd.api+json'}).
|
191
|
+
# will_respond_with(
|
192
|
+
# :status => 204,
|
193
|
+
# :body => '' )
|
194
|
+
|
195
|
+
# result = Flapjack::Diner.update_acceptors(
|
196
|
+
# {:id => acceptor_data[:id], :time_restrictions => []},
|
197
|
+
# {:id => acceptor_2_data[:id], :enabled => true})
|
198
|
+
# expect(result).to be_a(TrueClass)
|
199
|
+
# end
|
200
|
+
|
201
|
+
# it "can't find the acceptor to update" do
|
202
|
+
# flapjack.given("no data exists").
|
203
|
+
# upon_receiving("a PUT request for a single acceptor").
|
204
|
+
# with(:method => :put,
|
205
|
+
# :path => "/acceptors/#{acceptor_data[:id]}",
|
206
|
+
# :body => {:acceptors => {:id => acceptor_data[:id], :time_restrictions => []}},
|
207
|
+
# :headers => {'Content-Type' => 'application/vnd.api+json'}).
|
208
|
+
# will_respond_with(
|
209
|
+
# :status => 404,
|
210
|
+
# :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
211
|
+
# :body => {:errors => [{
|
212
|
+
# :status => '404',
|
213
|
+
# :detail => "could not find Acceptor records, ids: '#{acceptor_data[:id]}'"
|
214
|
+
# }]}
|
215
|
+
# )
|
216
|
+
|
217
|
+
# result = Flapjack::Diner.update_acceptors(:id => acceptor_data[:id], :time_restrictions => [])
|
218
|
+
# expect(result).to be_nil
|
219
|
+
# expect(Flapjack::Diner.last_error).to eq([{:status => '404',
|
220
|
+
# :detail => "could not find Acceptor records, ids: '#{acceptor_data[:id]}'"}])
|
221
|
+
# end
|
222
|
+
# end
|
223
|
+
|
224
|
+
context 'delete' do
|
225
|
+
|
226
|
+
it "submits a DELETE request for an acceptor" do
|
227
|
+
flapjack.given("an acceptor exists").
|
228
|
+
upon_receiving("a DELETE request for a single acceptor").
|
229
|
+
with(:method => :delete,
|
230
|
+
:path => "/acceptors/#{acceptor_data[:id]}",
|
231
|
+
:body => nil).
|
232
|
+
will_respond_with(:status => 204,
|
233
|
+
:body => '')
|
234
|
+
|
235
|
+
result = Flapjack::Diner.delete_acceptors(acceptor_data[:id])
|
236
|
+
expect(result).to be_a(TrueClass)
|
237
|
+
end
|
238
|
+
|
239
|
+
it "submits a DELETE request for several acceptors" do
|
240
|
+
acceptors_data = [{:type => 'acceptor', :id => acceptor_data[:id]},
|
241
|
+
{:type => 'acceptor', :id => acceptor_2_data[:id]}]
|
242
|
+
|
243
|
+
flapjack.given("two acceptors exist").
|
244
|
+
upon_receiving("a DELETE request for two acceptors").
|
245
|
+
with(:method => :delete,
|
246
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
247
|
+
:path => "/acceptors",
|
248
|
+
:body => {:data => acceptors_data}).
|
249
|
+
will_respond_with(:status => 204,
|
250
|
+
:body => '')
|
251
|
+
|
252
|
+
result = Flapjack::Diner.delete_acceptors(acceptor_data[:id], acceptor_2_data[:id])
|
253
|
+
expect(result).to be_a(TrueClass)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "can't find the acceptor to delete" do
|
257
|
+
flapjack.given("no data exists").
|
258
|
+
upon_receiving("a DELETE request for a single acceptor").
|
259
|
+
with(:method => :delete,
|
260
|
+
:path => "/acceptors/#{acceptor_data[:id]}",
|
261
|
+
:body => nil).
|
262
|
+
will_respond_with(
|
263
|
+
:status => 404,
|
264
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
265
|
+
:body => {:errors => [{
|
266
|
+
:status => '404',
|
267
|
+
:detail => "could not find Acceptor record, id: '#{acceptor_data[:id]}'"
|
268
|
+
}]}
|
269
|
+
)
|
270
|
+
|
271
|
+
result = Flapjack::Diner.delete_acceptors(acceptor_data[:id])
|
272
|
+
expect(result).to be_nil
|
273
|
+
expect(Flapjack::Diner.last_error).to eq([{:status => '404',
|
274
|
+
:detail => "could not find Acceptor record, id: '#{acceptor_data[:id]}'"}])
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|