riaction 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/lib/riaction/iactionable/api.rb +4 -43
  3. data/lib/riaction/iactionable/objects/achievement.rb +12 -0
  4. data/lib/riaction/iactionable/objects/awardable.rb +9 -1
  5. data/lib/riaction/iactionable/objects/challenge.rb +11 -0
  6. data/lib/riaction/iactionable/objects/goal.rb +13 -0
  7. data/lib/riaction/iactionable/objects/identifier.rb +8 -0
  8. data/lib/riaction/iactionable/objects/leaderboard.rb +7 -0
  9. data/lib/riaction/iactionable/objects/leaderboard_report.rb +11 -0
  10. data/lib/riaction/iactionable/objects/level.rb +9 -0
  11. data/lib/riaction/iactionable/objects/level_type.rb +7 -0
  12. data/lib/riaction/iactionable/objects/point_type.rb +7 -0
  13. data/lib/riaction/iactionable/objects/profile_achievements.rb +20 -0
  14. data/lib/riaction/iactionable/objects/profile_challenges.rb +20 -0
  15. data/lib/riaction/iactionable/objects/profile_goals.rb +20 -0
  16. data/lib/riaction/iactionable/objects/profile_level.rb +7 -0
  17. data/lib/riaction/iactionable/objects/profile_notifications.rb +29 -0
  18. data/lib/riaction/iactionable/objects/profile_points.rb +12 -0
  19. data/lib/riaction/iactionable/objects/profile_summary.rb +16 -3
  20. data/lib/riaction/iactionable/objects/progress.rb +11 -0
  21. data/lib/riaction/iactionable/objects.rb +4 -0
  22. data/lib/riaction/version.rb +1 -1
  23. data/spec/api_spec.rb +42 -16
  24. data/spec/get_achievements_api_response_spec.rb +46 -0
  25. data/spec/get_challenges_api_response_spec.rb +42 -0
  26. data/spec/get_goals_api_response_spec.rb +46 -0
  27. data/spec/get_leaderboard_api_response_spec.rb +76 -0
  28. data/spec/get_profile_achievements_api_response_spec.rb +99 -0
  29. data/spec/get_profile_api_response_spec.rb +103 -0
  30. data/spec/get_profile_challenges_api_response_spec.rb +85 -0
  31. data/spec/get_profile_goals_api_response_spec.rb +89 -0
  32. data/spec/get_profile_notifications_api_response_spec.rb +75 -0
  33. data/spec/get_profile_points_api_response_spec.rb +67 -0
  34. metadata +40 -16
@@ -0,0 +1,42 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_challenges" do
4
+ before do
5
+ @sample_response = [
6
+ {
7
+ "Key" => "easy_challenge",
8
+ "Description" => "Do something easy 5 times and earn 100 points",
9
+ "Name" => "Easy Challenge"
10
+ },
11
+ {
12
+ "Key" => "hard_challenge",
13
+ "Description" => "Do something hard 10 times and earn 200 points",
14
+ "Name" => "Hard Challenge"
15
+ }
16
+ ]
17
+ end
18
+
19
+ it "should not raise error on wrapping in an object" do
20
+ lambda { @sample_response.map{|data| IActionable::Objects::Challenge.new(data) } }.should_not raise_error
21
+ end
22
+
23
+ describe "when wrapped in an object" do
24
+ before do
25
+ @wrapped = @sample_response.map{|data| IActionable::Objects::Challenge.new(data) }
26
+ end
27
+
28
+ it "should contain ar array of available challenges" do
29
+ @wrapped.should be_instance_of Array
30
+ @wrapped.first.key.should == @sample_response[0]["Key"]
31
+ @wrapped.first.description.should == @sample_response[0]["Description"]
32
+ @wrapped.first.name.should == @sample_response[0]["Name"]
33
+ @wrapped.last.key.should == @sample_response[1]["Key"]
34
+ @wrapped.last.description.should == @sample_response[1]["Description"]
35
+ @wrapped.last.name.should == @sample_response[1]["Name"]
36
+ end
37
+
38
+ it "should convert to a hash equal to the original" do
39
+ hash_including(:array => @sample_response).should == {:array => @wrapped.map{|challenge| challenge.to_hash}}
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_goals" do
4
+ before do
5
+ @sample_response = [
6
+ {
7
+ "Key" => "easy_goal",
8
+ "Description" => "Do something easy 5 times today and earn 100 points",
9
+ "Name" => "Easy Goal",
10
+ "Interval" => "Daily"
11
+ },
12
+ {
13
+ "Key" => "hard_goal",
14
+ "Description" => "Do something hard 10 times this week and earn 200 points",
15
+ "Name" => "Hard Goal",
16
+ "Interval" => "Daily"
17
+ }
18
+ ]
19
+ end
20
+
21
+ it "should not raise error on wrapping in an object" do
22
+ lambda { @sample_response.map{|data| IActionable::Objects::Goal.new(data) } }.should_not raise_error
23
+ end
24
+
25
+ describe "when wrapped in an object" do
26
+ before do
27
+ @wrapped = @sample_response.map{|data| IActionable::Objects::Goal.new(data) }
28
+ end
29
+
30
+ it "should contain ar array of available goals" do
31
+ @wrapped.should be_instance_of Array
32
+ @wrapped.first.key.should == @sample_response[0]["Key"]
33
+ @wrapped.first.description.should == @sample_response[0]["Description"]
34
+ @wrapped.first.name.should == @sample_response[0]["Name"]
35
+ @wrapped.first.interval.should == @sample_response[0]["Interval"]
36
+ @wrapped.last.key.should == @sample_response[1]["Key"]
37
+ @wrapped.last.description.should == @sample_response[1]["Description"]
38
+ @wrapped.last.name.should == @sample_response[1]["Name"]
39
+ @wrapped.last.interval.should == @sample_response[1]["Interval"]
40
+ end
41
+
42
+ it "should convert to a hash equal to the original" do
43
+ hash_including(:array => @sample_response).should == {:array => @wrapped.map{|goal| goal.to_hash}}
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_leaderboard" do
4
+ before do
5
+ @sample_response = {
6
+ "Leaderboard" => {
7
+ "Key" => "weekly_leaderboard",
8
+ "Name" => "Weekly Experience Points Leaderboard"
9
+ },
10
+ "PageCount" => 10,
11
+ "PageNumber" => 1,
12
+ "PointType" => {
13
+ "Key" => "experience_points",
14
+ "Name" => "Experience Points"
15
+ },
16
+ "Profiles" => [
17
+ {
18
+ "DisplayName" => "Jimmy Dean",
19
+ "Identifiers" => [
20
+ {
21
+ "ID" => "100005",
22
+ "IDHash" => "d63c48a193f960380f0ac353eddc25d4",
23
+ "IDType" => "Facebook"
24
+ }
25
+ ],
26
+ "Rank" => 1,
27
+ "Points" => 246
28
+ },
29
+ {
30
+ "DisplayName" => "Jason Barnes",
31
+ "Identifiers" => [
32
+ {
33
+ "ID" => "100010",
34
+ "IDHash" => "d3d33fb3e33963b58f681ed2e98d835c",
35
+ "IDType" => "Facebook"
36
+ },
37
+ {
38
+ "ID" => "email@dot.com",
39
+ "IDHash" => "66a1bd06edcc1a2d208953d441e1374e",
40
+ "IDType" => "Email"
41
+ }
42
+ ],
43
+ "Rank" => 2,
44
+ "Points" => 216
45
+ },
46
+ {
47
+ "DisplayName" => "Ben Burt",
48
+ "Identifiers" => [
49
+ {
50
+ "ID" => "600004",
51
+ "IDHash" => "e567689d28abc93867955ff85324bd08",
52
+ "IDType" => "Facebook"
53
+ }
54
+ ],
55
+ "Rank" => 3,
56
+ "Points" => 50
57
+ }
58
+ ],
59
+ "TotalCount" => 50
60
+ }
61
+ end
62
+
63
+ it "should not raise error on wrapping in an object" do
64
+ lambda { IActionable::Objects::LeaderboardReport.new(@sample_response) }.should_not raise_error
65
+ end
66
+
67
+ describe "when wrapped in an object" do
68
+ before do
69
+ @wrapped = IActionable::Objects::LeaderboardReport.new(Marshal.load(Marshal.dump(@sample_response)))
70
+ end
71
+
72
+ it "should convert to a hash equal to the original" do
73
+ hash_including(@sample_response).should == @wrapped.to_hash
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_profile_achievements" do
4
+ before do
5
+ @sample_response = {
6
+ "Available" => [
7
+ {
8
+ "Key" => "super_user",
9
+ "Description" => "Post 35 Photos and make 50 Comments",
10
+ "ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/99999",
11
+ "Name" => "Super User",
12
+ "Progress" => [
13
+ {
14
+ "ConditionMetDate" => nil,
15
+ "CurrentValue" => 12,
16
+ "Description" => "Post 35 Photos",
17
+ "RequiredValue" => "35"
18
+ },
19
+ {
20
+ "ConditionMetDate" => nil,
21
+ "CurrentValue" => 6,
22
+ "Description" => "Make 50 Comments",
23
+ "RequiredValue" => "50"
24
+ }
25
+ ]
26
+ }
27
+ ],
28
+ "Completed" => [
29
+ {
30
+ "Key" => "you_can_talk",
31
+ "Description" => "Post a Comment on any blog post.",
32
+ "ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/99998",
33
+ "Name" => "You can talk!",
34
+ "Progress" => [
35
+ {
36
+ "ConditionMetDate" => "/Date(1275706032317-0600)/",
37
+ "CurrentValue" => 1,
38
+ "Description" => "Make 1 Comment",
39
+ "RequiredValue" => "1"
40
+ }
41
+ ],
42
+ "AwardDate" => "/Date(1275706032317-0600)/"
43
+ }
44
+ ]
45
+ }
46
+ end
47
+
48
+ it "should not raise error on wrapping in an object" do
49
+ lambda { IActionable::Objects::ProfileAchievements.new(@sample_response) }.should_not raise_error
50
+ end
51
+
52
+ describe "when wrapped in an object" do
53
+ before do
54
+ @wrapped = IActionable::Objects::ProfileAchievements.new(Marshal.load(Marshal.dump(@sample_response)))
55
+ end
56
+
57
+ it "should contain ar array of available achievements" do
58
+ @wrapped.available.should be_instance_of Array
59
+ @wrapped.available.first.key.should == @sample_response["Available"][0]["Key"]
60
+ @wrapped.available.first.description.should == @sample_response["Available"][0]["Description"]
61
+ @wrapped.available.first.image_url.should == @sample_response["Available"][0]["ImageURL"]
62
+ @wrapped.available.first.name.should == @sample_response["Available"][0]["Name"]
63
+ @wrapped.available.first.award_date.should be_nil
64
+ end
65
+
66
+ it "should contain an array of progresses within each available achievement" do
67
+ @wrapped.available.first.progress.should be_instance_of Array
68
+ @wrapped.available.first.progress.first.condition_met_date.should be_nil
69
+ @wrapped.available.first.progress.first.current_value.should == @sample_response["Available"][0]["Progress"][0]["CurrentValue"]
70
+ @wrapped.available.first.progress.first.description.should == @sample_response["Available"][0]["Progress"][0]["Description"]
71
+ @wrapped.available.first.progress.first.required_value.should == @sample_response["Available"][0]["Progress"][0]["RequiredValue"]
72
+ @wrapped.available.first.progress.last.condition_met_date.should be_nil
73
+ @wrapped.available.first.progress.last.current_value.should == @sample_response["Available"][0]["Progress"][1]["CurrentValue"]
74
+ @wrapped.available.first.progress.last.description.should == @sample_response["Available"][0]["Progress"][1]["Description"]
75
+ @wrapped.available.first.progress.last.required_value.should == @sample_response["Available"][0]["Progress"][1]["RequiredValue"]
76
+ end
77
+
78
+ it "should contain ar array of completed achievements" do
79
+ @wrapped.completed.should be_instance_of Array
80
+ @wrapped.completed.first.key.should == @sample_response["Completed"][0]["Key"]
81
+ @wrapped.completed.first.description.should == @sample_response["Completed"][0]["Description"]
82
+ @wrapped.completed.first.image_url.should == @sample_response["Completed"][0]["ImageURL"]
83
+ @wrapped.completed.first.name.should == @sample_response["Completed"][0]["Name"]
84
+ @wrapped.completed.first.award_date.should_not be_nil
85
+ end
86
+
87
+ it "should contain an array of progresses within each completed achievement" do
88
+ @wrapped.completed.first.progress.should be_instance_of Array
89
+ @wrapped.completed.first.progress.first.condition_met_date.should_not be_nil
90
+ @wrapped.completed.first.progress.first.current_value.should == @sample_response["Completed"][0]["Progress"][0]["CurrentValue"]
91
+ @wrapped.completed.first.progress.first.description.should == @sample_response["Completed"][0]["Progress"][0]["Description"]
92
+ @wrapped.completed.first.progress.first.required_value.should == @sample_response["Completed"][0]["Progress"][0]["RequiredValue"]
93
+ end
94
+
95
+ it "should convert to a hash equal to the original" do
96
+ hash_including(@sample_response).should == @wrapped.to_hash
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_profile" do
4
+ before do
5
+ @sample_response = {
6
+ "DisplayName" => "Jason",
7
+ "Identifiers" => [
8
+ {
9
+ "ID" => "jason@example.com",
10
+ "IDHash" => "eba69e62f8bc92297b7a97659b5d6130",
11
+ "IDType" => "Email"
12
+ }
13
+ ],
14
+ "Points" => [
15
+ {
16
+ "Level" => {
17
+ "Current" => {
18
+ "LevelType" => {
19
+ "Key" => "player_experience_level",
20
+ "Name" => "Experience Level"
21
+ },
22
+ "Name" => "Noobie",
23
+ "Number" => 1,
24
+ "RequiredPoints" => 10
25
+ },
26
+ "Next" => {
27
+ "LevelType" => {
28
+ "Key" => "player_experience_level",
29
+ "Name" => "Experience Level"
30
+ },
31
+ "Name" => "Expert",
32
+ "Number" => 2,
33
+ "RequiredPoints" => 100
34
+ },
35
+ },
36
+ "PointType" => {
37
+ "Key" => "experience_points",
38
+ "Name" => "Experience Points"
39
+ },
40
+ "Points" => 12
41
+ }
42
+ ],
43
+ "RecentAchievements" => [
44
+ {
45
+ "Key" => "i_love_stuff",
46
+ "Description" => "Favorite 10 Items",
47
+ "ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/9999",
48
+ "Name" => "I love stuff!"
49
+ }
50
+ ]
51
+ }
52
+ end
53
+
54
+ it "should not raise error on wrapping in an object" do
55
+ lambda { IActionable::Objects::ProfileSummary.new(@sample_response) }.should_not raise_error
56
+ end
57
+
58
+ describe "when wrapped in an object" do
59
+ before do
60
+ @wrapped = IActionable::Objects::ProfileSummary.new(Marshal.load(Marshal.dump(@sample_response)))
61
+ end
62
+
63
+ it "should contain the display name" do
64
+ @wrapped.display_name.should == @sample_response["DisplayName"]
65
+ end
66
+
67
+ it "should contain ar array of identifiers" do
68
+ @wrapped.identifiers.should be_instance_of Array
69
+ @wrapped.identifiers.first.id.should == @sample_response["Identifiers"][0]["ID"]
70
+ @wrapped.identifiers.first.id_hash.should == @sample_response["Identifiers"][0]["IDHash"]
71
+ @wrapped.identifiers.first.id_type.should == @sample_response["Identifiers"][0]["IDType"]
72
+ end
73
+
74
+ it "should contain an array of point summaries" do
75
+ @wrapped.points.should be_instance_of Array
76
+ @wrapped.points.first.points.should == @sample_response["Points"][0]["Points"]
77
+ @wrapped.points.first.point_type.key.should == @sample_response["Points"][0]["PointType"]["Key"]
78
+ @wrapped.points.first.point_type.name.should == @sample_response["Points"][0]["PointType"]["Name"]
79
+ @wrapped.points.first.level.current.name.should == @sample_response["Points"][0]["Level"]["Current"]["Name"]
80
+ @wrapped.points.first.level.current.number.should == @sample_response["Points"][0]["Level"]["Current"]["Number"]
81
+ @wrapped.points.first.level.current.required_points.should == @sample_response["Points"][0]["Level"]["Current"]["RequiredPoints"]
82
+ @wrapped.points.first.level.current.level_type.key.should == @sample_response["Points"][0]["Level"]["Current"]["LevelType"]["Key"]
83
+ @wrapped.points.first.level.current.level_type.name.should == @sample_response["Points"][0]["Level"]["Current"]["LevelType"]["Name"]
84
+ @wrapped.points.first.level.next.name.should == @sample_response["Points"][0]["Level"]["Next"]["Name"]
85
+ @wrapped.points.first.level.next.number.should == @sample_response["Points"][0]["Level"]["Next"]["Number"]
86
+ @wrapped.points.first.level.next.required_points.should == @sample_response["Points"][0]["Level"]["Next"]["RequiredPoints"]
87
+ @wrapped.points.first.level.next.level_type.key.should == @sample_response["Points"][0]["Level"]["Next"]["LevelType"]["Key"]
88
+ @wrapped.points.first.level.next.level_type.name.should == @sample_response["Points"][0]["Level"]["Next"]["LevelType"]["Name"]
89
+ end
90
+
91
+ it "should contain an array of recent achievements" do
92
+ @wrapped.recent_achievements.should be_instance_of Array
93
+ @wrapped.recent_achievements.first.key.should == @sample_response["RecentAchievements"][0]["Key"]
94
+ @wrapped.recent_achievements.first.description.should == @sample_response["RecentAchievements"][0]["Description"]
95
+ @wrapped.recent_achievements.first.image_url.should == @sample_response["RecentAchievements"][0]["ImageURL"]
96
+ @wrapped.recent_achievements.first.name.should == @sample_response["RecentAchievements"][0]["Name"]
97
+ end
98
+
99
+ it "should convert to a hash equal to the original" do
100
+ hash_including(@sample_response).should == @wrapped.to_hash
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_profile_challenges" do
4
+ before do
5
+ @sample_response = {
6
+ "Available" => [
7
+ {
8
+ "Key" => "hard_challenge",
9
+ "Description" => "Do something hard 10 times and earn 200 points",
10
+ "Name" => "Easy Challenge",
11
+ "Progress" => [
12
+ {
13
+ "ConditionMetDate" => nil,
14
+ "CurrentValue" => 9,
15
+ "Description" => "Do something hard 10 times",
16
+ "RequiredValue" => 10
17
+ }
18
+ ]
19
+ }
20
+ ],
21
+ "Completed" => [
22
+ {
23
+ "Key" => "easy_challenge",
24
+ "Description" => "Do something easy 5 times and earn 100 points",
25
+ "Name" => "Easy Challenge",
26
+ "Progress" => [
27
+ {
28
+ "ConditionMetDate" => "/Date(1275706032317-0600)/",
29
+ "CurrentValue" => 5,
30
+ "Description" => "Do something easy 5 times",
31
+ "RequiredValue" => "5"
32
+ }
33
+ ],
34
+ "AwardDate" => "/Date(1275706032317-0600)/"
35
+ }
36
+ ]
37
+ }
38
+ end
39
+
40
+ it "should not raise error on wrapping in an object" do
41
+ lambda { IActionable::Objects::ProfileChallenges.new(@sample_response) }.should_not raise_error
42
+ end
43
+
44
+ describe "when wrapped in an object" do
45
+ before do
46
+ @wrapped = IActionable::Objects::ProfileChallenges.new(Marshal.load(Marshal.dump(@sample_response)))
47
+ end
48
+
49
+ it "should contain ar array of available challenges" do
50
+ @wrapped.available.should be_instance_of Array
51
+ @wrapped.available.first.key.should == @sample_response["Available"][0]["Key"]
52
+ @wrapped.available.first.description.should == @sample_response["Available"][0]["Description"]
53
+ @wrapped.available.first.name.should == @sample_response["Available"][0]["Name"]
54
+ @wrapped.available.first.award_date.should be_nil
55
+ end
56
+
57
+ it "should contain an array of progresses within each available challenge" do
58
+ @wrapped.available.first.progress.should be_instance_of Array
59
+ @wrapped.available.first.progress.first.condition_met_date.should be_nil
60
+ @wrapped.available.first.progress.first.current_value.should == @sample_response["Available"][0]["Progress"][0]["CurrentValue"]
61
+ @wrapped.available.first.progress.first.description.should == @sample_response["Available"][0]["Progress"][0]["Description"]
62
+ @wrapped.available.first.progress.first.required_value.should == @sample_response["Available"][0]["Progress"][0]["RequiredValue"]
63
+ end
64
+
65
+ it "should contain ar array of completed challenges" do
66
+ @wrapped.completed.should be_instance_of Array
67
+ @wrapped.completed.first.key.should == @sample_response["Completed"][0]["Key"]
68
+ @wrapped.completed.first.description.should == @sample_response["Completed"][0]["Description"]
69
+ @wrapped.completed.first.name.should == @sample_response["Completed"][0]["Name"]
70
+ @wrapped.completed.first.award_date.should_not be_nil
71
+ end
72
+
73
+ it "should contain an array of progresses within each completed achievement" do
74
+ @wrapped.completed.first.progress.should be_instance_of Array
75
+ @wrapped.completed.first.progress.first.condition_met_date.should_not be_nil
76
+ @wrapped.completed.first.progress.first.current_value.should == @sample_response["Completed"][0]["Progress"][0]["CurrentValue"]
77
+ @wrapped.completed.first.progress.first.description.should == @sample_response["Completed"][0]["Progress"][0]["Description"]
78
+ @wrapped.completed.first.progress.first.required_value.should == @sample_response["Completed"][0]["Progress"][0]["RequiredValue"]
79
+ end
80
+
81
+ it "should convert to a hash equal to the original" do
82
+ hash_including(@sample_response).should == @wrapped.to_hash
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_profile_goals" do
4
+ before do
5
+ @sample_response = {
6
+ "Available" => [
7
+ {
8
+ "Key" => "hard_goal",
9
+ "Description" => "Do something hard 10 times within a week and earn 200 points",
10
+ "Name" => "Hard Goal",
11
+ "Interval" => "Weekly",
12
+ "Progress" => [
13
+ {
14
+ "ConditionMetDate" => nil,
15
+ "CurrentValue" => 9,
16
+ "Description" => "Do something hard 10 times",
17
+ "RequiredValue" => 10
18
+ }
19
+ ]
20
+ }
21
+ ],
22
+ "Completed" => [
23
+ {
24
+ "Key" => "easy_goal",
25
+ "Description" => "Do something easy 5 times today and earn 100 points",
26
+ "Name" => "Easy Goal",
27
+ "Interval" => "Daily",
28
+ "Progress" => [
29
+ {
30
+ "ConditionMetDate" => "/Date(1275706032317-0600)/",
31
+ "CurrentValue" => 5,
32
+ "Description" => "Do something easy 5 times",
33
+ "RequiredValue" => "5"
34
+ }
35
+ ],
36
+ "AwardDate" => "/Date(1275706032317-0600)/"
37
+ }
38
+ ]
39
+ }
40
+ end
41
+
42
+ it "should not raise error on wrapping in an object" do
43
+ lambda { IActionable::Objects::ProfileGoals.new(@sample_response) }.should_not raise_error
44
+ end
45
+
46
+ describe "when wrapped in an object" do
47
+ before do
48
+ @wrapped = IActionable::Objects::ProfileGoals.new(Marshal.load(Marshal.dump(@sample_response)))
49
+ end
50
+
51
+ it "should contain ar array of available goals" do
52
+ @wrapped.available.should be_instance_of Array
53
+ @wrapped.available.first.key.should == @sample_response["Available"][0]["Key"]
54
+ @wrapped.available.first.description.should == @sample_response["Available"][0]["Description"]
55
+ @wrapped.available.first.name.should == @sample_response["Available"][0]["Name"]
56
+ @wrapped.available.first.interval.should == @sample_response["Available"][0]["Interval"]
57
+ @wrapped.available.first.award_date.should be_nil
58
+ end
59
+
60
+ it "should contain an array of progresses within each available goals" do
61
+ @wrapped.available.first.progress.should be_instance_of Array
62
+ @wrapped.available.first.progress.first.condition_met_date.should be_nil
63
+ @wrapped.available.first.progress.first.current_value.should == @sample_response["Available"][0]["Progress"][0]["CurrentValue"]
64
+ @wrapped.available.first.progress.first.description.should == @sample_response["Available"][0]["Progress"][0]["Description"]
65
+ @wrapped.available.first.progress.first.required_value.should == @sample_response["Available"][0]["Progress"][0]["RequiredValue"]
66
+ end
67
+
68
+ it "should contain ar array of completed goals" do
69
+ @wrapped.completed.should be_instance_of Array
70
+ @wrapped.completed.first.key.should == @sample_response["Completed"][0]["Key"]
71
+ @wrapped.completed.first.description.should == @sample_response["Completed"][0]["Description"]
72
+ @wrapped.completed.first.name.should == @sample_response["Completed"][0]["Name"]
73
+ @wrapped.available.first.interval.should == @sample_response["Available"][0]["Interval"]
74
+ @wrapped.completed.first.award_date.should_not be_nil
75
+ end
76
+
77
+ it "should contain an array of progresses within each completed goals" do
78
+ @wrapped.completed.first.progress.should be_instance_of Array
79
+ @wrapped.completed.first.progress.first.condition_met_date.should_not be_nil
80
+ @wrapped.completed.first.progress.first.current_value.should == @sample_response["Completed"][0]["Progress"][0]["CurrentValue"]
81
+ @wrapped.completed.first.progress.first.description.should == @sample_response["Completed"][0]["Progress"][0]["Description"]
82
+ @wrapped.completed.first.progress.first.required_value.should == @sample_response["Completed"][0]["Progress"][0]["RequiredValue"]
83
+ end
84
+
85
+ it "should convert to a hash equal to the original" do
86
+ hash_including(@sample_response).should == @wrapped.to_hash
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "API response to get_profile_notifications" do
4
+ before do
5
+ @sample_response = {
6
+ "Achievements" => {
7
+ "Available" => [ ],
8
+ "Completed" => [
9
+ {
10
+ "Description" => "Achieve the impossible",
11
+ "ImageURL" => "http://iactionable.blob.core.windows.net/achievementimages/99999",
12
+ "Key" => "mission_impossible",
13
+ "Name" => "Mission Impossible"
14
+ }
15
+ ]
16
+ },
17
+ "Challenges" => {
18
+ "Available" => [ ],
19
+ "Completed" => [
20
+ {
21
+ "Description" => "Do something extraordinary",
22
+ "Key" => "super_challenge",
23
+ "Name" => "Super Challenge"
24
+ }
25
+ ]
26
+ },
27
+ "Goals" => {
28
+ "Available" => [ ],
29
+ "Completed" => [
30
+ {
31
+ "Description" => "Complete an awesome goal",
32
+ "Key" => "awesome_goal",
33
+ "Name" => "Awesome Goal"
34
+ }
35
+ ]
36
+ },
37
+ "Levels" => [
38
+ {
39
+ "LevelType" => {
40
+ "Key" => "player_experience_points",
41
+ "Name" => "Player Experience Points"
42
+ },
43
+ "Name" => "Noobie",
44
+ "Number" => 2,
45
+ "RequiredPoints" => 10
46
+ }
47
+ ],
48
+ "Points" => [
49
+ {
50
+ "PointType" => {
51
+ "Key" => "experience_points",
52
+ "Name" => "Experience Points"
53
+ },
54
+ "Points" => 20,
55
+ "Reason" => "Achieve the impossible"
56
+ }
57
+ ]
58
+ }
59
+ end
60
+
61
+ it "should not raise error on wrapping in an object" do
62
+ lambda { IActionable::Objects::ProfileNotifications.new(@sample_response) }.should_not raise_error
63
+ end
64
+
65
+ describe "when wrapped in an object" do
66
+ before do
67
+ @wrapped = IActionable::Objects::ProfileNotifications.new(Marshal.load(Marshal.dump(@sample_response)))
68
+ end
69
+
70
+
71
+ it "should convert to a hash equal to the original" do
72
+ hash_including(@sample_response).should == @wrapped.to_hash
73
+ end
74
+ end
75
+ end