smartwaiver-sdk 4.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,10 @@ class SmartwaiverTest < SmartwaiverSDK::SmartwaiverBase
16
16
  make_api_request(path, HTTP_PUT, data)
17
17
  end
18
18
 
19
+ def delete_test(path)
20
+ make_api_request(path, HTTP_DELETE)
21
+ end
22
+
19
23
  def parse_response_body_test(data)
20
24
  parse_response_body(data)
21
25
  end
@@ -24,6 +28,9 @@ class SmartwaiverTest < SmartwaiverSDK::SmartwaiverBase
24
28
  check_response(response)
25
29
  end
26
30
 
31
+ def create_query_string_test(params)
32
+ create_query_string(params)
33
+ end
27
34
  end
28
35
 
29
36
  describe SmartwaiverSDK::SmartwaiverBase do
@@ -115,6 +122,23 @@ describe SmartwaiverSDK::SmartwaiverBase do
115
122
  end
116
123
  end
117
124
  end
125
+
126
+ it "DELETE" do
127
+ path = "#{API_URL}/delete_test"
128
+ FakeWeb.register_uri(:delete, path, :body => json_base_results)
129
+ @client.delete_test(path)
130
+
131
+ request = FakeWeb.last_request
132
+ expect(request.method).to eq("DELETE")
133
+ request.each_header do |key, value|
134
+ case key
135
+ when "user-agent"
136
+ expect(value).to match(/^SmartwaiverAPI*/)
137
+ when "sw-api-key"
138
+ expect(value).to eq(@api_key)
139
+ end
140
+ end
141
+ end
118
142
  end
119
143
 
120
144
  describe "#parse_response_body" do
@@ -143,6 +167,19 @@ describe SmartwaiverSDK::SmartwaiverBase do
143
167
  end
144
168
  end
145
169
 
170
+ describe "#create_query_string" do
171
+ before do
172
+ @client = SmartwaiverTest.new(@api_key)
173
+ end
174
+
175
+ it "create a valid query string" do
176
+ params = {:a => "first", :b => "with space"}
177
+ query_string = @client.create_query_string_test(params)
178
+
179
+ expect(query_string).to eq("a=first&b=with+space")
180
+ end
181
+ end
182
+
146
183
  describe "#check_response" do
147
184
  it "HTTP 200" do
148
185
  path = "#{API_URL}/get_test"
@@ -0,0 +1,139 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../spec_helper"
3
+ require "#{dir}/../../lib/smartwaiver-sdk/dynamic_template_data"
4
+
5
+ describe SmartwaiverDynamicTemplateData do
6
+
7
+ before do
8
+ FakeWeb.allow_net_connect = false
9
+ end
10
+
11
+ describe "dynamic template data" do
12
+ it "#initialize" do
13
+ td = SmartwaiverDynamicTemplateData.new
14
+ expect(td).to be_kind_of(SmartwaiverDynamicTemplateData)
15
+ expect(td.adult).to eq(true)
16
+ expect(td.participants).to eq([])
17
+ expect(td.guardian).to be_kind_of(SmartwaiverGuardian)
18
+ end
19
+
20
+ it "#initialize with non default adult" do
21
+ td = SmartwaiverDynamicTemplateData.new(false)
22
+ expect(td.adult).to eq(false)
23
+ end
24
+
25
+ it "#add_participant" do
26
+ td = SmartwaiverDynamicTemplateData.new
27
+
28
+ p = SmartwaiverParticipant.new
29
+ p.first_name = "Rocky"
30
+ p.last_name = "RockChuck"
31
+
32
+ td.add_participant(p)
33
+
34
+ expect(td.participants).to eq([p])
35
+ end
36
+
37
+ it "#for_json" do
38
+ td = SmartwaiverDynamicTemplateData.new
39
+
40
+ p = SmartwaiverParticipant.new
41
+ p.first_name = "Rocky"
42
+ p.last_name = "RockChuck"
43
+
44
+ td.add_participant(p)
45
+
46
+ a = td.for_json
47
+
48
+ a_expected = {
49
+ "adult"=>true,
50
+ "participants"=>[{"firstName"=>"Rocky", "lastName"=>"RockChuck"}],
51
+ "guardian"=>{"participant"=>false}
52
+ }
53
+ expect(a).to eq(a_expected)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe SmartwaiverParticipant do
59
+ describe "Participant Data" do
60
+ it "#initialize" do
61
+ p = SmartwaiverParticipant.new
62
+ expect(p.first_name).to be_nil
63
+ expect(p.middle_name).to be_nil
64
+ expect(p.last_name).to be_nil
65
+ expect(p.phone).to be_nil
66
+ expect(p.gender).to be_nil
67
+ expect(p.dob).to be_nil
68
+
69
+ a = p.for_json
70
+ expect(a).to eq({})
71
+ end
72
+
73
+ it "#for_json" do
74
+ p = SmartwaiverParticipant.new
75
+
76
+ p.first_name = "Rocky"
77
+ p.middle_name = "R"
78
+ p.last_name = "RockChuck"
79
+ p.phone = "800-555-1212"
80
+ p.gender = "M"
81
+ p.dob = '1970-01-01'
82
+
83
+ a = p.for_json
84
+ a_expected = {
85
+ "firstName"=>"Rocky",
86
+ "middleName"=>"R",
87
+ "lastName"=>"RockChuck",
88
+ "phone"=>"800-555-1212",
89
+ "gender"=>"M",
90
+ "dob"=>"1970-01-01"
91
+ }
92
+ expect(a).to eq(a_expected)
93
+ end
94
+ end
95
+ end
96
+
97
+ describe SmartwaiverGuardian do
98
+ describe "Guardian Data" do
99
+ it "#initialize" do
100
+ g = SmartwaiverGuardian.new
101
+
102
+ expect(g.participant).to eq(false)
103
+ expect(g.first_name).to be_nil
104
+ expect(g.middle_name).to be_nil
105
+ expect(g.last_name).to be_nil
106
+ expect(g.relationship).to be_nil
107
+ expect(g.phone).to be_nil
108
+ expect(g.gender).to be_nil
109
+ expect(g.dob).to be_nil
110
+
111
+ a = g.for_json
112
+ expect(a).to eq({"participant" => false})
113
+ end
114
+
115
+ it "#for_json" do
116
+ g = SmartwaiverGuardian.new
117
+
118
+ g.participant = false
119
+ g.first_name = "Rocky"
120
+ g.middle_name = "R"
121
+ g.last_name = "RockChuck"
122
+ g.phone = "800-555-1212"
123
+ g.gender = "M"
124
+ g.dob = '1970-01-01'
125
+
126
+ a = g.for_json
127
+ a_expected = {
128
+ "participant"=>false,
129
+ "firstName"=>"Rocky",
130
+ "middleName"=>"R",
131
+ "lastName"=>"RockChuck",
132
+ "phone"=>"800-555-1212",
133
+ "gender"=>"M",
134
+ "dob"=>"1970-01-01"
135
+ }
136
+ expect(a).to eq(a_expected)
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,450 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../spec_helper"
3
+ require "#{dir}/../../lib/smartwaiver-sdk/dynamic_template"
4
+
5
+ describe SmartwaiverDynamicTemplate do
6
+
7
+ before do
8
+ FakeWeb.allow_net_connect = false
9
+ end
10
+
11
+ describe "dynamic templates" do
12
+ it "#initialize" do
13
+ dt = SmartwaiverDynamicTemplate.new
14
+ expect(dt).to be_kind_of(SmartwaiverDynamicTemplate)
15
+ expect(dt.data).to be_kind_of(SmartwaiverDynamicTemplateData)
16
+ expect(dt.template_config).to be_kind_of(SmartwaiverDynamicTemplateConfig)
17
+ expect(dt.expiration).to eq(300)
18
+ end
19
+
20
+ it "#initialize with non default expiration" do
21
+ dt = SmartwaiverDynamicTemplate.new(30)
22
+ expect(dt.expiration).to eq(30)
23
+ end
24
+
25
+ it "to_json default values" do
26
+ dt = SmartwaiverDynamicTemplate.new
27
+ json = dt.to_json
28
+ expect(json).to eq(json_dynamic_template_default)
29
+ end
30
+ end
31
+ end
32
+
33
+ describe SmartwaiverTemplateMeta do
34
+ describe "dynamic template meta" do
35
+ it "#initialize" do
36
+ meta = SmartwaiverTemplateMeta.new
37
+ expect(meta.title).to be_nil
38
+ expect(meta.locale).to be_nil
39
+
40
+ a = meta.for_json
41
+ expect(a).to eq({})
42
+ end
43
+
44
+ it "#for_json" do
45
+ meta = SmartwaiverTemplateMeta.new
46
+ meta.title = "Test"
47
+ meta.locale = "fr_FR"
48
+ a = meta.for_json
49
+ expect(a).to eq({'title' => 'Test', 'locale' => {"locale"=>"fr_FR"}})
50
+ end
51
+ end
52
+ end
53
+
54
+ describe SmartwaiverTemplateHeader do
55
+ describe "dynamic template header" do
56
+ it "#initialize" do
57
+ header = SmartwaiverTemplateHeader.new
58
+ expect(header.text).to be_nil
59
+ expect(header.image_base_64).to be_nil
60
+
61
+ a = header.for_json
62
+ expect(a).to eq({})
63
+ end
64
+
65
+ it "#format_image_inline" do
66
+ header = SmartwaiverTemplateHeader.new
67
+ header.format_image_inline(SmartwaiverTemplateHeader::MEDIA_TYPE_PNG,"image-text-here")
68
+ expect(header.image_base_64).to eq("data:image/png;base64,image-text-here")
69
+ end
70
+
71
+ it "#for_json" do
72
+ header = SmartwaiverTemplateHeader.new
73
+ header.text = "Ruby SDK Test"
74
+ header.image_base_64 = "image-text-here"
75
+
76
+ a = header.for_json
77
+ expect(a).to eq({"text"=>"Ruby SDK Test", "logo"=>{"image"=>"image-text-here"}})
78
+ end
79
+
80
+
81
+ end
82
+ end
83
+
84
+ describe SmartwaiverTemplateBody do
85
+ describe "dynamic template body" do
86
+ it "#initialize" do
87
+ body = SmartwaiverTemplateBody.new
88
+ expect(body.text).to be_nil
89
+
90
+ a = body.for_json
91
+ expect(a).to eq({})
92
+ end
93
+
94
+ it "#for_json" do
95
+ body = SmartwaiverTemplateBody.new
96
+ body.text = "Ruby SDK Test"
97
+
98
+ a = body.for_json
99
+ expect(a).to eq({"text"=>"Ruby SDK Test"})
100
+ end
101
+ end
102
+ end
103
+
104
+ describe SmartwaiverTemplateParticipants do
105
+ describe "dynamic template participants" do
106
+ it "#initialize" do
107
+ participants = SmartwaiverTemplateParticipants.new
108
+ expect(participants.adults).to eq(true)
109
+ expect(participants.minors_enabled).to be_nil
110
+ expect(participants.allow_multiple_minors).to be_nil
111
+ expect(participants.allow_without_adults).to be_nil
112
+ expect(participants.allows_adults_and_minors).to be_nil
113
+ expect(participants.age_of_majority).to be_nil
114
+ expect(participants.participant_label).to be_nil
115
+ expect(participants.participating_text).to be_nil
116
+ expect(participants.show_middle_name).to be_nil
117
+ expect(participants.show_phone).to be_nil
118
+ expect(participants.show_gender).to be_nil
119
+ expect(participants.dob_type).to be_nil
120
+
121
+ a = participants.for_json
122
+ expect(a).to eq({"adults"=>true})
123
+ end
124
+
125
+ it "#for_json" do
126
+ participants = SmartwaiverTemplateParticipants.new
127
+
128
+ participants.minors_enabled = true
129
+ participants.allow_multiple_minors = true
130
+ participants.allow_without_adults = false
131
+ participants.allows_adults_and_minors = false
132
+ participants.age_of_majority = 18
133
+ participants.participant_label = "Event Participant"
134
+ participants.participating_text = "Have fun"
135
+ participants.show_middle_name = false
136
+ participants.show_phone = "adults"
137
+ participants.show_gender = true
138
+ participants.dob_type = "select"
139
+
140
+ a = participants.for_json
141
+ a_expected = {"adults"=>true,
142
+ "minors"=>{"enabled"=>true, "multipleMinors"=>true, "minorsWithoutAdults"=>false, "adultsAndMinors" => false},
143
+ "ageOfMajority" => 18,
144
+ "participantLabel" => "Event Participant",
145
+ "participatingText" => "Have fun",
146
+ "config"=>{"middleName"=>false, "phone"=>"adults", "gender"=>true, "dobType"=>"select"}
147
+ }
148
+
149
+ expect(a).to eq(a_expected)
150
+ end
151
+ end
152
+ end
153
+
154
+ describe SmartwaiverTemplateStandardQuestions do
155
+ describe "dynamic template standard questions" do
156
+ it "#initialize" do
157
+ sq = SmartwaiverTemplateStandardQuestions.new
158
+ expect(sq.address_enabled).to be_nil
159
+ expect(sq.address_required).to be_nil
160
+ expect(sq.default_country_code).to be_nil
161
+ expect(sq.default_state_code).to be_nil
162
+ expect(sq.email_verification_enabled).to be_nil
163
+ expect(sq.email_marketing_enabled).to be_nil
164
+ expect(sq.marketing_opt_in_text).to be_nil
165
+ expect(sq.marketing_opt_in_checked).to be_nil
166
+ expect(sq.emergency_contact_enabled).to be_nil
167
+ expect(sq.insurance_enabled).to be_nil
168
+ expect(sq.id_card_enabled).to be_nil
169
+
170
+ a = sq.for_json
171
+ expect(a).to eq({})
172
+ end
173
+
174
+ it "#for_json" do
175
+ sq = SmartwaiverTemplateStandardQuestions.new
176
+
177
+ sq.address_enabled = false
178
+ sq.address_required = false
179
+ sq.default_country_code = 'US'
180
+ sq.default_state_code = 'CA'
181
+ sq.email_verification_enabled = true
182
+ sq.email_marketing_enabled = true
183
+ sq.marketing_opt_in_text = 'Join the mailing list'
184
+ sq.marketing_opt_in_checked = true
185
+ sq.emergency_contact_enabled = true
186
+ sq.insurance_enabled = false
187
+ sq.id_card_enabled = true
188
+
189
+
190
+ a = sq.for_json
191
+ a_expected = {
192
+ "address"=>{"enabled"=>false, "required"=>false, "defaults"=>{"country"=>"US", "state"=>"CA"}},
193
+ "email"=>{"verification"=>true, "marketing"=>{"enabled"=>true, "optInText"=>"Join the mailing list", "defaultChecked"=>true}},
194
+ "emergencyContact" => {"enabled"=>true},
195
+ "insurance"=>{"enabled"=>true},
196
+ "idCard"=>{"enabled"=>true}
197
+ }
198
+
199
+ expect(a).to eq(a_expected)
200
+ end
201
+ end
202
+ end
203
+
204
+ describe SmartwaiverTemplateGuardian do
205
+ describe "dynamic template guardian" do
206
+ it "#initialize" do
207
+ g = SmartwaiverTemplateGuardian.new
208
+ expect(g.verbiage).to be_nil
209
+ expect(g.verbiage_participant_addendum).to be_nil
210
+ expect(g.label).to be_nil
211
+ expect(g.relationship).to be_nil
212
+ expect(g.age_verification).to be_nil
213
+
214
+ a = g.for_json
215
+ expect(a).to eq({})
216
+ end
217
+
218
+ it "#for_json" do
219
+ g = SmartwaiverTemplateGuardian.new
220
+
221
+ g.verbiage = "Guardians are allowed with minors"
222
+ g.verbiage_participant_addendum = "More legal text here"
223
+ g.label = "The Guardian"
224
+ g.relationship = false
225
+ g.age_verification = true
226
+
227
+ a = g.for_json
228
+ a_expected = {
229
+ "verbiage"=>"Guardians are allowed with minors",
230
+ "verbiageParticipantAddendum"=>"More legal text here",
231
+ "label"=>"The Guardian",
232
+ "relationship"=>false,
233
+ "ageVerification"=>true
234
+ }
235
+
236
+ expect(a).to eq(a_expected)
237
+ end
238
+ end
239
+ end
240
+
241
+ describe SmartwaiverTemplateElectronicConsent do
242
+ describe "dynamic template electronic Consent" do
243
+ it "#initialize" do
244
+ ec = SmartwaiverTemplateElectronicConsent.new
245
+ expect(ec.title).to be_nil
246
+ expect(ec.verbiage).to be_nil
247
+
248
+ a = ec.for_json
249
+ expect(a).to eq({})
250
+ end
251
+
252
+ it "#for_json" do
253
+ ec = SmartwaiverTemplateElectronicConsent.new
254
+
255
+ ec.title = "Electronic Consent Below"
256
+ ec.verbiage = "Use the default text"
257
+
258
+ a = ec.for_json
259
+ a_expected = {
260
+ "title"=>"Electronic Consent Below",
261
+ "verbiage"=>"Use the default text"
262
+ }
263
+
264
+ expect(a).to eq(a_expected)
265
+ end
266
+ end
267
+ end
268
+
269
+ describe SmartwaiverTemplateStyling do
270
+ describe "dynamic template styling" do
271
+ it "#initialize" do
272
+ s = SmartwaiverTemplateStyling.new
273
+ @style = nil
274
+ @custom_background_color = nil
275
+ @custom_border_color = nil
276
+ @custom_shadow_color = nil
277
+
278
+ expect(s.style).to be_nil
279
+ expect(s.custom_background_color).to be_nil
280
+ expect(s.custom_border_color).to be_nil
281
+ expect(s.custom_shadow_color).to be_nil
282
+
283
+ a = s.for_json
284
+ expect(a).to eq({})
285
+ end
286
+
287
+ it "#for_json" do
288
+ s = SmartwaiverTemplateStyling.new
289
+
290
+ s.style = 'custom'
291
+ s.custom_background_color = '#FF0000'
292
+ s.custom_border_color = '#00FF00'
293
+ s.custom_shadow_color = '#0000FF'
294
+
295
+ a = s.for_json
296
+ a_expected = {
297
+ "style"=>"custom",
298
+ "custom"=>{"background"=>"#FF0000", "border"=>"#00FF00", "shadow"=>"#0000FF"}
299
+ }
300
+
301
+ expect(a).to eq(a_expected)
302
+ end
303
+ end
304
+ end
305
+
306
+ describe SmartwaiverTemplateCompletion do
307
+ describe "dynamic template completion" do
308
+ it "#initialize" do
309
+ c = SmartwaiverTemplateCompletion.new
310
+ expect(c.redirect_success).to be_nil
311
+ expect(c.redirect_cancel).to be_nil
312
+
313
+ a = c.for_json
314
+ expect(a).to eq({})
315
+ end
316
+
317
+ it "#for_json" do
318
+ c = SmartwaiverTemplateCompletion.new
319
+
320
+ c.redirect_success = 'http://127.0.0.1/success'
321
+ c.redirect_cancel = 'http://127.0.0.1/cancel'
322
+
323
+ a = c.for_json
324
+ a_expected = {
325
+ "redirect"=>{"success"=>"http://127.0.0.1/success", "cancel"=>"http://127.0.0.1/cancel"}
326
+ }
327
+
328
+ expect(a).to eq(a_expected)
329
+ end
330
+ end
331
+ end
332
+
333
+ describe SmartwaiverTemplateSignatures do
334
+ describe "dynamic template signatures" do
335
+ it "#initialize" do
336
+ s = SmartwaiverTemplateSignatures.new
337
+ expect(s.type).to be_nil
338
+ expect(s.minors).to be_nil
339
+ expect(s.default_choice).to be_nil
340
+
341
+ a = s.for_json
342
+ expect(a).to eq({})
343
+ end
344
+
345
+ it "#for_json" do
346
+ s = SmartwaiverTemplateSignatures.new
347
+
348
+ s.type = 'choice'
349
+ s.minors = false
350
+ s.default_choice ='type'
351
+
352
+ a = s.for_json
353
+ a_expected = {
354
+ "type"=>"choice",
355
+ "minors"=>false,
356
+ "defaultChoice"=>"type"
357
+ }
358
+
359
+ expect(a).to eq(a_expected)
360
+ end
361
+ end
362
+ end
363
+
364
+ describe SmartwaiverTemplateProcessing do
365
+ describe "dynamic template processing" do
366
+ it "#initialize" do
367
+ proc = SmartwaiverTemplateProcessing.new
368
+ expect(proc.email_business_name).to be_nil
369
+ expect(proc.email_reply_to).to be_nil
370
+ expect(proc.email_custom_text_enabled).to be_nil
371
+ expect(proc.email_custom_text_web).to be_nil
372
+ expect(proc.email_cc_enabled).to be_nil
373
+ expect(proc.email_cc_web_completed).to be_nil
374
+ expect(proc.email_cc_addresses).to be_nil
375
+ expect(proc.include_bar_codes).to be_nil
376
+
377
+ a = proc.for_json
378
+ expect(a).to eq({})
379
+ end
380
+
381
+ it "#for_json" do
382
+ proc = SmartwaiverTemplateProcessing.new
383
+
384
+ proc.email_business_name = 'Smartwaiver'
385
+ proc.email_reply_to = 'no-reply@smartwaiver.com'
386
+ proc.email_custom_text_enabled = true
387
+ proc.email_custom_text_web = "Thanks!"
388
+ proc.email_cc_enabled = true
389
+ proc.email_cc_web_completed = "Online"
390
+ proc.email_cc_addresses = ['no-replay-cc@smartwaiver.com']
391
+ proc.include_bar_codes = true
392
+
393
+ a = proc.for_json
394
+ a_expected = {
395
+ "emails"=>{
396
+ "businessName"=>"Smartwaiver",
397
+ "replyTo"=>"no-reply@smartwaiver.com",
398
+ "customText"=>{"enabled"=>true, "web"=>"Thanks!"},
399
+ "cc"=>{"enabled"=>true, "web"=>"Online", "emails"=>["no-replay-cc@smartwaiver.com"]},
400
+ "includeBarcodes"=>true}
401
+ }
402
+
403
+ expect(a).to eq(a_expected)
404
+ end
405
+ end
406
+ end
407
+
408
+ describe SmartwaiverDynamicTemplateConfig do
409
+
410
+ describe "dynamic template config" do
411
+ it "#initialize" do
412
+ dtc = SmartwaiverDynamicTemplateConfig.new
413
+ expect(dtc).to be_kind_of(SmartwaiverDynamicTemplateConfig)
414
+
415
+ expect(dtc.meta).to be_kind_of(SmartwaiverTemplateMeta)
416
+ expect(dtc.header).to be_kind_of(SmartwaiverTemplateHeader)
417
+ expect(dtc.body).to be_kind_of(SmartwaiverTemplateBody)
418
+ expect(dtc.participants).to be_kind_of(SmartwaiverTemplateParticipants)
419
+ expect(dtc.standard_questions).to be_kind_of(SmartwaiverTemplateStandardQuestions)
420
+ expect(dtc.guardian).to be_kind_of(SmartwaiverTemplateGuardian)
421
+ expect(dtc.electronic_consent).to be_kind_of(SmartwaiverTemplateElectronicConsent)
422
+ expect(dtc.styling).to be_kind_of(SmartwaiverTemplateStyling)
423
+ expect(dtc.completion).to be_kind_of(SmartwaiverTemplateCompletion)
424
+ expect(dtc.signatures).to be_kind_of(SmartwaiverTemplateSignatures)
425
+ expect(dtc.processing).to be_kind_of(SmartwaiverTemplateProcessing)
426
+ end
427
+
428
+ it "#for_json" do
429
+ dtc = SmartwaiverDynamicTemplateConfig.new
430
+
431
+ a = dtc.for_json
432
+ a_expected = {
433
+ "body" => {},
434
+ "completion" => {},
435
+ "electronicConsent" => {},
436
+ "guardian" => {},
437
+ "header" => {},
438
+ "meta" => {},
439
+ "participants" => {"adults"=>true},
440
+ "processing" => {},
441
+ "signatures" => {},
442
+ "standardQuestions" => {},
443
+ "styling" => {}
444
+ }
445
+
446
+ expect(a).to eq(a_expected)
447
+ end
448
+ end
449
+
450
+ end