flapjack-diner 2.0.0.pre.alpha.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -10
- data/README.md +165 -272
- data/flapjack-diner.gemspec +1 -1
- data/lib/flapjack-diner.rb +54 -25
- data/lib/flapjack-diner/argument_validator.rb +0 -17
- data/lib/flapjack-diner/configuration.rb +417 -0
- data/lib/flapjack-diner/log_formatter.rb +22 -0
- data/lib/flapjack-diner/query.rb +114 -0
- data/lib/flapjack-diner/relationships.rb +180 -0
- data/lib/flapjack-diner/request.rb +280 -0
- data/lib/flapjack-diner/resources.rb +64 -0
- data/lib/flapjack-diner/response.rb +91 -0
- data/lib/flapjack-diner/tools.rb +46 -456
- data/lib/flapjack-diner/utility.rb +16 -0
- data/lib/flapjack-diner/version.rb +1 -1
- data/spec/flapjack-diner_spec.rb +9 -18
- data/spec/{resources/relationships_spec.rb → relationships_spec.rb} +75 -29
- data/spec/resources/checks_spec.rb +7 -7
- data/spec/resources/contacts_spec.rb +21 -19
- data/spec/resources/events_spec.rb +13 -13
- data/spec/resources/maintenance_periods_spec.rb +3 -3
- data/spec/resources/media_spec.rb +3 -3
- data/spec/resources/metrics_spec.rb +1 -1
- data/spec/resources/rules_spec.rb +278 -0
- data/spec/resources/states_spec.rb +1 -1
- data/spec/resources/statistics_spec.rb +1 -1
- data/spec/resources/tags_spec.rb +75 -19
- data/spec/support/fixture_data.rb +57 -98
- metadata +21 -29
- data/.rubocop.yml +0 -21
- data/.rubocop_todo.yml +0 -135
- data/lib/flapjack-diner/resources/acceptors.rb +0 -77
- data/lib/flapjack-diner/resources/checks.rb +0 -52
- data/lib/flapjack-diner/resources/contacts.rb +0 -54
- data/lib/flapjack-diner/resources/events.rb +0 -54
- data/lib/flapjack-diner/resources/maintenance_periods.rb +0 -76
- data/lib/flapjack-diner/resources/media.rb +0 -75
- data/lib/flapjack-diner/resources/metrics.rb +0 -23
- data/lib/flapjack-diner/resources/rejectors.rb +0 -77
- data/lib/flapjack-diner/resources/relationships.rb +0 -314
- data/lib/flapjack-diner/resources/states.rb +0 -24
- data/lib/flapjack-diner/resources/statistics.rb +0 -24
- data/lib/flapjack-diner/resources/tags.rb +0 -47
- data/spec/resources/acceptors_spec.rb +0 -278
- data/spec/resources/rejectors_spec.rb +0 -278
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'json'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
require 'flapjack-diner/version'
|
6
|
-
require 'flapjack-diner/argument_validator'
|
7
|
-
|
8
|
-
module Flapjack
|
9
|
-
module Diner
|
10
|
-
module Resources
|
11
|
-
module States
|
12
|
-
def states(*args)
|
13
|
-
ids, data = unwrap_uuids(*args), unwrap_data(*args)
|
14
|
-
validate_params(data) do
|
15
|
-
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
16
|
-
validate :query => :filter, :as => :hash
|
17
|
-
validate :query => [:page, :per_page], :as => :positive_integer
|
18
|
-
end
|
19
|
-
perform_get('/states', ids, data)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'json'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
require 'flapjack-diner/version'
|
6
|
-
require 'flapjack-diner/argument_validator'
|
7
|
-
|
8
|
-
module Flapjack
|
9
|
-
module Diner
|
10
|
-
module Resources
|
11
|
-
module Statistics
|
12
|
-
def statistics(*args)
|
13
|
-
ids, data = unwrap_ids(*args), unwrap_data(*args)
|
14
|
-
validate_params(data) do
|
15
|
-
validate :query => :fields, :as => :string_or_array_of_strings
|
16
|
-
validate :query => :filter, :as => :hash
|
17
|
-
validate :query => [:page, :per_page], :as => :positive_integer
|
18
|
-
end
|
19
|
-
perform_get('/statistics', ids, data)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'json'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
require 'flapjack-diner/version'
|
6
|
-
require 'flapjack-diner/argument_validator'
|
7
|
-
|
8
|
-
module Flapjack
|
9
|
-
module Diner
|
10
|
-
module Resources
|
11
|
-
module Tags
|
12
|
-
def create_tags(*args)
|
13
|
-
data = unwrap_data(*args)
|
14
|
-
validate_params(data) do
|
15
|
-
validate :query => :name, :as => [:required, :non_empty_string]
|
16
|
-
validate :query => [:checks, :acceptors, :rejectors], :as => :multiple_link_uuid
|
17
|
-
end
|
18
|
-
perform_post(:tags, '/tags', data)
|
19
|
-
end
|
20
|
-
|
21
|
-
def tags(*args)
|
22
|
-
ids, data = unwrap_ids(*args), unwrap_data(*args)
|
23
|
-
validate_params(data) do
|
24
|
-
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
25
|
-
validate :query => :filter, :as => :hash
|
26
|
-
validate :query => [:page, :per_page], :as => :positive_integer
|
27
|
-
end
|
28
|
-
perform_get('/tags', ids, data)
|
29
|
-
end
|
30
|
-
|
31
|
-
def update_tags(*args)
|
32
|
-
data = unwrap_data(*args)
|
33
|
-
validate_params(data) do
|
34
|
-
validate :query => [:checks, :acceptors, :rejectors], :as => :multiple_link_uuid
|
35
|
-
end
|
36
|
-
perform_patch(:tags, "/tags", data)
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete_tags(*ids)
|
40
|
-
raise "'delete_tags' requires at least one tag ID " \
|
41
|
-
'parameter' if ids.nil? || ids.empty?
|
42
|
-
perform_delete(:tags, '/tags', *ids)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,278 +0,0 @@
|
|
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
|
@@ -1,278 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'flapjack-diner'
|
3
|
-
|
4
|
-
describe Flapjack::Diner::Resources::Rejectors, :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 a rejector" do
|
14
|
-
req_data = rejector_json(rejector_data).merge(
|
15
|
-
:relationships => {
|
16
|
-
:contact => {
|
17
|
-
:data => {
|
18
|
-
:type => 'contact',
|
19
|
-
:id => contact_data[:id]
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
23
|
-
)
|
24
|
-
resp_data = rejector_json(rejector_data).merge(:relationships => rejector_rel(rejector_data))
|
25
|
-
|
26
|
-
flapjack.given("a contact exists").
|
27
|
-
upon_receiving("a POST request with one rejector").
|
28
|
-
with(:method => :post, :path => '/rejectors',
|
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_rejectors(rejector_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 rejectors" do
|
43
|
-
req_data = [rejector_json(rejector_data).merge(
|
44
|
-
:relationships => {
|
45
|
-
:contact => {
|
46
|
-
:data => {
|
47
|
-
:type => 'contact',
|
48
|
-
:id => contact_data[:id]
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
), rejector_json(rejector_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
|
-
rejector_json(rejector_data).merge(:relationships => rejector_rel(rejector_data)),
|
64
|
-
rejector_json(rejector_2_data).merge(:relationships => rejector_rel(rejector_2_data))
|
65
|
-
]
|
66
|
-
|
67
|
-
flapjack.given("a contact exists").
|
68
|
-
upon_receiving("a POST request with two rejectors").
|
69
|
-
with(:method => :post, :path => '/rejectors',
|
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_rejectors(rejector_data.merge(:contact => contact_data[:id]),
|
79
|
-
rejector_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 rejectors" do
|
91
|
-
resp_data = [rejector_json(rejector_data).merge(:relationships => rejector_rel(rejector_data))]
|
92
|
-
|
93
|
-
flapjack.given("a rejector exists").
|
94
|
-
upon_receiving("a GET request for all rejectors").
|
95
|
-
with(:method => :get, :path => '/rejectors').
|
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.rejectors
|
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 rejector" do
|
107
|
-
resp_data = rejector_json(rejector_data).merge(:relationships => rejector_rel(rejector_data))
|
108
|
-
|
109
|
-
flapjack.given("a rejector exists").
|
110
|
-
upon_receiving("a GET request for a single rejector").
|
111
|
-
with(:method => :get, :path => "/rejectors/#{rejector_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.rejectors(rejector_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 rejectors" do
|
124
|
-
resp_data = [
|
125
|
-
rejector_json(rejector_data).merge(:relationships => rejector_rel(rejector_data)),
|
126
|
-
rejector_json(rejector_2_data).merge(:relationships => rejector_rel(rejector_2_data))
|
127
|
-
]
|
128
|
-
|
129
|
-
rejectors_data = [rejector_data.merge(:type => 'rejector'), rejector_2_data.merge(:type => 'rejector')]
|
130
|
-
|
131
|
-
flapjack.given("two rejectors exist").
|
132
|
-
upon_receiving("a GET request for two rejectors").
|
133
|
-
with(:method => :get, :path => "/rejectors",
|
134
|
-
:query => "filter%5B%5D=id%3A#{rejector_data[:id]}%7C#{rejector_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.rejectors(rejector_data[:id], rejector_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 rejector to read" do
|
146
|
-
flapjack.given("no data exists").
|
147
|
-
upon_receiving("a GET request for a single rejector").
|
148
|
-
with(:method => :get, :path => "/rejectors/#{rejector_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 Rejector record, id: '#{rejector_data[:id]}'"
|
155
|
-
}]}
|
156
|
-
)
|
157
|
-
|
158
|
-
result = Flapjack::Diner.rejectors(rejector_data[:id])
|
159
|
-
expect(result).to be_nil
|
160
|
-
expect(Flapjack::Diner.last_error).to eq([{:status => '404',
|
161
|
-
:detail => "could not find Rejector record, id: '#{rejector_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 a rejector' do
|
169
|
-
# flapjack.given("a rejector exists").
|
170
|
-
# upon_receiving("a PUT request for a single rejector").
|
171
|
-
# with(:method => :put,
|
172
|
-
# :path => "/rejectors/#{rejector_data[:id]}",
|
173
|
-
# :body => {:rejectors => {:id => rejector_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_rejectors(:id => rejector_data[:id], :time_restrictions => [])
|
180
|
-
# expect(result).to be_a(TrueClass)
|
181
|
-
# end
|
182
|
-
|
183
|
-
# it 'submits a PUT request for several rejectors' do
|
184
|
-
# flapjack.given("two rejectors exist").
|
185
|
-
# upon_receiving("a PUT request for two rejectors").
|
186
|
-
# with(:method => :put,
|
187
|
-
# :path => "/rejectors/#{rejector_data[:id]},#{rejector_2_data[:id]}",
|
188
|
-
# :body => {:rejectors => [{:id => rejector_data[:id], :time_restrictions => []},
|
189
|
-
# {:id => rejector_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_rejectors(
|
196
|
-
# {:id => rejector_data[:id], :time_restrictions => []},
|
197
|
-
# {:id => rejector_2_data[:id], :enabled => true})
|
198
|
-
# expect(result).to be_a(TrueClass)
|
199
|
-
# end
|
200
|
-
|
201
|
-
# it "can't find the rejector to update" do
|
202
|
-
# flapjack.given("no data exists").
|
203
|
-
# upon_receiving("a PUT request for a single rejector").
|
204
|
-
# with(:method => :put,
|
205
|
-
# :path => "/rejectors/#{rejector_data[:id]}",
|
206
|
-
# :body => {:rejectors => {:id => rejector_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 Rejector records, ids: '#{rejector_data[:id]}'"
|
214
|
-
# }]}
|
215
|
-
# )
|
216
|
-
|
217
|
-
# result = Flapjack::Diner.update_rejectors(:id => rejector_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 Rejector records, ids: '#{rejector_data[:id]}'"}])
|
221
|
-
# end
|
222
|
-
# end
|
223
|
-
|
224
|
-
context 'delete' do
|
225
|
-
|
226
|
-
it "submits a DELETE request for a rejector" do
|
227
|
-
flapjack.given("a rejector exists").
|
228
|
-
upon_receiving("a DELETE request for a single rejector").
|
229
|
-
with(:method => :delete,
|
230
|
-
:path => "/rejectors/#{rejector_data[:id]}",
|
231
|
-
:body => nil).
|
232
|
-
will_respond_with(:status => 204,
|
233
|
-
:body => '')
|
234
|
-
|
235
|
-
result = Flapjack::Diner.delete_rejectors(rejector_data[:id])
|
236
|
-
expect(result).to be_a(TrueClass)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "submits a DELETE request for several rejectors" do
|
240
|
-
rejectors_data = [{:type => 'rejector', :id => rejector_data[:id]},
|
241
|
-
{:type => 'rejector', :id => rejector_2_data[:id]}]
|
242
|
-
|
243
|
-
flapjack.given("two rejectors exist").
|
244
|
-
upon_receiving("a DELETE request for two rejectors").
|
245
|
-
with(:method => :delete,
|
246
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
247
|
-
:path => "/rejectors",
|
248
|
-
:body => {:data => rejectors_data}).
|
249
|
-
will_respond_with(:status => 204,
|
250
|
-
:body => '')
|
251
|
-
|
252
|
-
result = Flapjack::Diner.delete_rejectors(rejector_data[:id], rejector_2_data[:id])
|
253
|
-
expect(result).to be_a(TrueClass)
|
254
|
-
end
|
255
|
-
|
256
|
-
it "can't find the rejector to delete" do
|
257
|
-
flapjack.given("no data exists").
|
258
|
-
upon_receiving("a DELETE request for a single rejector").
|
259
|
-
with(:method => :delete,
|
260
|
-
:path => "/rejectors/#{rejector_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 Rejector record, id: '#{rejector_data[:id]}'"
|
268
|
-
}]}
|
269
|
-
)
|
270
|
-
|
271
|
-
result = Flapjack::Diner.delete_rejectors(rejector_data[:id])
|
272
|
-
expect(result).to be_nil
|
273
|
-
expect(Flapjack::Diner.last_error).to eq([{:status => '404',
|
274
|
-
:detail => "could not find Rejector record, id: '#{rejector_data[:id]}'"}])
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
end
|