flapjack-diner 2.0.0b1 → 2.0.0.pre.alpha.1

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +21 -0
  3. data/.rubocop_todo.yml +135 -0
  4. data/.travis.yml +10 -5
  5. data/README.md +125 -143
  6. data/flapjack-diner.gemspec +1 -1
  7. data/lib/flapjack-diner.rb +24 -54
  8. data/lib/flapjack-diner/argument_validator.rb +17 -0
  9. data/lib/flapjack-diner/resources/checks.rb +52 -0
  10. data/lib/flapjack-diner/resources/contacts.rb +54 -0
  11. data/lib/flapjack-diner/resources/events.rb +54 -0
  12. data/lib/flapjack-diner/resources/maintenance_periods.rb +76 -0
  13. data/lib/flapjack-diner/resources/media.rb +75 -0
  14. data/lib/flapjack-diner/resources/metrics.rb +23 -0
  15. data/lib/flapjack-diner/resources/relationships.rb +275 -0
  16. data/lib/flapjack-diner/resources/rules.rb +75 -0
  17. data/lib/flapjack-diner/resources/states.rb +24 -0
  18. data/lib/flapjack-diner/resources/statistics.rb +24 -0
  19. data/lib/flapjack-diner/resources/tags.rb +47 -0
  20. data/lib/flapjack-diner/tools.rb +456 -46
  21. data/lib/flapjack-diner/version.rb +1 -1
  22. data/spec/flapjack-diner_spec.rb +18 -9
  23. data/spec/resources/checks_spec.rb +7 -7
  24. data/spec/resources/contacts_spec.rb +12 -14
  25. data/spec/resources/events_spec.rb +13 -13
  26. data/spec/resources/maintenance_periods_spec.rb +3 -3
  27. data/spec/resources/media_spec.rb +3 -3
  28. data/spec/resources/metrics_spec.rb +1 -1
  29. data/spec/{relationships_spec.rb → resources/relationships_spec.rb} +25 -71
  30. data/spec/resources/rules_spec.rb +62 -62
  31. data/spec/resources/states_spec.rb +1 -1
  32. data/spec/resources/statistics_spec.rb +1 -1
  33. data/spec/resources/tags_spec.rb +19 -75
  34. data/spec/support/fixture_data.rb +43 -80
  35. metadata +22 -17
  36. data/lib/flapjack-diner/configuration.rb +0 -417
  37. data/lib/flapjack-diner/log_formatter.rb +0 -22
  38. data/lib/flapjack-diner/query.rb +0 -114
  39. data/lib/flapjack-diner/relationships.rb +0 -180
  40. data/lib/flapjack-diner/request.rb +0 -280
  41. data/lib/flapjack-diner/resources.rb +0 -64
  42. data/lib/flapjack-diner/response.rb +0 -91
  43. data/lib/flapjack-diner/utility.rb +0 -16
@@ -1,5 +1,5 @@
1
1
  module Flapjack
2
2
  module Diner
3
- VERSION = '2.0.0b1'
3
+ VERSION = '2.0.0-alpha.1'
4
4
  end
5
5
  end
@@ -3,6 +3,8 @@ require 'flapjack-diner'
3
3
 
4
4
  describe Flapjack::Diner do
5
5
 
6
+ # include_context 'fixture data'
7
+
6
8
  let(:server) { 'flapjack.com' }
7
9
 
8
10
  let(:time) { Time.now }
@@ -16,9 +18,9 @@ describe Flapjack::Diner do
16
18
  WebMock.reset!
17
19
  end
18
20
 
19
- # context 'argument parsing' do
21
+ context 'argument parsing' do
20
22
 
21
- # end
23
+ end
22
24
 
23
25
  context 'keys as strings' do
24
26
 
@@ -39,8 +41,8 @@ describe Flapjack::Diner do
39
41
  expect(result).not_to be_nil
40
42
  expect(result).to be_an_instance_of(Array)
41
43
  expect(result.length).to be(1)
42
- expect(result.first).to be_an_instance_of(Hash)
43
- expect(result.first).to have_key('id')
44
+ expect(result[0]).to be_an_instance_of(Hash)
45
+ expect(result[0]).to have_key('id')
44
46
  end
45
47
 
46
48
  end
@@ -58,7 +60,9 @@ describe Flapjack::Diner do
58
60
  req = stub_request(:get, "http://#{server}/contacts").
59
61
  to_return(:body => response)
60
62
 
61
- expect(logger).to receive(:info).with(%r{\[Flapjack::Diner\] \[[^\]]+\] 200 "GET /contacts" - $})
63
+ expect(logger).to receive(:info).with("GET http://#{server}/contacts")
64
+ expect(logger).to receive(:info).with(" Response Code: 200")
65
+ expect(logger).to receive(:info).with(" Response Body: #{response}")
62
66
 
63
67
  result = Flapjack::Diner.contacts
64
68
  expect(req).to have_been_requested
@@ -78,8 +82,10 @@ describe Flapjack::Diner do
78
82
  response = {:data => resp_data}.to_json
79
83
  req = stub_request(:post, "http://#{server}/test_notifications").
80
84
  to_return(:status => 201, :body => response)
81
-
82
- expect(logger).to receive(:info).with(%r{\[Flapjack::Diner\] \[[^\]]+\] 201 "POST /test_notifications" - $})
85
+ expect(logger).to receive(:info).with("POST http://#{server}/test_notifications\n" +
86
+ " Body: {:data=>#{req_data.inspect}}")
87
+ expect(logger).to receive(:info).with(" Response Code: 201")
88
+ expect(logger).to receive(:info).with(" Response Body: #{response}")
83
89
 
84
90
  result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:check => check_data[:id]))
85
91
  expect(req).to have_been_requested
@@ -90,8 +96,8 @@ describe Flapjack::Diner do
90
96
  req = stub_request(:delete, "http://#{server}/scheduled_maintenances/#{scheduled_maintenance_data[:id]}").
91
97
  to_return(:status => 204)
92
98
 
93
- expect(logger).to receive(:info).
94
- with(%r{\[Flapjack::Diner\] \[[^\]]+\] 204 "DELETE /scheduled_maintenances/#{scheduled_maintenance_data[:id]}" - $})
99
+ expect(logger).to receive(:info).with("DELETE http://#{server}/scheduled_maintenances/#{scheduled_maintenance_data[:id]}")
100
+ expect(logger).to receive(:info).with(" Response Code: 204")
95
101
 
96
102
  result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id])
97
103
  expect(req).to have_been_requested
@@ -101,6 +107,7 @@ describe Flapjack::Diner do
101
107
  end
102
108
 
103
109
  context "problems" do
110
+
104
111
  it "raises an exception on network failure" do
105
112
  req = stub_request(:get, "http://#{server}/contacts").to_timeout
106
113
 
@@ -138,5 +145,7 @@ describe Flapjack::Diner do
138
145
  }.to raise_error(ArgumentError)
139
146
  expect(req).not_to have_been_requested
140
147
  end
148
+
141
149
  end
150
+
142
151
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources, :pact => true do
4
+ describe Flapjack::Diner::Resources::Checks, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -55,7 +55,7 @@ describe Flapjack::Diner::Resources, :pact => true do
55
55
  req_data = check_json(check_data).merge(
56
56
  :relationships => {
57
57
  :tags => {
58
- :data => [{:type => 'tag', :id => tag_data[:id]}]
58
+ :data => [{:type => 'tag', :id => tag_data[:name]}]
59
59
  }
60
60
  }
61
61
  )
@@ -71,7 +71,7 @@ describe Flapjack::Diner::Resources, :pact => true do
71
71
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
72
72
  :body => {:data => resp_data})
73
73
 
74
- result = Flapjack::Diner.create_checks(check_data.merge(:tags => [tag_data[:id]]))
74
+ result = Flapjack::Diner.create_checks(check_data.merge(:tags => [tag_data[:name]]))
75
75
  expect(result).to eq(resultify(resp_data))
76
76
  end
77
77
 
@@ -218,7 +218,7 @@ describe Flapjack::Diner::Resources, :pact => true do
218
218
 
219
219
  result = Flapjack::Diner.checks(check_data[:id])
220
220
  expect(result).to be_nil
221
- expect(Flapjack::Diner.error).to eq([{:status => '404',
221
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
222
222
  :detail => "could not find Check record, id: '#{check_data[:id]}'"}])
223
223
  end
224
224
  end
@@ -277,7 +277,7 @@ describe Flapjack::Diner::Resources, :pact => true do
277
277
 
278
278
  result = Flapjack::Diner.update_checks(:id => check_data[:id], :enabled => false)
279
279
  expect(result).to be_nil
280
- expect(Flapjack::Diner.error).to eq([{:status => '404',
280
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
281
281
  :detail => "could not find Check record, id: '#{check_data[:id]}'"}])
282
282
  end
283
283
 
@@ -287,7 +287,7 @@ describe Flapjack::Diner::Resources, :pact => true do
287
287
  :type => 'check',
288
288
  :relationships => {
289
289
  :tags => {
290
- :data => [{:type => 'tag', :id => tag_data[:id]}]
290
+ :data => [{:type => 'tag', :id => tag_data[:name]}]
291
291
  }
292
292
  }
293
293
  }
@@ -302,7 +302,7 @@ describe Flapjack::Diner::Resources, :pact => true do
302
302
  :status => 204,
303
303
  :body => '' )
304
304
 
305
- result = Flapjack::Diner.update_checks(:id => check_data[:id], :tags => [tag_data[:id]])
305
+ result = Flapjack::Diner.update_checks(:id => check_data[:id], :tags => [tag_data[:name]])
306
306
  expect(result).to be_a(TrueClass)
307
307
  end
308
308
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources, :pact => true do
4
+ describe Flapjack::Diner::Resources::Contacts, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -70,7 +70,7 @@ describe Flapjack::Diner::Resources, :pact => true do
70
70
 
71
71
  result = Flapjack::Diner.create_contacts(contact_data)
72
72
  expect(result).to be_nil
73
- expect(Flapjack::Diner.error).to eq([{:status => '409',
73
+ expect(Flapjack::Diner.last_error).to eq([{:status => '409',
74
74
  :detail => "Contacts already exist with the following ids: #{contact_data[:id]}"}])
75
75
  end
76
76
 
@@ -146,7 +146,7 @@ describe Flapjack::Diner::Resources, :pact => true do
146
146
 
147
147
  result = Flapjack::Diner.contacts(contact_data[:id])
148
148
  expect(result).to be_nil
149
- expect(Flapjack::Diner.error).to eq([{:status => '404',
149
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
150
150
  :detail => "could not find Contact record, id: '#{contact_data[:id]}'"}])
151
151
  end
152
152
 
@@ -159,7 +159,7 @@ describe Flapjack::Diner::Resources, :pact => true do
159
159
  resp_data[:relationships][:media][:data] = [
160
160
  {:type => 'medium', :id => email_data[:id]}
161
161
  ]
162
- resp_included = [medium_json(email_data)]
162
+ resp_included = [medium_json(email_data).merge(:relationships => medium_rel(email_data))]
163
163
 
164
164
  flapjack.given("a contact with one medium exists").
165
165
  upon_receiving("a GET request for a single contact with media").
@@ -173,7 +173,7 @@ describe Flapjack::Diner::Resources, :pact => true do
173
173
  result = Flapjack::Diner.contacts(contact_data[:id], :include => 'media')
174
174
  expect(result).not_to be_nil
175
175
  expect(result).to eq(resultify(resp_data))
176
- expect(Flapjack::Diner.context).to eq(:included => {'medium' => {email_data[:id] => resultify(resp_included.first)}})
176
+ expect(Flapjack::Diner.context).to eq(:included => resultify(resp_included))
177
177
  end
178
178
 
179
179
  it 'returns a contact with media and rules' do
@@ -185,8 +185,8 @@ describe Flapjack::Diner::Resources, :pact => true do
185
185
  {:type => 'rule', :id => rule_data[:id]}
186
186
  ]
187
187
  resp_included = [
188
- medium_json(email_data),
189
- rule_json(rule_data)
188
+ medium_json(email_data).merge(:relationships => medium_rel(email_data)),
189
+ rule_json(rule_data).merge(:relationships => rule_rel(rule_data))
190
190
  ]
191
191
 
192
192
  flapjack.given("a contact with one medium and one rule exists").
@@ -201,13 +201,11 @@ describe Flapjack::Diner::Resources, :pact => true do
201
201
  result = Flapjack::Diner.contacts(contact_data[:id], :include => ['media', 'rules'])
202
202
  expect(result).not_to be_nil
203
203
  expect(result).to eq(resultify(resp_data))
204
- expect(Flapjack::Diner.context).to eq(:included => {
205
- 'medium' => {email_data[:id] => resultify(resp_included[0])},
206
- 'rule' => {rule_data[:id] => resultify(resp_included[1])}
207
- })
208
-
204
+ expect(Flapjack::Diner.context).to eq(:included => [resultify(resp_included[0]), resultify(resp_included[1])])
209
205
  end
206
+
210
207
  end
208
+
211
209
  end
212
210
 
213
211
  context 'update' do
@@ -263,7 +261,7 @@ describe Flapjack::Diner::Resources, :pact => true do
263
261
 
264
262
  result = Flapjack::Diner.update_contacts(:id => contact_data[:id], :name => 'Hello There')
265
263
  expect(result).to be_nil
266
- expect(Flapjack::Diner.error).to eq([{:status => '404',
264
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
267
265
  :detail => "could not find Contact record, id: '#{contact_data[:id]}'"}])
268
266
  end
269
267
  end
@@ -317,7 +315,7 @@ describe Flapjack::Diner::Resources, :pact => true do
317
315
 
318
316
  result = Flapjack::Diner.delete_contacts(contact_data[:id])
319
317
  expect(result).to be_nil
320
- expect(Flapjack::Diner.error).to eq([{:status => '404',
318
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
321
319
  :detail => "could not find Contact record, id: '#{contact_data[:id]}'"}])
322
320
  end
323
321
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources, :pact => true do
4
+ describe Flapjack::Diner::Resources::Events, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -41,7 +41,7 @@ describe Flapjack::Diner::Resources, :pact => true do
41
41
  req_data = test_notification_json(test_notification_data).merge(
42
42
  :relationships => {
43
43
  :tag => {
44
- :data => {:type => 'tag', :id => tag_data[:id]}
44
+ :data => {:type => 'tag', :id => tag_data[:name]}
45
45
  }
46
46
  }
47
47
  )
@@ -57,7 +57,7 @@ describe Flapjack::Diner::Resources, :pact => true do
57
57
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
58
58
  :body => {:data => resp_data})
59
59
 
60
- result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:id]))
60
+ result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:name]))
61
61
  expect(result).not_to be_nil
62
62
  expect(result).to eq(resultify(resp_data))
63
63
  end
@@ -107,14 +107,14 @@ describe Flapjack::Diner::Resources, :pact => true do
107
107
  test_notification_json(test_notification_data).merge(
108
108
  :relationships => {
109
109
  :tag => {
110
- :data => {:type => 'tag', :id => tag_data[:id]}
110
+ :data => {:type => 'tag', :id => tag_data[:name]}
111
111
  }
112
112
  }
113
113
  ),
114
114
  test_notification_json(test_notification_2_data).merge(
115
115
  :relationships => {
116
116
  :tag => {
117
- :data => {:type => 'tag', :id => tag_data[:id]}
117
+ :data => {:type => 'tag', :id => tag_data[:name]}
118
118
  }
119
119
  }
120
120
  )
@@ -136,8 +136,8 @@ describe Flapjack::Diner::Resources, :pact => true do
136
136
  :body => {:data => resp_data})
137
137
 
138
138
  result = Flapjack::Diner.create_test_notifications(
139
- test_notification_data.merge(:tag => tag_data[:id]),
140
- test_notification_2_data.merge(:tag => tag_data[:id])
139
+ test_notification_data.merge(:tag => tag_data[:name]),
140
+ test_notification_2_data.merge(:tag => tag_data[:name])
141
141
  )
142
142
  expect(result).not_to be_nil
143
143
  expect(result).to eq(resultify(resp_data))
@@ -168,7 +168,7 @@ describe Flapjack::Diner::Resources, :pact => true do
168
168
 
169
169
  result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:check => check_data[:id]))
170
170
  expect(result).to be_nil
171
- expect(Flapjack::Diner.error).to eq([{:status => '404',
171
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
172
172
  :detail => "could not find Check record, id: '#{check_data[:id]}'"}])
173
173
  end
174
174
 
@@ -176,7 +176,7 @@ describe Flapjack::Diner::Resources, :pact => true do
176
176
  req_data = test_notification_json(test_notification_data).merge(
177
177
  :relationships => {
178
178
  :tag => {
179
- :data => {:type => 'tag', :id => tag_data[:id]}
179
+ :data => {:type => 'tag', :id => tag_data[:name]}
180
180
  }
181
181
  }
182
182
  )
@@ -191,14 +191,14 @@ describe Flapjack::Diner::Resources, :pact => true do
191
191
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
192
192
  :body => {:errors => [{
193
193
  :status => '404',
194
- :detail => "could not find Tag record, id: '#{tag_data[:id]}'"
194
+ :detail => "could not find Tag record, id: '#{tag_data[:name]}'"
195
195
  }]}
196
196
  )
197
197
 
198
- result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:id]))
198
+ result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:name]))
199
199
  expect(result).to be_nil
200
- expect(Flapjack::Diner.error).to eq([{:status => '404',
201
- :detail => "could not find Tag record, id: '#{tag_data[:id]}'"}])
200
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
201
+ :detail => "could not find Tag record, id: '#{tag_data[:name]}'"}])
202
202
  end
203
203
 
204
204
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources, :pact => true do
4
+ describe Flapjack::Diner::Resources::MaintenancePeriods, :pact => true do
5
5
 
6
6
  let(:time) { Time.now }
7
7
 
@@ -148,7 +148,7 @@ describe Flapjack::Diner::Resources, :pact => true do
148
148
 
149
149
  result = Flapjack::Diner.update_unscheduled_maintenances(:id => unscheduled_maintenance_data[:id], :end_time => time)
150
150
  expect(result).to be_nil
151
- expect(Flapjack::Diner.error).to eq([{:status => '404',
151
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
152
152
  :detail => "could not find UnscheduledMaintenance record, id: '#{unscheduled_maintenance_data[:id]}'"}])
153
153
  end
154
154
 
@@ -206,7 +206,7 @@ describe Flapjack::Diner::Resources, :pact => true do
206
206
 
207
207
  result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id])
208
208
  expect(result).to be_nil
209
- expect(Flapjack::Diner.error).to eq([{:status => '404',
209
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
210
210
  :detail => "could not find ScheduledMaintenance record, id: '#{scheduled_maintenance_data[:id]}'"}])
211
211
  end
212
212
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources, :pact => true do
4
+ describe Flapjack::Diner::Resources::Media, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -198,7 +198,7 @@ describe Flapjack::Diner::Resources, :pact => true do
198
198
 
199
199
  result = Flapjack::Diner.update_media(:id => email_data[:id], :interval => 50)
200
200
  expect(result).to be_nil
201
- expect(Flapjack::Diner.error).to eq([{:status => '404',
201
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
202
202
  :detail => "could not find Medium record, id: '#{email_data[:id]}'"}])
203
203
  end
204
204
 
@@ -254,7 +254,7 @@ describe Flapjack::Diner::Resources, :pact => true do
254
254
 
255
255
  result = Flapjack::Diner.delete_media(sms_data[:id])
256
256
  expect(result).to be_nil
257
- expect(Flapjack::Diner.error).to eq([{:status => '404',
257
+ expect(Flapjack::Diner.last_error).to eq([{:status => '404',
258
258
  :detail => "could not find Medium record, id: '#{sms_data[:id]}'"}])
259
259
  end
260
260
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources, :pact => true do
4
+ describe Flapjack::Diner::Resources::Metrics, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Relationships, :pact => true do
4
+ describe Flapjack::Diner::Resources::Relationships, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -13,11 +13,11 @@ describe Flapjack::Diner::Relationships, :pact => true do
13
13
  upon_receiving("a POST request adding a tag to a check").
14
14
  with(:method => :post, :path => "/checks/#{check_data[:id]}/relationships/tags",
15
15
  :headers => {'Content-Type' => 'application/vnd.api+json'},
16
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]}).
16
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]}).
17
17
  will_respond_with(:status => 204,
18
18
  :body => '')
19
19
 
20
- result = Flapjack::Diner.create_check_link_tags(check_data[:id], tag_data[:id])
20
+ result = Flapjack::Diner.create_check_link_tags(check_data[:id], tag_data[:name])
21
21
  expect(result).to be true
22
22
  end
23
23
 
@@ -26,13 +26,13 @@ describe Flapjack::Diner::Relationships, :pact => true do
26
26
  upon_receiving("a POST request adding two tags to a check").
27
27
  with(:method => :post, :path => "/checks/#{check_data[:id]}/relationships/tags",
28
28
  :headers => {'Content-Type' => 'application/vnd.api+json'},
29
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'},
30
- {:id => tag_2_data[:id], :type => 'tag'}]}).
29
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'},
30
+ {:id => tag_2_data[:name], :type => 'tag'}]}).
31
31
  will_respond_with(:status => 204,
32
32
  :body => '')
33
33
 
34
34
  result = Flapjack::Diner.create_check_link_tags(check_data[:id],
35
- tag_data[:id], tag_2_data[:id])
35
+ tag_data[:name], tag_2_data[:name])
36
36
  expect(result).to be true
37
37
  end
38
38
 
@@ -43,15 +43,15 @@ describe Flapjack::Diner::Relationships, :pact => true do
43
43
  will_respond_with(
44
44
  :status => 200,
45
45
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
46
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]})
46
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]})
47
47
 
48
48
  result = Flapjack::Diner.check_link_tags(check_data[:id])
49
- expect(result).to eq([{:id => tag_data[:id], :type => 'tag'}])
49
+ expect(result).to eq([{:id => tag_data[:name], :type => 'tag'}])
50
50
  end
51
51
 
52
52
  it 'gets tags for a check with full tag records' do
53
53
  included_data = [
54
- tag_json(tag_data)
54
+ tag_json(tag_data).merge(:relationships => tag_rel(tag_data))
55
55
  ]
56
56
 
57
57
  flapjack.given("a check with a tag exists").
@@ -62,18 +62,18 @@ describe Flapjack::Diner::Relationships, :pact => true do
62
62
  will_respond_with(
63
63
  :status => 200,
64
64
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
65
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'}],
65
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'}],
66
66
  :included => included_data})
67
67
 
68
68
  result = Flapjack::Diner.check_link_tags(check_data[:id], :include => 'tags')
69
- expect(result).to eq([{:id => tag_data[:id], :type => 'tag'}])
70
- expect(Flapjack::Diner.context[:included]).to eq('tag' => {tag_data[:id] => resultify(included_data[0])})
69
+ expect(result).to eq([{:id => tag_data[:name], :type => 'tag'}])
70
+ expect(Flapjack::Diner.context[:included]).to eq([resultify(included_data[0])])
71
71
  end
72
72
 
73
73
  it 'gets tags for a check with full tag and rule record' do
74
74
  included_data = [
75
- tag_json(tag_data),
76
- rule_json(rule_data)
75
+ tag_json(tag_data).merge(:relationships => tag_rel(tag_data)),
76
+ rule_json(rule_data).merge(:relationships => rule_rel(rule_data))
77
77
  ]
78
78
 
79
79
  flapjack.given("a check with a tag and a rule exists").
@@ -84,15 +84,13 @@ describe Flapjack::Diner::Relationships, :pact => true do
84
84
  will_respond_with(
85
85
  :status => 200,
86
86
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
87
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'}],
87
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'}],
88
88
  :included => included_data})
89
89
 
90
90
  result = Flapjack::Diner.check_link_tags(check_data[:id], :include => 'rules')
91
- expect(result).to eq([{:id => tag_data[:id], :type => 'tag'}])
92
- expect(Flapjack::Diner.context[:included]).to eq(
93
- 'tag' => {tag_data[:id] => resultify(included_data[0])},
94
- 'rule' => {rule_data[:id] => resultify(included_data[1])}
95
- )
91
+ expect(result).to eq([{:id => tag_data[:name], :type => 'tag'}])
92
+ expect(Flapjack::Diner.context[:included]).to eq([resultify(included_data[0]),
93
+ resultify(included_data[1])])
96
94
  end
97
95
 
98
96
  it 'updates tags for a check' do
@@ -100,12 +98,12 @@ describe Flapjack::Diner::Relationships, :pact => true do
100
98
  upon_receiving("a PATCH request updating tags for a check").
101
99
  with(:method => :patch, :path => "/checks/#{check_data[:id]}/relationships/tags",
102
100
  :headers => {'Content-Type' => 'application/vnd.api+json'},
103
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]}).
101
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]}).
104
102
  will_respond_with(:status => 204,
105
103
  :body => '')
106
104
 
107
105
  result = Flapjack::Diner.update_check_link_tags(check_data[:id],
108
- tag_data[:id])
106
+ tag_data[:name])
109
107
  expect(result).to be true
110
108
  end
111
109
 
@@ -127,12 +125,12 @@ describe Flapjack::Diner::Relationships, :pact => true do
127
125
  upon_receiving("a DELETE request deleting a tag from a check").
128
126
  with(:method => :delete, :path => "/checks/#{check_data[:id]}/relationships/tags",
129
127
  :headers => {'Content-Type' => 'application/vnd.api+json'},
130
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]}).
128
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]}).
131
129
  will_respond_with(:status => 204,
132
130
  :body => '')
133
131
 
134
132
  result = Flapjack::Diner.delete_check_link_tags(check_data[:id],
135
- tag_data[:id])
133
+ tag_data[:name])
136
134
  expect(result).to be true
137
135
  end
138
136
 
@@ -141,13 +139,13 @@ describe Flapjack::Diner::Relationships, :pact => true do
141
139
  upon_receiving("a DELETE request deleting two tags from a check").
142
140
  with(:method => :delete, :path => "/checks/#{check_data[:id]}/relationships/tags",
143
141
  :headers => {'Content-Type' => 'application/vnd.api+json'},
144
- :body => {:data => [{:id => tag_data[:id], :type => 'tag'},
145
- {:id => tag_2_data[:id], :type => 'tag'}]}).
142
+ :body => {:data => [{:id => tag_data[:name], :type => 'tag'},
143
+ {:id => tag_2_data[:name], :type => 'tag'}]}).
146
144
  will_respond_with(:status => 204,
147
145
  :body => '')
148
146
 
149
147
  result = Flapjack::Diner.delete_check_link_tags(check_data[:id],
150
- tag_data[:id], tag_2_data[:id])
148
+ tag_data[:name], tag_2_data[:name])
151
149
  expect(result).to be true
152
150
  end
153
151
 
@@ -164,48 +162,4 @@ describe Flapjack::Diner::Relationships, :pact => true do
164
162
  expect(result).to eq(:id => contact_data[:id], :type => 'contact')
165
163
  end
166
164
 
167
- it "doesn't duplicate linked data references in included data" do
168
- resp_check = check_json(check_data)
169
- resp_check[:relationships] = {
170
- :current_state => {
171
- :data => {:type => 'state', :id => state_data[:id]}
172
- },
173
- :latest_notifications => {
174
- :data => [{:type => 'state', :id => state_data[:id]}]
175
- }
176
- }
177
-
178
- sd = state_data.delete_if {|k, _| [:created_at, :updated_at].include?(k)}
179
-
180
- included_data = [
181
- resp_check,
182
- state_json(sd)
183
- ]
184
-
185
- flapjack.given("a check with a tag, current state and a latest notification exists").
186
- upon_receiving("a GET request for a check (via tag)'s state and notifications").
187
- with(:method => :get,
188
- :path => "/tags/#{tag_data[:id]}/checks",
189
- :query => 'include=checks.current_state%2Cchecks.latest_notifications').
190
- will_respond_with(
191
- :status => 200,
192
- :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
193
- :body => {
194
- :data => [
195
- {:id => check_data[:id], :type => 'check'},
196
- ],
197
- :included => included_data
198
- })
199
-
200
- result = Flapjack::Diner.tag_link_checks(tag_data[:id],
201
- :include => ['checks.current_state', 'checks.latest_notifications'])
202
- expect(result).to eq([
203
- {:id => check_data[:id], :type => 'check'}
204
- ])
205
- expect(Flapjack::Diner.context[:included]).to eq(
206
- 'check' => {check_data[:id] => resultify(resp_check)},
207
- 'state' => {sd[:id] => resultify(state_json(sd))}
208
- )
209
- end
210
-
211
165
  end