ims_caliper 0.1.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.
- checksums.yaml +15 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +16 -0
- data/README.md +16 -0
- data/caliper.gemspec +26 -0
- data/config/locales/en.yml +86 -0
- data/lib/caliper/client.rb +33 -0
- data/lib/caliper/consumer/base.rb +46 -0
- data/lib/caliper/consumer/queue.rb +40 -0
- data/lib/caliper/consumer/socket.rb +132 -0
- data/lib/caliper/defaults.rb +8 -0
- data/lib/caliper/entities/annotation/annotation.rb +29 -0
- data/lib/caliper/entities/annotation/bookmark_annotation.rb +17 -0
- data/lib/caliper/entities/annotation/highlight_annotation.rb +18 -0
- data/lib/caliper/entities/annotation/shared_annotation.rb +18 -0
- data/lib/caliper/entities/annotation/tag_annotation.rb +17 -0
- data/lib/caliper/entities/annotation/text_position_selector.rb +14 -0
- data/lib/caliper/entities/digital_resource.rb +52 -0
- data/lib/caliper/entities/entity.rb +44 -0
- data/lib/caliper/entities/foaf/agent.rb +12 -0
- data/lib/caliper/entities/generatable.rb +9 -0
- data/lib/caliper/entities/learning_context.rb +21 -0
- data/lib/caliper/entities/lis/course_section.rb +18 -0
- data/lib/caliper/entities/lis/organization.rb +22 -0
- data/lib/caliper/entities/lis/person.rb +12 -0
- data/lib/caliper/entities/outcome/result.rb +23 -0
- data/lib/caliper/entities/reading/epub_chapter.rb +20 -0
- data/lib/caliper/entities/reading/epub_part.rb +20 -0
- data/lib/caliper/entities/reading/epub_sub_chapter.rb +20 -0
- data/lib/caliper/entities/reading/epub_volume.rb +20 -0
- data/lib/caliper/entities/reading/frame.rb +32 -0
- data/lib/caliper/entities/schemadotorg/audio_object.rb +15 -0
- data/lib/caliper/entities/schemadotorg/creative_work.rb +12 -0
- data/lib/caliper/entities/schemadotorg/image_object.rb +15 -0
- data/lib/caliper/entities/schemadotorg/media_object.rb +19 -0
- data/lib/caliper/entities/schemadotorg/software_application.rb +11 -0
- data/lib/caliper/entities/schemadotorg/thing.rb +9 -0
- data/lib/caliper/entities/schemadotorg/video_object.rb +15 -0
- data/lib/caliper/entities/schemadotorg/web_page.rb +11 -0
- data/lib/caliper/entities/session.rb +26 -0
- data/lib/caliper/entities/software_application.rb +19 -0
- data/lib/caliper/entities/targetable.rb +12 -0
- data/lib/caliper/entities/web_page.rb +13 -0
- data/lib/caliper/event/.shared.rb.swp +0 -0
- data/lib/caliper/event/annotation_event.rb +14 -0
- data/lib/caliper/event/event.rb +68 -0
- data/lib/caliper/event/media_event.rb +19 -0
- data/lib/caliper/event/navigation_event.rb +23 -0
- data/lib/caliper/event/outcome_event.rb +20 -0
- data/lib/caliper/event/session_event.rb +21 -0
- data/lib/caliper/event/view_event.rb +20 -0
- data/lib/caliper/options.rb +18 -0
- data/lib/caliper/profiles/annotation_profile.rb +61 -0
- data/lib/caliper/profiles/profile.rb +46 -0
- data/lib/caliper/profiles/reading_profile.rb +36 -0
- data/lib/caliper/profiles/session_profile.rb +29 -0
- data/lib/caliper/request/event_store_envelope.rb +9 -0
- data/lib/caliper/request/event_store_requestor.rb +41 -0
- data/lib/caliper/request/http_requestor.rb +42 -0
- data/lib/caliper/sensor.rb +37 -0
- data/lib/caliper/stats/atomic_wrapper.rb +86 -0
- data/lib/caliper/stats/statistic.rb +104 -0
- data/lib/caliper/stats/statistics.rb +45 -0
- data/lib/caliper/stats/statistics_map.rb +39 -0
- data/lib/caliper/validators/error_message.rb +43 -0
- data/lib/caliper/validators/event_validator.rb +37 -0
- data/lib/caliper/validators/event_validator_context.rb +16 -0
- data/lib/caliper/validators/property_type_check.rb +14 -0
- data/lib/caliper/validators/session_login_event_validator.rb +103 -0
- data/lib/caliper/validators/session_logout_event_validator.rb +102 -0
- data/lib/caliper/validators/time_check.rb +30 -0
- data/lib/caliper/version.rb +4 -0
- data/lib/caliper.rb +17 -0
- data/spec/lib/client_spec.rb +35 -0
- data/spec/lib/consumer/base_spec.rb +28 -0
- data/spec/lib/consumer/queue_spec.rb +16 -0
- data/spec/lib/event/annotation_spec.rb +12 -0
- data/spec/lib/event/bookmarked_spec.rb +17 -0
- data/spec/lib/event/commented_spec.rb +19 -0
- data/spec/lib/event/highlighted_spec.rb +18 -0
- data/spec/lib/event/navigation_spec.rb +15 -0
- data/spec/lib/event/shared_spec.rb +18 -0
- data/spec/lib/event/tagged_spec.rb +17 -0
- data/spec/lib/event/used_spec.rb +15 -0
- data/spec/lib/event/viewed_spec.rb +15 -0
- data/spec/spec_helper.rb +26 -0
- data/test/caliper/events/session_login_event_test.rb +58 -0
- data/test/caliper/events/session_logout_event_test.rb +55 -0
- data/test/caliper/events/session_timeout_event_test.rb +55 -0
- data/test/caliper/request/http_requestor_test.rb +59 -0
- data/test/caliper/test_event.rb +53 -0
- data/test/caliper/test_utils.rb +198 -0
- data/test/fixtures/caliper_session_login_event.json +71 -0
- data/test/fixtures/caliper_session_logout_event.json +52 -0
- data/test/fixtures/caliper_session_timeout_event.json +52 -0
- data/test/fixtures/event_store_payload.json +85 -0
- metadata +165 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'event_validator'
|
2
|
+
require_relative 'error_message'
|
3
|
+
require_relative 'property_type_check'
|
4
|
+
require_relative 'time_check'
|
5
|
+
require_relative '../event/event'
|
6
|
+
require_relative '../profiles/profile'
|
7
|
+
require_relative '../entities/lis/person'
|
8
|
+
require_relative '../entities/digital_resource'
|
9
|
+
require_relative '../entities/session'
|
10
|
+
require_relative '../entities/schemadotorg/software_application'
|
11
|
+
|
12
|
+
|
13
|
+
module Caliper
|
14
|
+
module Validators
|
15
|
+
class SessionLoginEventValidator
|
16
|
+
include EventValidator
|
17
|
+
include TimeCheck
|
18
|
+
|
19
|
+
## Validate session login event properties.
|
20
|
+
# Properties
|
21
|
+
# context:: required
|
22
|
+
# type:: required
|
23
|
+
# edApp:: optional
|
24
|
+
# group:: optional
|
25
|
+
# actor:: required: Person
|
26
|
+
# action:: required: session.loggedIn
|
27
|
+
# object:: required: SoftwareApplication
|
28
|
+
# target:: required: DigitalResource
|
29
|
+
# generated:: required: Session
|
30
|
+
# startedAtTime:: required
|
31
|
+
# endedAtTime:: optional: but should not be set.
|
32
|
+
# duration:: optional: but should not be set.
|
33
|
+
# returns conformance violations message.
|
34
|
+
def validate(event)
|
35
|
+
context = "session"
|
36
|
+
error_message = ErrorMessage.new
|
37
|
+
property_check = PropertyTypeCheck.new
|
38
|
+
|
39
|
+
|
40
|
+
if (!event.is_a?(Event))
|
41
|
+
# check whether the argument is of right type
|
42
|
+
return
|
43
|
+
else
|
44
|
+
# is event context of Session
|
45
|
+
if (!event.context.equal?(EventType::SESSION))
|
46
|
+
error_message.append_text(event.context + " " + ProfileConformance::CONTEXT_ERROR)
|
47
|
+
end
|
48
|
+
|
49
|
+
# is event type of Session
|
50
|
+
if (!event.type.equal?(EventType::SESSION))
|
51
|
+
error_message.append_text(event.type + " " + ProfileConformance::TYPE_ERROR)
|
52
|
+
end
|
53
|
+
|
54
|
+
# is event actor a Person
|
55
|
+
if (!property_check.is_object_of_type(event.actor, Person.class))
|
56
|
+
error_message.append_text(event.actor.class + " " + ProfileConformance::ACTOR_NOT_PERSON)
|
57
|
+
end
|
58
|
+
|
59
|
+
# is event object a SoftwareApplication
|
60
|
+
if (!property_check.is_object_of_type(event.object, SoftwareApplication.class))
|
61
|
+
error_message.append_text(event.object.class + " " + ProfileConformance::OBJECT_NOT_SOFTWAREAPP)
|
62
|
+
end
|
63
|
+
|
64
|
+
# is event target a DigitalResource
|
65
|
+
if (!property_check.is_object_of_type(event.target, DigitalResource.class))
|
66
|
+
error_message.append_text(event.object.class + " " + ProfileConformance::TARGET_NOT_DIGITALRESOURCE)
|
67
|
+
end
|
68
|
+
|
69
|
+
if (property_check.is_object_of_type(event.generated, Session.class))
|
70
|
+
if (event.generated.started_at_time == 0)
|
71
|
+
error_message.append_text(context + " " + ProfileConformance::STARTEDATTIME_IS_NULL)
|
72
|
+
elsif (event.generated.end_at_time != 0)
|
73
|
+
error_message.append_text(context + " " + ProfileConformance::ENDEDATTIME_SET)
|
74
|
+
end
|
75
|
+
else
|
76
|
+
error_message.append_text(ProfileConformance::GENERATED_NOT_SESSION)
|
77
|
+
end
|
78
|
+
|
79
|
+
# start time set for event
|
80
|
+
if (!check_started_at_time(event.started_at_time))
|
81
|
+
error_message.append_text(ProfileConformance::STARTEDATTIME_IS_NULL)
|
82
|
+
end
|
83
|
+
|
84
|
+
# also check the event end time
|
85
|
+
if (!check_ended_at_time(event.started_at_time, event.ended_at_time))
|
86
|
+
error_message.append_text(ProfileConformance::TIME_ERROR)
|
87
|
+
end
|
88
|
+
|
89
|
+
# check duration value
|
90
|
+
if (check_duration(event.duration))
|
91
|
+
error_message.append_text(ProfileConformance::DURATION_INVALID)
|
92
|
+
end
|
93
|
+
|
94
|
+
if (error_message.length() > 0)
|
95
|
+
error_message.end_message("Caliper Session profile login event conformance: ")
|
96
|
+
end
|
97
|
+
|
98
|
+
return error_message.text
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative 'event_validator'
|
2
|
+
require_relative 'error_message'
|
3
|
+
require_relative 'property_type_check'
|
4
|
+
require_relative 'time_check'
|
5
|
+
require_relative '../event/event'
|
6
|
+
require_relative '../profiles/profile'
|
7
|
+
require_relative '../entities/lis/person'
|
8
|
+
require_relative '../entities/digital_resource'
|
9
|
+
require_relative '../entities/session'
|
10
|
+
require_relative '../entities/schemadotorg/software_application'
|
11
|
+
|
12
|
+
|
13
|
+
module Caliper
|
14
|
+
module Validators
|
15
|
+
class SessionLogoutEventValidator
|
16
|
+
include EventValidator
|
17
|
+
include TimeCheck
|
18
|
+
|
19
|
+
Validate session logout event properties.
|
20
|
+
*
|
21
|
+
## Validate SessionEvent.
|
22
|
+
# An IllegalStateException will be thrown as a defensive measure if programing
|
23
|
+
# errors are encountered during object construction.
|
24
|
+
# Properties
|
25
|
+
# context:: required
|
26
|
+
# type:: required
|
27
|
+
# edApp:: optional
|
28
|
+
# group:: optional
|
29
|
+
# actor:: required: Person
|
30
|
+
# action:: required: session.loggedIn
|
31
|
+
# object:: required: SoftwareApplication
|
32
|
+
# target:: required: DigitalResource
|
33
|
+
# generated:: required: Session
|
34
|
+
# startedAtTime:: required
|
35
|
+
# endedAtTime:: optional: but should not be set.
|
36
|
+
# duration:: optional: but should not be set.
|
37
|
+
# returns conformance violations message.
|
38
|
+
def validate(event)
|
39
|
+
context = "session"
|
40
|
+
error_message = ErrorMessage.new
|
41
|
+
property_check = PropertyTypeCheck.new
|
42
|
+
|
43
|
+
|
44
|
+
if (!event.is_a?(Event))
|
45
|
+
# check whether the argument is of right type
|
46
|
+
return
|
47
|
+
else
|
48
|
+
# is event context of Session
|
49
|
+
if (!event.context.equal?(EventType::SESSION))
|
50
|
+
error_message.append_text(event.context + " " + ProfileConformance::CONTEXT_ERROR)
|
51
|
+
end
|
52
|
+
|
53
|
+
# is event type of Session
|
54
|
+
if (!event.type.equal?(EventType::SESSION))
|
55
|
+
error_message.append_text(event.type + " " + ProfileConformance::TYPE_ERROR)
|
56
|
+
end
|
57
|
+
|
58
|
+
# is event actor a Person
|
59
|
+
if (!property_check.is_object_of_type(event.actor, Person.class))
|
60
|
+
error_message.append_text(event.actor.class + " " + ProfileConformance::ACTOR_NOT_PERSON)
|
61
|
+
end
|
62
|
+
|
63
|
+
# is event object a SoftwareApplication
|
64
|
+
if (!property_check.is_object_of_type(event.object, SoftwareApplication.class))
|
65
|
+
error_message.append_text(event.object.class + " " + ProfileConformance::OBJECT_NOT_SOFTWAREAPP)
|
66
|
+
end
|
67
|
+
|
68
|
+
# is event target a DigitalResource
|
69
|
+
if (!property_check.is_object_of_type(event.target, Session.class))
|
70
|
+
error_message.append_text(event.object.class + " " + ProfileConformance::TARGET_NOT_SESSION)
|
71
|
+
end
|
72
|
+
|
73
|
+
# should not be generated
|
74
|
+
if (event.generated)
|
75
|
+
message.appendText(Profile.Conformance.GENERATED_NOT_NULL.violation());
|
76
|
+
end
|
77
|
+
|
78
|
+
# start time set for event
|
79
|
+
if (!check_started_at_time(event.started_at_time))
|
80
|
+
error_message.append_text(ProfileConformance::STARTEDATTIME_IS_NULL)
|
81
|
+
end
|
82
|
+
|
83
|
+
# also check the event end time
|
84
|
+
if (!check_ended_at_time(event.started_at_time, event.ended_at_time))
|
85
|
+
error_message.append_text(ProfileConformance::TIME_ERROR)
|
86
|
+
end
|
87
|
+
|
88
|
+
# check duration value
|
89
|
+
if (check_duration(event.duration))
|
90
|
+
error_message.append_text(ProfileConformance::DURATION_INVALID)
|
91
|
+
end
|
92
|
+
|
93
|
+
if (error_message.length > 0)
|
94
|
+
error_message.end_message("Caliper Session profile login event conformance: ")
|
95
|
+
end
|
96
|
+
|
97
|
+
return error_message.text
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Caliper
|
2
|
+
module Validators
|
3
|
+
module TimeCheck
|
4
|
+
|
5
|
+
# validate startedAtTime
|
6
|
+
def check_started_at_time(started_at_time)
|
7
|
+
return started_at_time > 0
|
8
|
+
end
|
9
|
+
|
10
|
+
# Event ended_at_time is an optional setting.
|
11
|
+
# If both a started_at_time and ended_at_aime are specified
|
12
|
+
# check that startedAtTime precedes endedAtTime. If not return false.
|
13
|
+
def check_ended_at_time(started_at_time, ended_at_time)
|
14
|
+
if (check_started_at_time(started_at_time))
|
15
|
+
return ended_at_time >= started_at_time
|
16
|
+
else
|
17
|
+
return true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_duration(duration)
|
22
|
+
if (!duration.nil? && !duration.length == 0)
|
23
|
+
return true
|
24
|
+
else
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/caliper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Caliper
|
2
|
+
autoload :Client, "caliper/client"
|
3
|
+
|
4
|
+
module Consumer
|
5
|
+
autoload :Base, "caliper/consumer/base"
|
6
|
+
autoload :Queue, "caliper/consumer/queue"
|
7
|
+
autoload :Socket, "caliper/consumer/socket"
|
8
|
+
end
|
9
|
+
|
10
|
+
module Event
|
11
|
+
autoload :Base, "caliper/event/base"
|
12
|
+
end
|
13
|
+
|
14
|
+
module Entities
|
15
|
+
autoload :Base, "caliper/entity/base"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
module Caliper
|
4
|
+
describe Client do
|
5
|
+
it "should throw error if provided consumer is invalid" do
|
6
|
+
expect(lambda{ Client.new("some API key", :consumer => "ThisClassTotally::DoesntExist") }).to raise_error(NameError)
|
7
|
+
expect(lambda{ Client.new("some API key", :consumer => Object) }).to raise_error(ArgumentError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should throw error if provided an invalid event" do
|
11
|
+
expect(lambda{ Client.new("some API key").measure(Object.new) }).to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should call the appropriate method on the consumer" do
|
15
|
+
consumer = Consumer::Base.new("some API key")
|
16
|
+
client = Client.new("some API key", :consumer => consumer)
|
17
|
+
consumer.expects(:measure)
|
18
|
+
consumer.expects(:describe)
|
19
|
+
|
20
|
+
client.measure(Event::Base.new)
|
21
|
+
client.describe(Entity::Base.new)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should default to current if timestamps are not provided" do
|
25
|
+
consumer = Consumer::Base.new("some API key")
|
26
|
+
client = Client.new("some API key", :consumer => consumer)
|
27
|
+
t = Time.now
|
28
|
+
Time.stubs(:now).returns(t)
|
29
|
+
consumer.expects(:measure).with(anything, anything, anything, t)
|
30
|
+
#todo same for describe
|
31
|
+
client.measure(Event::Base.new)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
module Caliper
|
4
|
+
module Consumer
|
5
|
+
describe Base do
|
6
|
+
it "should validate options hash" do
|
7
|
+
b = Base.new("Some API key")
|
8
|
+
expect(b.validate_options({:debug= => true, :ssl => false, :on_error => lambda { "blah blah" }, :some_other_key => "This will be ignored"})).not_to include(:some_other_key)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should enable debug and ssl" do
|
12
|
+
b = Base.new("Some API key", :debug => true, :ssl => true)
|
13
|
+
expect(b.with_debug?).to be_truthy
|
14
|
+
expect(b.with_ssl?).to be_truthy
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#on_error" do
|
18
|
+
it "should call custom error handler" do
|
19
|
+
Object.stubs(:non_existent_method).returns(true)
|
20
|
+
p = proc { |e| Object.non_existent_method }
|
21
|
+
Object.expects(:non_existent_method).once
|
22
|
+
b = Base.new("Some API key", :on_error => p)
|
23
|
+
b.on_error("Some error")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
module Caliper
|
4
|
+
module Consumer
|
5
|
+
describe Queue do
|
6
|
+
it "should store max_queue_size and batch_size" do
|
7
|
+
max = 1000
|
8
|
+
batch = 100
|
9
|
+
c = Queue.new("some API key", :max_queue_size => max, :batch_size => batch)
|
10
|
+
expect(c.max_queue_size).to equal(max)
|
11
|
+
expect(c.batch_size).to equal(batch)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Annotation do
|
7
|
+
it "should raise error if instantiated directly" do
|
8
|
+
expect(lambda{ Annotation.new("action") }).to raise_error NotImplementedError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Bookmarked do
|
7
|
+
it "should be a BookmarkedEvent" do
|
8
|
+
expect(Bookmarked.new("action").type).to eq "BookmarkedEvent"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a 'marked' or 'unmarked' action, as appropriate" do
|
12
|
+
expect(Bookmarked.mark.action).to eq "marked"
|
13
|
+
expect(Bookmarked.unmark.action).to eq "unmarked"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Commented do
|
7
|
+
it "should be a CommentedEvent" do
|
8
|
+
expect(Commented.new("action").type).to eq "CommentedEvent"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have 'commented', 'comment-updated', or 'uncommented' actions, as appropriate" do
|
12
|
+
expect(Commented.add_comment.action).to eq "commented"
|
13
|
+
expect(Commented.remove_comment.action).to eq "uncommented"
|
14
|
+
expect(Commented.update_comment.action).to eq "comment-updated"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Highlighted do
|
7
|
+
it "should be a HighlightedEvent" do
|
8
|
+
expect(Highlighted.new("action").type).to eq "HighlightedEvent"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a 'highlighted' or 'unhighlighted' action, as appropriate" do
|
12
|
+
expect(Highlighted.highlight.action).to eq "highlighted"
|
13
|
+
expect(Highlighted.unhighlight.action).to eq "unhighlighted"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Navigation do
|
7
|
+
it "should be a NavigationEvent" do
|
8
|
+
e = Navigation.new
|
9
|
+
expect(e.type).to eq "NavigationEvent"
|
10
|
+
expect(e.action).to eq "navigatedTo"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Shared do
|
7
|
+
it "should be a SharedEvent" do
|
8
|
+
expect(Shared.new("action").type).to eq "SharedEvent"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a 'shared' or 'unshared' action, as appropriate" do
|
12
|
+
expect(Shared.share.action).to eq "shared"
|
13
|
+
expect(Shared.unshare.action).to eq "unshared"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Tagged do
|
7
|
+
it "should be a TaggedEvent" do
|
8
|
+
expect(Tagged.new("action").type).to eq "TaggedEvent"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a 'tagged' or 'untagged' action, as appropriate" do
|
12
|
+
expect(Tagged.tag.action).to eq "tagged"
|
13
|
+
expect(Tagged.untag.action).to eq "untagged"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "caliper"
|
3
|
+
|
4
|
+
module Caliper
|
5
|
+
module Event
|
6
|
+
describe Viewed do
|
7
|
+
it "should be a ViewedEvent" do
|
8
|
+
e = Viewed.new
|
9
|
+
expect(e.type).to eq "ViewedEvent"
|
10
|
+
expect(e.action).to eq "viewed"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-rcov'
|
3
|
+
require "caliper"
|
4
|
+
|
5
|
+
SimpleCov.use_merging
|
6
|
+
SimpleCov.merge_timeout(10000)
|
7
|
+
SimpleCov.command_name('open_data_export_gem')
|
8
|
+
SimpleCov.start('test_frameworks') do
|
9
|
+
SimpleCov.coverage_dir('../../coverage')
|
10
|
+
SimpleCov.at_exit {
|
11
|
+
SimpleCov.result
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# ## Mock Framework
|
18
|
+
config.mock_with :mocha
|
19
|
+
|
20
|
+
# Run specs in random order to surface order dependencies. If you find an
|
21
|
+
# order dependency and want to debug it, you can fix the order by providing
|
22
|
+
# the seed, which is printed after each run.
|
23
|
+
# --seed 1234
|
24
|
+
config.order = "random"
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
require '../../../lib/caliper/entities/learning_context'
|
3
|
+
require '../../../lib/caliper/entities/software_application'
|
4
|
+
require '../../../lib/caliper/entities/reading/epub_sub_chapter'
|
5
|
+
require '../../../lib/caliper/entities/session'
|
6
|
+
require '../../../lib/caliper/event/event'
|
7
|
+
|
8
|
+
require_relative "../../../lib/caliper/request/http_requestor"
|
9
|
+
require_relative "../../../lib/caliper/profiles/session_profile"
|
10
|
+
require_relative "../../../lib/caliper/profiles/reading_profile"
|
11
|
+
require_relative "../test_utils"
|
12
|
+
|
13
|
+
require 'i18n'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
class SessionLoginEventTest < Test::Unit::TestCase
|
17
|
+
include I18n::Tests
|
18
|
+
include TestUtils
|
19
|
+
|
20
|
+
attr_accessor :learning_context, # LearningContext
|
21
|
+
:ed_app, # SoftwareApplication
|
22
|
+
:key, # String
|
23
|
+
:target, # EpubSubChapter
|
24
|
+
:generated, # Session
|
25
|
+
:event # Event
|
26
|
+
|
27
|
+
def setup
|
28
|
+
|
29
|
+
p File.expand_path("../../", Dir.pwd) + '/config/locales/en.yml'
|
30
|
+
I18n.load_path = [[File.expand_path("../../..", Dir.pwd) + '/config/locales/en.yml']]
|
31
|
+
I18n.locale = :en
|
32
|
+
# I18n.t("actions.annotation.attached")
|
33
|
+
|
34
|
+
# Build the Learning Context
|
35
|
+
@learning_context = TestUtils.build_readium_learning_context
|
36
|
+
|
37
|
+
# Action
|
38
|
+
@ed_app = learning_context.ed_app
|
39
|
+
|
40
|
+
@key = Caliper::Profiles::SessionActions::LOGGED_IN
|
41
|
+
|
42
|
+
# build target
|
43
|
+
@target = TestUtils.build_epub_sub_chap_431
|
44
|
+
|
45
|
+
# build generated
|
46
|
+
@generated = TestUtils.build_session_start
|
47
|
+
|
48
|
+
# build event
|
49
|
+
@event = TestUtils.build_epub_login_event(@learning_context, @ed_app, @key, @target, @generated)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_caliper_event_serializes_to_json
|
54
|
+
json_payload_fixture = JSON.parse(File.read(File.expand_path("../../", Dir.pwd) + "/fixtures/caliper_session_login_event.json")).to_json
|
55
|
+
assert_equal("Test if loggedIn event is serialized to JSON with expected values",
|
56
|
+
json_payload_fixture, @event.to_json)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
require '../../../lib/caliper/entities/learning_context'
|
3
|
+
require '../../../lib/caliper/entities/software_application'
|
4
|
+
require '../../../lib/caliper/entities/reading/epub_sub_chapter'
|
5
|
+
require '../../../lib/caliper/entities/session'
|
6
|
+
require '../../../lib/caliper/event/event'
|
7
|
+
|
8
|
+
require_relative "../../../lib/caliper/request/http_requestor"
|
9
|
+
require_relative "../../../lib/caliper/profiles/session_profile"
|
10
|
+
require_relative "../../../lib/caliper/profiles/reading_profile"
|
11
|
+
require_relative "../test_utils"
|
12
|
+
|
13
|
+
require 'i18n'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
class SessionLogoutEventTest < Test::Unit::TestCase
|
17
|
+
include I18n::Tests
|
18
|
+
include TestUtils
|
19
|
+
|
20
|
+
attr_accessor :learning_context, # LearningContext
|
21
|
+
:ed_app, # SoftwareApplication
|
22
|
+
:key, # String
|
23
|
+
:target, # EpubSubChapter
|
24
|
+
:event # Event
|
25
|
+
|
26
|
+
def setup
|
27
|
+
|
28
|
+
p File.expand_path("../../", Dir.pwd) + '/config/locales/en.yml'
|
29
|
+
I18n.load_path = [[File.expand_path("../../..", Dir.pwd) + '/config/locales/en.yml']]
|
30
|
+
I18n.locale = :en
|
31
|
+
# I18n.t("actions.annotation.attached")
|
32
|
+
|
33
|
+
# Build the Learning Context
|
34
|
+
@learning_context = TestUtils.build_readium_learning_context
|
35
|
+
|
36
|
+
# Action
|
37
|
+
@ed_app = learning_context.ed_app
|
38
|
+
|
39
|
+
# Action
|
40
|
+
@key = Caliper::Profiles::SessionActions::LOGGED_OUT
|
41
|
+
|
42
|
+
# build target
|
43
|
+
@target = TestUtils.build_session_end
|
44
|
+
|
45
|
+
# build event
|
46
|
+
@event = TestUtils.build_epub_logout_event(@learning_context, @ed_app, @key, @target)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_caliper_event_serializes_to_json
|
51
|
+
json_payload_fixture = JSON.parse(File.read(File.expand_path("../../", Dir.pwd) + "/fixtures/caliper_session_logout_event.json")).to_json
|
52
|
+
assert_equal("Test if loggedIn event is serialized to JSON with expected values",
|
53
|
+
json_payload_fixture, @event.to_json)
|
54
|
+
end
|
55
|
+
end
|