scorm_engine 0.3.0 → 0.4.0

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/scorm_engine/api/endpoints.rb +12 -2
  3. data/lib/scorm_engine/api/endpoints/destinations.rb +225 -0
  4. data/lib/scorm_engine/api/endpoints/dispatches.rb +301 -0
  5. data/lib/scorm_engine/faraday/connection.rb +0 -1
  6. data/lib/scorm_engine/models.rb +3 -0
  7. data/lib/scorm_engine/models/destination.rb +27 -0
  8. data/lib/scorm_engine/models/dispatch.rb +51 -0
  9. data/lib/scorm_engine/models/dispatch_zip.rb +18 -0
  10. data/lib/scorm_engine/version.rb +1 -1
  11. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_delete_destination/raises_ArgumentError_when_destination_id_is_missing.yml +32 -0
  12. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_delete_destination/returns_success_even_when_id_is_invalid.yml +32 -0
  13. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_delete_destination/works.yml +32 -0
  14. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination/fails_when_id_is_invalid.yml +38 -0
  15. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination/is_successful.yml +38 -0
  16. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination/results/sucessfully_creates_the_destination_attributes.yml +38 -0
  17. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination_dispatches_registration_count/fails_when_invalid.yml +38 -0
  18. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destination_dispatches_registration_count/works.yml +36 -0
  19. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_more_option_pagination_/returns_all_the_destinations.yml +73 -0
  20. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_more_option_pagination_/returns_the_more_key_in_the_raw_response.yml +38 -0
  21. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_since_option/fails_when_passed_an_invalid_value.yml +37 -0
  22. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/_since_option/works.yml +38 -0
  23. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/is_successful.yml +38 -0
  24. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/results/is_an_enumerator_of_Destination_models.yml +38 -0
  25. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_get_destinations/results/sucessfully_creates_the_Destination_attributes.yml +38 -0
  26. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination/is_successful.yml +61 -0
  27. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination/is_successful_even_if_the_destination_id_is_not_unique.yml +32 -0
  28. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_enabled/fails_when_invalid.yml +38 -0
  29. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_enabled/works_when_false.yml +32 -0
  30. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_enabled/works_when_true.yml +32 -0
  31. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_registration_instancing/fails_when_invalid.yml +38 -0
  32. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_registration_instancing/works_when_false.yml +32 -0
  33. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_post_destination_dispatches_registration_instancing/works_when_true.yml +32 -0
  34. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_put_destination/is_successful.yml +32 -0
  35. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Destinations/_put_destination/results/sucessfully_creates_the_destination_attributes.yml +67 -0
  36. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_delete_dispatch/returns_success_even_when_id_is_invalid.yml +30 -0
  37. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_delete_dispatch/works.yml +30 -0
  38. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch/fails_when_id_is_invalid.yml +36 -0
  39. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch/is_successful.yml +36 -0
  40. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch/results/sucessfully_creates_the_dispatch_attributes.yml +36 -0
  41. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_enabled/is_false_when_disabled.yml +63 -0
  42. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_enabled/is_true_when_enabled.yml +63 -0
  43. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/fails_given_an_invalid_id.yml +36 -0
  44. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/fails_given_an_invalid_type.yml +34 -0
  45. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works.yml +37 -0
  46. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works_when_type_is_AICC.yml +37 -0
  47. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works_when_type_is_SCORM12.yml +37 -0
  48. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatch_zip/works_when_type_is_SCORM20043RDEDITION.yml +35 -0
  49. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_more_option_pagination_/returns_all_the_dispatches.yml +69 -0
  50. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_more_option_pagination_/returns_the_more_key_in_the_raw_response.yml +36 -0
  51. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_since_option/fails_when_passed_an_invalid_value.yml +35 -0
  52. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/_since_option/works.yml +36 -0
  53. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/is_successful.yml +36 -0
  54. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/results/is_an_enumerator_of_dispatch_models.yml +36 -0
  55. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_get_dispatches/results/sucessfully_creates_the_dispatch_attributes.yml +69 -0
  56. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_post_dispatch/is_successful.yml +59 -0
  57. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch/is_successful.yml +32 -0
  58. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch/results/sucessfully_creates_the_dispatch_attributes.yml +65 -0
  59. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch_enabled/fails_when_invalid.yml +38 -0
  60. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch_enabled/works_when_false.yml +32 -0
  61. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Dispatches/_put_dispatch_enabled/works_when_true.yml +32 -0
  62. data/spec/fixtures/vcr/ScormEngine_Api_Endpoints_Registrations/_post_registration/is_successful_even_when_given_a_UTF8/slashed_username.yml +97 -0
  63. data/spec/scorm_engine/api/endpoints/destinations_spec.rb +215 -0
  64. data/spec/scorm_engine/api/endpoints/dispatches_spec.rb +286 -0
  65. data/spec/scorm_engine/api/endpoints/registrations_spec.rb +12 -0
  66. data/spec/scorm_engine/models/destination_spec.rb +21 -0
  67. data/spec/scorm_engine/models/dispatch_spec.rb +85 -0
  68. data/spec/scorm_engine/models/dispatch_zip_spec.rb +18 -0
  69. data/spec/support/scorm_engine.rb +21 -0
  70. metadata +78 -2
@@ -0,0 +1,286 @@
1
+ require "zip"
2
+
3
+ RSpec.describe ScormEngine::Api::Endpoints::Dispatches do
4
+ let(:subject) { scorm_engine_client }
5
+
6
+ let(:course_options) { {
7
+ course_id: "testing-golf-explained"
8
+ } }
9
+
10
+ let(:destination_options) { {
11
+ destination_id: "testing-golf-club",
12
+ name: "Golf Club",
13
+ } }
14
+
15
+ let(:dispatch_options) { {
16
+ destination_id: destination_options[:destination_id],
17
+ course_id: course_options[:course_id],
18
+ dispatch_id: "testing-dispatch-id",
19
+ } }
20
+
21
+ before do
22
+ against_real_scorm_engine do
23
+ ensure_course_exists(course_options.merge(client: subject))
24
+ ensure_destination_exists(destination_options.merge(client: subject))
25
+ ensure_dispatch_exists(dispatch_options.merge(client: subject))
26
+ end
27
+ end
28
+
29
+ describe "#get_dispatches" do
30
+ let(:dispatches) { subject.get_dispatches }
31
+
32
+ it "is successful" do
33
+ expect(dispatches.success?).to eq true
34
+ end
35
+
36
+ describe "results" do
37
+ it "is an enumerator of dispatch models" do
38
+ expect(dispatches.results).to be_a Enumerator
39
+ expect(dispatches.results.first).to be_a ScormEngine::Models::Dispatch
40
+ end
41
+
42
+ it "sucessfully creates the dispatch attributes" do
43
+ dispatch = dispatches.results.detect { |c| c.id == dispatch_options[:dispatch_id] }
44
+ aggregate_failures do
45
+ expect(dispatch.destination_id).to eq dispatch_options[:destination_id]
46
+ expect(dispatch.course_id).to eq dispatch_options[:course_id]
47
+ end
48
+ end
49
+ end
50
+
51
+ describe ":since option" do
52
+ it "works" do
53
+ dispatches = subject.get_dispatches(since: Time.parse("2000-01-1 00:00:00 UTC"))
54
+ aggregate_failures do
55
+ expect(dispatches.success?).to eq true
56
+ expect(dispatches.results.to_a.size).to be >= 0
57
+ end
58
+ end
59
+
60
+ it "fails when passed an invalid value" do
61
+ dispatches = subject.get_dispatches(since: "invalid")
62
+ aggregate_failures do
63
+ expect(dispatches.success?).to eq false
64
+ expect(dispatches.status).to eq 400
65
+ expect(dispatches.results.to_a).to eq []
66
+ expect(dispatches.message).to match(/'invalid' is either not a timestamp or seems to be not formatted according to ISO 8601/)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe ":more option (pagination)" do
72
+ before do
73
+ against_real_scorm_engine do
74
+ 11.times do |idx|
75
+ ensure_dispatch_exists(dispatch_options.merge(client: subject, dispatch_id: "paginated-dispatch-#{idx}"))
76
+ end
77
+ end
78
+ end
79
+
80
+ it "returns the :more key in the raw response" do
81
+ expect(subject.get_dispatches.raw_response.body["more"]).to match(%r{https?://.*&more=.+})
82
+ end
83
+
84
+ it "returns all the dispatches" do
85
+ expect(subject.get_dispatches.results.to_a.size).to be >= 11 # there may be other ones beyond those we just added
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "#post_dispatch" do
91
+ it "is successful" do
92
+ subject.delete_dispatch(dispatch_options)
93
+ response = subject.post_dispatch(dispatch_options)
94
+ aggregate_failures do
95
+ expect(response.success?).to eq true
96
+ expect(response.status).to eq 204
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#get_dispatch" do
102
+ let(:response) { subject.get_dispatch(dispatch_id: dispatch_options[:dispatch_id]) }
103
+
104
+ it "is successful" do
105
+ expect(response.success?).to eq true
106
+ end
107
+
108
+ describe "results" do
109
+ it "sucessfully creates the dispatch attributes" do
110
+ dispatch = response.result
111
+ aggregate_failures do
112
+ expect(dispatch.destination_id).to eq dispatch_options[:destination_id]
113
+ expect(dispatch.course_id).to eq dispatch_options[:course_id]
114
+ end
115
+ end
116
+ end
117
+
118
+ it "fails when id is invalid" do
119
+ response = subject.get_dispatch(dispatch_id: "nonexistent-dispatch")
120
+ aggregate_failures do
121
+ expect(response.success?).to eq false
122
+ expect(response.status).to eq 404
123
+ expect(response.message).to match(/No dispatches found with ID: nonexistent-dispatch/)
124
+ expect(response.result).to eq nil
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "#put_dispatch" do
130
+ let(:response) { subject.put_dispatch(dispatch_options.merge(allow_new_registrations: false, instanced: false, registration_cap: 123, expiration_date: "2018-01-01")) }
131
+
132
+ it "is successful" do
133
+ expect(response.success?).to eq true
134
+ end
135
+
136
+ describe "results" do
137
+ it "sucessfully creates the dispatch attributes" do
138
+ response # trigger the put
139
+ response = subject.get_dispatch(dispatch_id: dispatch_options[:dispatch_id])
140
+ dispatch = response.result
141
+ aggregate_failures do
142
+ expect(dispatch.allow_new_registrations).to eq false
143
+ expect(dispatch.instanced).to eq false
144
+ expect(dispatch.registration_cap).to eq 123
145
+ expect(dispatch.expiration_date.to_date).to eq Date.new(2018, 1, 1)
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ describe "#delete_dispatch" do
152
+ before do
153
+ against_real_scorm_engine do
154
+ ensure_dispatch_exists(dispatch_options.merge(client: subject, dispatch_id: "dispatch-to-be-deleted"))
155
+ end
156
+ end
157
+
158
+ it "works" do
159
+ response = subject.delete_dispatch(dispatch_id: "dispatch-to-be-deleted")
160
+ expect(response.success?).to eq true
161
+ expect(response.status).to eq 204
162
+ end
163
+
164
+ it "raises ArgumentError when :dispatch_id is missing" do
165
+ expect { subject.delete_dispatch }.to raise_error(ArgumentError, /dispatch_id missing/)
166
+ end
167
+
168
+ it "returns success even when id is invalid" do
169
+ response = subject.delete_dispatch(dispatch_id: "nonexistent-dispatch")
170
+ expect(response.success?).to eq true
171
+ expect(response.status).to eq 204
172
+ end
173
+ end
174
+
175
+ describe "#get_dispatch_enabled" do
176
+ it "is true when enabled" do
177
+ subject.put_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id], enabled: true)
178
+ response = subject.get_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id])
179
+ aggregate_failures do
180
+ expect(response.success?).to eq true
181
+ expect(response.status).to eq 200
182
+ expect(response.result).to eq true
183
+ end
184
+ end
185
+
186
+ it "is false when disabled" do
187
+ subject.put_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id], enabled: false)
188
+ response = subject.get_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id])
189
+ aggregate_failures do
190
+ expect(response.success?).to eq true
191
+ expect(response.status).to eq 200
192
+ expect(response.result).to eq false
193
+ end
194
+ end
195
+ end
196
+
197
+ describe "#put_dispatch_enabled" do
198
+ it "works when true" do
199
+ response = subject.put_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id], enabled: true)
200
+ expect(response.success?).to eq true
201
+ expect(response.status).to eq 204
202
+ end
203
+
204
+ it "works when false" do
205
+ response = subject.put_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id], enabled: false)
206
+ expect(response.success?).to eq true
207
+ expect(response.status).to eq 204
208
+ end
209
+
210
+ it "fails when invalid" do
211
+ response = subject.put_dispatch_enabled(dispatch_id: dispatch_options[:dispatch_id], enabled: "oops")
212
+ expect(response.success?).to eq false
213
+ expect(response.status).to eq 400
214
+ end
215
+ end
216
+
217
+ describe "#get_dispatch_zip" do
218
+ it "works" do
219
+ response = subject.get_dispatch_zip(dispatch_id: dispatch_options[:dispatch_id])
220
+ aggregate_failures do
221
+ expect(response.success?).to eq true
222
+ expect(response.status).to eq 200
223
+ expect(response.result.dispatch_id).to eq dispatch_options[:dispatch_id]
224
+ expect(response.result.type).to eq "SCORM12"
225
+ expect(response.result.filename).to end_with("golf_club_dispatch_testing-dispatch-id.zip")
226
+
227
+ zip_contents = Zip::File.open_buffer(StringIO.new(response.result.body)).each_entry.map(&:name)
228
+ expect(zip_contents).to include("blank.html", "configuration.js", "dispatch.html", "goodbye.html") # sampling
229
+ end
230
+ end
231
+
232
+ it "works when type is SCORM12" do
233
+ response = subject.get_dispatch_zip(dispatch_id: dispatch_options[:dispatch_id], type: "SCORM12")
234
+ aggregate_failures do
235
+ expect(response.success?).to eq true
236
+ expect(response.result.type).to eq "SCORM12"
237
+
238
+ zip_contents = Zip::File.open_buffer(StringIO.new(response.result.body)).each_entry.map(&:name)
239
+ expect(zip_contents).to include("blank.html", "configuration.js", "dispatch.html", "goodbye.html") # sampling
240
+ end
241
+ end
242
+
243
+ it "works when type is SCORM20043RDEDITION" do
244
+ pending "https://basecamp.com/2819363/projects/15019959/messages/80053329"
245
+ response = subject.get_dispatch_zip(dispatch_id: dispatch_options[:dispatch_id], type: "SCORM20043RDEDITION")
246
+ aggregate_failures do
247
+ expect(response.success?).to eq true
248
+ expect(response.result.type).to eq "SCORM20043RDEDITION"
249
+
250
+ zip_contents = Zip::File.open_buffer(StringIO.new(response.result.body)).each_entry.map(&:name)
251
+ expect(zip_contents).to include("blank.html", "configuration.js", "dispatch.html", "goodbye.html") # sampling
252
+ end
253
+ end
254
+
255
+ it "works when type is AICC" do
256
+ response = subject.get_dispatch_zip(dispatch_id: dispatch_options[:dispatch_id], type: "AICC")
257
+ aggregate_failures do
258
+ expect(response.success?).to eq true
259
+ expect(response.result.type).to eq "AICC"
260
+
261
+ zip_contents = Zip::File.open_buffer(StringIO.new(response.result.body)).each_entry.map(&:name)
262
+ expect(zip_contents).to include("blank.html", "configuration.js", "dispatch.html", "goodbye.html") # sampling
263
+ end
264
+ end
265
+
266
+ it "fails given an invalid id" do
267
+ response = subject.get_dispatch_zip(dispatch_id: "nonexistent-dispatch")
268
+ aggregate_failures do
269
+ expect(response.success?).to eq false
270
+ expect(response.status).to eq 404
271
+ expect(response.result).to eq nil
272
+ expect(response.message).to eq "No dispatches found with ID: nonexistent-dispatch"
273
+ end
274
+ end
275
+
276
+ it "fails given an invalid type" do
277
+ response = subject.get_dispatch_zip(dispatch_id: dispatch_options[:dispatch_id], type: "OOPS")
278
+ aggregate_failures do
279
+ expect(response.success?).to eq false
280
+ expect(response.status).to eq 500
281
+ expect(response.result).to eq nil
282
+ expect(response.message).to eq "The value 'OOPS' is not a valid Dispatch Type."
283
+ end
284
+ end
285
+ end
286
+ end
@@ -159,6 +159,18 @@ RSpec.describe ScormEngine::Api::Endpoints::Registrations do
159
159
  end
160
160
  end
161
161
 
162
+ it "is successful even when given a UTF8/slashed username" do
163
+ options = registration_options.dup
164
+ options[:learner][:first_name] = "Släshy"
165
+ options[:learner][:last_name] = "Mč/Slásh\Facę"
166
+ subject.delete_registration(options)
167
+ response = subject.post_registration(options)
168
+ aggregate_failures do
169
+ expect(response.success?).to eq true
170
+ expect(response.status).to eq 204
171
+ end
172
+ end
173
+
162
174
  it "fails if course_id is invalid" do
163
175
  response = subject.post_registration(registration_options.merge(course_id: "invalid-bogus"))
164
176
  aggregate_failures do
@@ -0,0 +1,21 @@
1
+ RSpec.describe ScormEngine::Models::Destination do
2
+ describe ".new_from_api" do
3
+ describe ":name" do
4
+ it "is set when passed at the root level" do
5
+ destination = described_class.new_from_api(
6
+ "name" => "test"
7
+ )
8
+ expect(destination.name).to eq "test"
9
+ end
10
+
11
+ it "is set when passed at within `data`" do
12
+ destination = described_class.new_from_api(
13
+ "data" => {
14
+ "name" => "test"
15
+ }
16
+ )
17
+ expect(destination.name).to eq "test"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,85 @@
1
+ RSpec.describe ScormEngine::Models::Dispatch do
2
+ describe ".new_from_api" do
3
+ describe ":destination_id" do
4
+ it "is set" do
5
+ dispatch = described_class.new_from_api(
6
+ "data" => {
7
+ "destinationId" => "dest-id"
8
+ }
9
+ )
10
+ expect(dispatch.destination_id).to eq "dest-id"
11
+ end
12
+ end
13
+
14
+ describe ":course_id" do
15
+ it "is set" do
16
+ dispatch = described_class.new_from_api(
17
+ "data" => {
18
+ "courseId" => "course-id"
19
+ }
20
+ )
21
+ expect(dispatch.course_id).to eq "course-id"
22
+ end
23
+ end
24
+
25
+ describe ":allow_new_registrations" do
26
+ it "is set" do
27
+ dispatch = described_class.new_from_api(
28
+ "data" => {
29
+ "allowNewRegistrations" => true
30
+ }
31
+ )
32
+ expect(dispatch.allow_new_registrations).to eq true
33
+ end
34
+ end
35
+
36
+ describe ":instanced" do
37
+ it "is set" do
38
+ dispatch = described_class.new_from_api(
39
+ "data" => {
40
+ "instanced" => true
41
+ }
42
+ )
43
+ expect(dispatch.instanced).to eq true
44
+ end
45
+ end
46
+
47
+ describe ":registration_cap" do
48
+ it "is set" do
49
+ dispatch = described_class.new_from_api(
50
+ "data" => {
51
+ "registrationCap" => "123"
52
+ }
53
+ )
54
+ expect(dispatch.registration_cap).to eq 123
55
+ end
56
+ end
57
+
58
+ describe ":expiration_date" do
59
+ it "is set" do
60
+ dispatch = described_class.new_from_api(
61
+ "data" => {
62
+ "expirationDate" => "2018-05-24"
63
+ }
64
+ )
65
+ expect(dispatch.expiration_date.to_date).to eq Date.new(2018, 5, 24)
66
+ end
67
+
68
+ it "is set to nil if blank" do
69
+ dispatch = described_class.new_from_api({})
70
+ expect(dispatch.expiration_date).to eq nil
71
+ end
72
+ end
73
+
74
+ describe ":external_config" do
75
+ it "is set" do
76
+ dispatch = described_class.new_from_api(
77
+ "data" => {
78
+ "externalConfig" => "this one goes to 11"
79
+ }
80
+ )
81
+ expect(dispatch.external_config).to eq "this one goes to 11"
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.describe ScormEngine::Models::DispatchZip do
2
+ describe ".new" do
3
+ it "set the attributes correctly" do
4
+ dispatch_zip = described_class.new(
5
+ dispatch_id: 123,
6
+ type: "SCORM12",
7
+ filename: "dispatch.zip",
8
+ body: "raw zip string",
9
+ )
10
+ aggregate_failures do
11
+ expect(dispatch_zip.dispatch_id).to eq 123
12
+ expect(dispatch_zip.type).to eq "SCORM12"
13
+ expect(dispatch_zip.filename).to eq "dispatch.zip"
14
+ expect(dispatch_zip.body).to eq "raw zip string"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -65,6 +65,27 @@ module ScormEngineHelpers
65
65
  return if response&.result
66
66
  options[:client].post_registration(options)
67
67
  end
68
+
69
+ #
70
+ # Ensure that the specified destination exists in SCORM engine.
71
+ #
72
+ def ensure_destination_exists(options = {})
73
+ response = options[:client].get_destination(destination_id: options[:destination_id])
74
+ if response&.result.nil?
75
+ options[:client].post_destination(options)
76
+ elsif options.key?(:name) && response&.result&.name != options[:name]
77
+ options[:client].put_destination(options)
78
+ end
79
+ end
80
+
81
+ #
82
+ # Ensure that the specified dispatch exists in SCORM engine.
83
+ #
84
+ def ensure_dispatch_exists(options = {})
85
+ response = options[:client].get_dispatch(dispatch_id: options[:dispatch_id])
86
+ options[:client].post_dispatch(options) if response&.result.nil?
87
+ end
88
+
68
89
  end
69
90
 
70
91
  RSpec.configure do |c|