flapjack-diner 1.4.0 → 2.0.0.a4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/README.md +620 -413
- data/flapjack-diner.gemspec +1 -1
- data/lib/flapjack-diner/argument_validator.rb +77 -7
- data/lib/flapjack-diner/configuration.rb +409 -0
- data/lib/flapjack-diner/index_range.rb +42 -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 +47 -251
- data/lib/flapjack-diner/utility.rb +16 -0
- data/lib/flapjack-diner/version.rb +1 -1
- data/lib/flapjack-diner.rb +54 -20
- data/spec/argument_validator_spec.rb +87 -28
- data/spec/flapjack-diner_spec.rb +42 -64
- data/spec/relationships_spec.rb +211 -0
- data/spec/resources/checks_spec.rb +219 -79
- data/spec/resources/contacts_spec.rb +179 -151
- data/spec/resources/events_spec.rb +208 -0
- data/spec/resources/maintenance_periods_spec.rb +177 -565
- data/spec/resources/media_spec.rb +157 -171
- data/spec/resources/metrics_spec.rb +45 -0
- data/spec/resources/rules_spec.rb +278 -0
- data/spec/resources/states_spec.rb +93 -0
- data/spec/resources/statistics_spec.rb +53 -0
- data/spec/resources/tags_spec.rb +243 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/fixture_data.rb +541 -0
- metadata +33 -31
- data/.rubocop.yml +0 -21
- data/.rubocop_todo.yml +0 -135
- data/lib/flapjack-diner/resources/checks.rb +0 -64
- data/lib/flapjack-diner/resources/contacts.rb +0 -70
- data/lib/flapjack-diner/resources/entities.rb +0 -68
- data/lib/flapjack-diner/resources/maintenance_periods.rb +0 -82
- data/lib/flapjack-diner/resources/media.rb +0 -61
- data/lib/flapjack-diner/resources/notification_rules.rb +0 -66
- data/lib/flapjack-diner/resources/notifications.rb +0 -28
- data/lib/flapjack-diner/resources/pagerduty_credentials.rb +0 -59
- data/lib/flapjack-diner/resources/reports.rb +0 -33
- data/spec/pacts/flapjack-diner-flapjack.json +0 -4515
- data/spec/resources/entities_spec.rb +0 -181
- data/spec/resources/notification_rules_spec.rb +0 -341
- data/spec/resources/notifications_spec.rb +0 -208
- data/spec/resources/pagerduty_credentials_spec.rb +0 -237
- data/spec/resources/reports_spec.rb +0 -255
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack-diner'
|
3
|
+
|
4
|
+
describe Flapjack::Diner::Resources, :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 rule" do
|
14
|
+
req_data = rule_json(rule_data).merge(
|
15
|
+
:relationships => {
|
16
|
+
:contact => {
|
17
|
+
:data => {
|
18
|
+
:type => 'contact',
|
19
|
+
:id => contact_data[:id]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
)
|
24
|
+
resp_data = rule_json(rule_data).merge(:relationships => rule_rel(rule_data))
|
25
|
+
|
26
|
+
flapjack.given("a contact exists").
|
27
|
+
upon_receiving("a POST request with one rule").
|
28
|
+
with(:method => :post, :path => '/rules',
|
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_rules(rule_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 rules" do
|
43
|
+
req_data = [rule_json(rule_data).merge(
|
44
|
+
:relationships => {
|
45
|
+
:contact => {
|
46
|
+
:data => {
|
47
|
+
:type => 'contact',
|
48
|
+
:id => contact_data[:id]
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
), rule_json(rule_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
|
+
rule_json(rule_data).merge(:relationships => rule_rel(rule_data)),
|
64
|
+
rule_json(rule_2_data).merge(:relationships => rule_rel(rule_2_data))
|
65
|
+
]
|
66
|
+
|
67
|
+
flapjack.given("a contact exists").
|
68
|
+
upon_receiving("a POST request with two rules").
|
69
|
+
with(:method => :post, :path => '/rules',
|
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_rules(rule_data.merge(:contact => contact_data[:id]),
|
79
|
+
rule_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 rules" do
|
91
|
+
resp_data = [rule_json(rule_data).merge(:relationships => rule_rel(rule_data))]
|
92
|
+
|
93
|
+
flapjack.given("a rule exists").
|
94
|
+
upon_receiving("a GET request for all rules").
|
95
|
+
with(:method => :get, :path => '/rules').
|
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.rules
|
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 rule" do
|
107
|
+
resp_data = rule_json(rule_data).merge(:relationships => rule_rel(rule_data))
|
108
|
+
|
109
|
+
flapjack.given("a rule exists").
|
110
|
+
upon_receiving("a GET request for a single rule").
|
111
|
+
with(:method => :get, :path => "/rules/#{rule_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.rules(rule_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 rules" do
|
124
|
+
resp_data = [
|
125
|
+
rule_json(rule_data).merge(:relationships => rule_rel(rule_data)),
|
126
|
+
rule_json(rule_2_data).merge(:relationships => rule_rel(rule_2_data))
|
127
|
+
]
|
128
|
+
|
129
|
+
rules_data = [rule_data.merge(:type => 'rule'), rule_2_data.merge(:type => 'rule')]
|
130
|
+
|
131
|
+
flapjack.given("two rules exist").
|
132
|
+
upon_receiving("a GET request for two rules").
|
133
|
+
with(:method => :get, :path => "/rules",
|
134
|
+
:query => "filter%5B%5D=id%3A#{rule_data[:id]}%7C#{rule_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.rules(rule_data[:id], rule_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 rule to read" do
|
146
|
+
flapjack.given("no data exists").
|
147
|
+
upon_receiving("a GET request for a single rule").
|
148
|
+
with(:method => :get, :path => "/rules/#{rule_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 Rule record, id: '#{rule_data[:id]}'"
|
155
|
+
}]}
|
156
|
+
)
|
157
|
+
|
158
|
+
result = Flapjack::Diner.rules(rule_data[:id])
|
159
|
+
expect(result).to be_nil
|
160
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
161
|
+
:detail => "could not find Rule record, id: '#{rule_data[:id]}'"}])
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'update' do
|
167
|
+
|
168
|
+
it 'submits a PATCH request for a rule' do
|
169
|
+
flapjack.given("a rule exists").
|
170
|
+
upon_receiving("a PATCH request for a single rule").
|
171
|
+
with(:method => :patch,
|
172
|
+
:path => "/rules/#{rule_data[:id]}",
|
173
|
+
:body => {:data => {:id => rule_data[:id], :type => 'rule', :attributes => {:strategy => 'global'}}},
|
174
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
175
|
+
will_respond_with(
|
176
|
+
:status => 204,
|
177
|
+
:body => '' )
|
178
|
+
|
179
|
+
result = Flapjack::Diner.update_rules(:id => rule_data[:id], :strategy => 'global')
|
180
|
+
expect(result).to be_a(TrueClass)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'submits a PATCH request for several rules' do
|
184
|
+
flapjack.given("two rules exist").
|
185
|
+
upon_receiving("a PATCH request for two rules").
|
186
|
+
with(:method => :patch,
|
187
|
+
:path => "/rules",
|
188
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
189
|
+
:body => {:data => [{:id => rule_data[:id], :type => 'rule', :attributes => {:conditions_list => 'warning'}},
|
190
|
+
{:id => rule_2_data[:id], :type => 'rule', :attributes => {:strategy => 'any_tag'}}]}).
|
191
|
+
will_respond_with(
|
192
|
+
:status => 204,
|
193
|
+
:body => '' )
|
194
|
+
|
195
|
+
result = Flapjack::Diner.update_rules(
|
196
|
+
{:id => rule_data[:id], :conditions_list => 'warning'},
|
197
|
+
{:id => rule_2_data[:id], :strategy => 'any_tag'})
|
198
|
+
expect(result).to be_a(TrueClass)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "can't find the rule to update" do
|
202
|
+
flapjack.given("no data exists").
|
203
|
+
upon_receiving("a PATCH request for a single rule").
|
204
|
+
with(:method => :patch,
|
205
|
+
:path => "/rules/#{rule_data[:id]}",
|
206
|
+
:body => {:data => {:id => rule_data[:id], :type => 'rule', :attributes => {:strategy => 'global'}}},
|
207
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
208
|
+
will_respond_with(
|
209
|
+
:status => 404,
|
210
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
211
|
+
:body => {:errors => [{
|
212
|
+
:status => '404',
|
213
|
+
:detail => "could not find Rule record, id: '#{rule_data[:id]}'"
|
214
|
+
}]}
|
215
|
+
)
|
216
|
+
|
217
|
+
result = Flapjack::Diner.update_rules(:id => rule_data[:id], :strategy => 'global')
|
218
|
+
expect(result).to be_nil
|
219
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
220
|
+
:detail => "could not find Rule record, id: '#{rule_data[:id]}'"}])
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'delete' do
|
225
|
+
|
226
|
+
it "submits a DELETE request for an rule" do
|
227
|
+
flapjack.given("a rule exists").
|
228
|
+
upon_receiving("a DELETE request for a single rule").
|
229
|
+
with(:method => :delete,
|
230
|
+
:path => "/rules/#{rule_data[:id]}",
|
231
|
+
:body => nil).
|
232
|
+
will_respond_with(:status => 204,
|
233
|
+
:body => '')
|
234
|
+
|
235
|
+
result = Flapjack::Diner.delete_rules(rule_data[:id])
|
236
|
+
expect(result).to be_a(TrueClass)
|
237
|
+
end
|
238
|
+
|
239
|
+
it "submits a DELETE request for several rules" do
|
240
|
+
rules_data = [{:type => 'rule', :id => rule_data[:id]},
|
241
|
+
{:type => 'rule', :id => rule_2_data[:id]}]
|
242
|
+
|
243
|
+
flapjack.given("two rules exist").
|
244
|
+
upon_receiving("a DELETE request for two rules").
|
245
|
+
with(:method => :delete,
|
246
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
247
|
+
:path => "/rules",
|
248
|
+
:body => {:data => rules_data}).
|
249
|
+
will_respond_with(:status => 204,
|
250
|
+
:body => '')
|
251
|
+
|
252
|
+
result = Flapjack::Diner.delete_rules(rule_data[:id], rule_2_data[:id])
|
253
|
+
expect(result).to be_a(TrueClass)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "can't find the rule to delete" do
|
257
|
+
flapjack.given("no data exists").
|
258
|
+
upon_receiving("a DELETE request for a single rule").
|
259
|
+
with(:method => :delete,
|
260
|
+
:path => "/rules/#{rule_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 Rule record, id: '#{rule_data[:id]}'"
|
268
|
+
}]}
|
269
|
+
)
|
270
|
+
|
271
|
+
result = Flapjack::Diner.delete_rules(rule_data[:id])
|
272
|
+
expect(result).to be_nil
|
273
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
274
|
+
:detail => "could not find Rule record, id: '#{rule_data[:id]}'"}])
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack-diner'
|
3
|
+
require 'flapjack-diner/index_range'
|
4
|
+
|
5
|
+
describe Flapjack::Diner::Resources, :pact => true do
|
6
|
+
|
7
|
+
let(:time) { Time.now }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
Flapjack::Diner.base_uri('localhost:19081')
|
11
|
+
Flapjack::Diner.logger = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'get' do
|
15
|
+
|
16
|
+
it 'gets a single state' do
|
17
|
+
resp_data = state_json(state_data).merge(:relationships => state_rel(state_data))
|
18
|
+
result_data = resultify(state_json(state_data).merge(:relationships => state_rel(state_data)))
|
19
|
+
|
20
|
+
[:created_at, :updated_at].each do |t|
|
21
|
+
resp_data[:attributes][t] = Pact::Term.new(
|
22
|
+
:generate => state_data[t],
|
23
|
+
:matcher => /\A#{ISO8601_PAT}\z/
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
flapjack.given("a state exists").
|
28
|
+
upon_receiving("a GET request for a single state").
|
29
|
+
with(:method => :get,
|
30
|
+
:path => "/states/#{state_data[:id]}").
|
31
|
+
will_respond_with(
|
32
|
+
:status => 200,
|
33
|
+
:body => {:data => resp_data})
|
34
|
+
|
35
|
+
result = Flapjack::Diner.states(state_data[:id])
|
36
|
+
expect(result).to eq(result_data)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'gets all states' do
|
40
|
+
resp_data = [state_json(state_data).merge(:relationships => state_rel(state_data))]
|
41
|
+
result_data = resultify([state_json(state_data).merge(:relationships => state_rel(state_data))])
|
42
|
+
|
43
|
+
[:created_at, :updated_at].each do |t|
|
44
|
+
resp_data.first[:attributes][t] = Pact::Term.new(
|
45
|
+
:generate => state_data[t],
|
46
|
+
:matcher => /\A#{ISO8601_PAT}\z/
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
flapjack.given("a state exists").
|
51
|
+
upon_receiving("a GET request for all states").
|
52
|
+
with(:method => :get,
|
53
|
+
:path => "/states").
|
54
|
+
will_respond_with(
|
55
|
+
:status => 200,
|
56
|
+
:body => {:data => resp_data})
|
57
|
+
|
58
|
+
result = Flapjack::Diner.states
|
59
|
+
expect(result).to eq(result_data)
|
60
|
+
end
|
61
|
+
|
62
|
+
# pact won't pass if run later than a closed date range (or in a time earlier
|
63
|
+
# than what's provided, but that's less of a concern assuming clocks are sane)
|
64
|
+
it 'gets all states in a date range unbounded on upper side' do
|
65
|
+
resp_data = [state_json(state_data).merge(:relationships => state_rel(state_data))]
|
66
|
+
result_data = resultify([state_json(state_data).merge(:relationships => state_rel(state_data))])
|
67
|
+
|
68
|
+
[:created_at, :updated_at].each do |t|
|
69
|
+
resp_data.first[:attributes][t] = Pact::Term.new(
|
70
|
+
:generate => state_data[t],
|
71
|
+
:matcher => /\A#{ISO8601_PAT}\z/
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
st = fixture_time - 60
|
76
|
+
|
77
|
+
flapjack.given("a state exists").
|
78
|
+
upon_receiving("a GET request for all states within a date range").
|
79
|
+
with(:method => :get,
|
80
|
+
:path => '/states',
|
81
|
+
:query => "filter%5B%5D=created_at%3A#{CGI::escape(st.iso8601)}..").
|
82
|
+
will_respond_with(
|
83
|
+
:status => 200,
|
84
|
+
:body => {:data => resp_data})
|
85
|
+
|
86
|
+
filt = {:created_at => Flapjack::Diner::IndexRange.new(st, nil)}
|
87
|
+
result = Flapjack::Diner.states(:filter => filt)
|
88
|
+
expect(result).to eq(result_data)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack-diner'
|
3
|
+
|
4
|
+
describe Flapjack::Diner::Resources, :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 'read' do
|
12
|
+
it 'gets all statistics' do
|
13
|
+
resp_data = [global_statistics_json]
|
14
|
+
resp_data.first[:attributes][:created_at] = Pact::Term.new(
|
15
|
+
:generate => global_statistics_data[:created_at],
|
16
|
+
:matcher => /\A#{ISO8601_PAT}\z/
|
17
|
+
)
|
18
|
+
|
19
|
+
flapjack.given("a global statistics object exists").
|
20
|
+
upon_receiving("a GET request for all statistics").
|
21
|
+
with(:method => :get, :path => '/statistics').
|
22
|
+
will_respond_with(
|
23
|
+
:status => 200,
|
24
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
25
|
+
:body => {:data => resp_data})
|
26
|
+
|
27
|
+
result = Flapjack::Diner.statistics
|
28
|
+
expect(result).to eq(resultify([global_statistics_json]))
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'gets global statistics' do
|
32
|
+
resp_data = [global_statistics_json]
|
33
|
+
|
34
|
+
resp_data.first[:attributes][:created_at] = Pact::Term.new(
|
35
|
+
:generate => global_statistics_data[:created_at],
|
36
|
+
:matcher => /\A#{ISO8601_PAT}\z/
|
37
|
+
)
|
38
|
+
|
39
|
+
flapjack.given("a global statistics object exists").
|
40
|
+
upon_receiving("a GET request for some statistics").
|
41
|
+
with(:method => :get, :path => '/statistics',
|
42
|
+
:query => 'filter%5B%5D=instance_name%3Aglobal').
|
43
|
+
will_respond_with(
|
44
|
+
:status => 200,
|
45
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
46
|
+
:body => {:data => resp_data})
|
47
|
+
|
48
|
+
result = Flapjack::Diner.statistics(:filter => {:instance_name => global_statistics_data[:instance_name]})
|
49
|
+
expect(result).to eq(resultify([global_statistics_json]))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack-diner'
|
3
|
+
|
4
|
+
describe Flapjack::Diner::Resources, :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 tag" do
|
14
|
+
req_data = tag_json(tag_data)
|
15
|
+
resp_data = req_data.merge(:relationships => tag_rel(tag_data))
|
16
|
+
|
17
|
+
flapjack.given("no data exists").
|
18
|
+
upon_receiving("a POST request with one tag").
|
19
|
+
with(:method => :post, :path => '/tags',
|
20
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
21
|
+
:body => {:data => req_data}).
|
22
|
+
will_respond_with(
|
23
|
+
:status => 201,
|
24
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
25
|
+
:body => {:data => resp_data}
|
26
|
+
)
|
27
|
+
|
28
|
+
result = Flapjack::Diner.create_tags(tag_data)
|
29
|
+
expect(result).to eq(resultify(resp_data))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "submits a POST request for several tags" do
|
33
|
+
req_data = [tag_json(tag_data), tag_json(tag_2_data)]
|
34
|
+
resp_data = [
|
35
|
+
req_data[0].merge(:relationships => tag_rel(tag_data)),
|
36
|
+
req_data[1].merge(:relationships => tag_rel(tag_2_data))
|
37
|
+
]
|
38
|
+
|
39
|
+
flapjack.given("no data exists").
|
40
|
+
upon_receiving("a POST request with two tags").
|
41
|
+
with(:method => :post, :path => '/tags',
|
42
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
43
|
+
:body => {:data => req_data}).
|
44
|
+
will_respond_with(
|
45
|
+
:status => 201,
|
46
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
47
|
+
:body => {'data' => resp_data}
|
48
|
+
)
|
49
|
+
|
50
|
+
result = Flapjack::Diner.create_tags(tag_data, tag_2_data)
|
51
|
+
expect(result).to eq(resultify(resp_data))
|
52
|
+
end
|
53
|
+
|
54
|
+
# TODO fails to create with invalid data
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'read' do
|
58
|
+
|
59
|
+
context 'GET all tags' do
|
60
|
+
|
61
|
+
it "has no data" do
|
62
|
+
flapjack.given("no data exists").
|
63
|
+
upon_receiving("a GET request for all tags").
|
64
|
+
with(:method => :get, :path => '/tags').
|
65
|
+
will_respond_with(
|
66
|
+
:status => 200,
|
67
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
68
|
+
:body => {:data => []} )
|
69
|
+
|
70
|
+
result = Flapjack::Diner.tags
|
71
|
+
expect(result).to eq([])
|
72
|
+
end
|
73
|
+
|
74
|
+
it "has some data" do
|
75
|
+
resp_data = [tag_json(tag_data).merge(:relationships => tag_rel(tag_data))]
|
76
|
+
|
77
|
+
flapjack.given("a tag exists").
|
78
|
+
upon_receiving("a GET request for all tags").
|
79
|
+
with(:method => :get, :path => '/tags').
|
80
|
+
will_respond_with(
|
81
|
+
:status => 200,
|
82
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
83
|
+
:body => {:data => resp_data} )
|
84
|
+
|
85
|
+
result = Flapjack::Diner.tags
|
86
|
+
expect(result).to eq(resultify(resp_data))
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'GET a single tag' do
|
92
|
+
|
93
|
+
it "has some data" do
|
94
|
+
resp_data = tag_json(tag_data).merge(:relationships => tag_rel(tag_data))
|
95
|
+
|
96
|
+
flapjack.given("a tag exists").
|
97
|
+
upon_receiving("a GET request for tag 'www.example.com:SSH'").
|
98
|
+
with(:method => :get, :path => "/tags/#{tag_data[:id]}").
|
99
|
+
will_respond_with(
|
100
|
+
:status => 200,
|
101
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
102
|
+
:body => {:data => resp_data} )
|
103
|
+
|
104
|
+
result = Flapjack::Diner.tags(tag_data[:id])
|
105
|
+
expect(result).to eq(resultify(resp_data))
|
106
|
+
end
|
107
|
+
|
108
|
+
it "can't find tag" do
|
109
|
+
flapjack.given("no data exists").
|
110
|
+
upon_receiving("a GET request for tag 'www.example.com:SSH'").
|
111
|
+
with(:method => :get, :path => "/tags/#{tag_data[:id]}").
|
112
|
+
will_respond_with(
|
113
|
+
:status => 404,
|
114
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
115
|
+
:body => {:errors => [{
|
116
|
+
:status => '404',
|
117
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"
|
118
|
+
}]}
|
119
|
+
)
|
120
|
+
|
121
|
+
result = Flapjack::Diner.tags(tag_data[:id])
|
122
|
+
expect(result).to be_nil
|
123
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
124
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"}])
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'update' do
|
132
|
+
|
133
|
+
it 'submits a PATCH request for a tag' do
|
134
|
+
flapjack.given("a tag exists").
|
135
|
+
upon_receiving("a PATCH request for a single tag").
|
136
|
+
with(:method => :patch,
|
137
|
+
:path => "/tags/#{tag_data[:id]}",
|
138
|
+
:body => {:data => {:id => tag_data[:id], :type => 'tag', :attributes => {:name => 'database_only'}}},
|
139
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
140
|
+
will_respond_with(
|
141
|
+
:status => 204,
|
142
|
+
:body => '' )
|
143
|
+
|
144
|
+
result = Flapjack::Diner.update_tags(:id => tag_data[:id], :name => 'database_only')
|
145
|
+
expect(result).to be_a(TrueClass)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'submits a PATCH request for several tags' do
|
149
|
+
flapjack.given("two tags exist").
|
150
|
+
upon_receiving("a PATCH request for two tags").
|
151
|
+
with(:method => :patch,
|
152
|
+
:path => "/tags",
|
153
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
154
|
+
:body => {:data => [{:id => tag_data[:id], :type => 'tag', :attributes => {:name => 'database_only'}},
|
155
|
+
{:id => tag_2_data[:id], :type => 'tag', :attributes => {:name => 'app_only'}}]}).
|
156
|
+
will_respond_with(
|
157
|
+
:status => 204,
|
158
|
+
:body => '' )
|
159
|
+
|
160
|
+
result = Flapjack::Diner.update_tags(
|
161
|
+
{:id => tag_data[:id], :name => 'database_only'},
|
162
|
+
{:id => tag_2_data[:id], :name => 'app_only'})
|
163
|
+
expect(result).to be_a(TrueClass)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "can't find the tag to update" do
|
167
|
+
flapjack.given("no data exists").
|
168
|
+
upon_receiving("a PATCH request for a single tag").
|
169
|
+
with(:method => :patch,
|
170
|
+
:path => "/tags/#{tag_data[:id]}",
|
171
|
+
:body => {:data => {:id => tag_data[:id], :type => 'tag', :attributes => {:name => 'database_only'}}},
|
172
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
173
|
+
will_respond_with(
|
174
|
+
:status => 404,
|
175
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
176
|
+
:body => {:errors => [{
|
177
|
+
:status => '404',
|
178
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"
|
179
|
+
}]}
|
180
|
+
)
|
181
|
+
|
182
|
+
result = Flapjack::Diner.update_tags(:id => tag_data[:id], :name => 'database_only')
|
183
|
+
expect(result).to be_nil
|
184
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
185
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"}])
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'delete' do
|
190
|
+
|
191
|
+
it "submits a DELETE request for a tag" do
|
192
|
+
flapjack.given("a tag exists").
|
193
|
+
upon_receiving("a DELETE request for a single tag").
|
194
|
+
with(:method => :delete,
|
195
|
+
:path => "/tags/#{tag_data[:id]}",
|
196
|
+
:body => nil).
|
197
|
+
will_respond_with(:status => 204,
|
198
|
+
:body => '')
|
199
|
+
|
200
|
+
result = Flapjack::Diner.delete_tags(tag_data[:id])
|
201
|
+
expect(result).to be_a(TrueClass)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "submits a DELETE request for several tags" do
|
205
|
+
tags_data = [{:type => 'tag', :id => tag_data[:id]},
|
206
|
+
{:type => 'tag', :id => tag_2_data[:id]}]
|
207
|
+
|
208
|
+
flapjack.given("two tags exist").
|
209
|
+
upon_receiving("a DELETE request for two tags").
|
210
|
+
with(:method => :delete,
|
211
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
212
|
+
:path => "/tags",
|
213
|
+
:body => {:data => tags_data}).
|
214
|
+
will_respond_with(:status => 204,
|
215
|
+
:body => '')
|
216
|
+
|
217
|
+
result = Flapjack::Diner.delete_tags(tag_data[:id], tag_2_data[:id])
|
218
|
+
expect(result).to be_a(TrueClass)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "can't find the tag to delete" do
|
222
|
+
flapjack.given("no data exists").
|
223
|
+
upon_receiving("a DELETE request for a single tag").
|
224
|
+
with(:method => :delete,
|
225
|
+
:path => "/tags/#{tag_data[:id]}",
|
226
|
+
:body => nil).
|
227
|
+
will_respond_with(
|
228
|
+
:status => 404,
|
229
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
230
|
+
:body => {:errors => [{
|
231
|
+
:status => '404',
|
232
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"
|
233
|
+
}]}
|
234
|
+
)
|
235
|
+
|
236
|
+
result = Flapjack::Diner.delete_tags(tag_data[:id])
|
237
|
+
expect(result).to be_nil
|
238
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
239
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"}])
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|