api_test.rb
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require_relative '../test_helper'
require_relative '../../../../test/unit/api/test_helper'
class APITest < ActiveSupport::TestCase
def setup
login_api
environment = Environment.default
environment.enable_plugin(GamificationPlugin)
GamificationPlugin.gamification_set_rules(@environment)
end
should 'get my own badges' do
badge = GamificationPlugin::Badge.create!(:owner => environment, :name => 'test_badge')
person.add_badge(badge.id)
get "/api/v1/gamification_plugin/my/badges?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal 'test_badge', json['badges'].first['name']
end
should 'get my level' do
badge = GamificationPlugin::Badge.create!(:owner => environment, :name => 'test_badge')
person.add_badge(badge.id)
get "/api/v1/gamification_plugin/my/level?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_not_nil json['level']
assert_not_nil json['percent']
end
should 'get my total pontuation' do
badge = GamificationPlugin::Badge.create!(:owner => environment, :name => 'test_badge')
person.add_badge(badge.id)
get "/api/v1/gamification_plugin/my/points?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_not_nil json['points']
end
should 'get badges of the public person' do
badge = GamificationPlugin::Badge.create!(:owner => environment, :name => 'test_badge')
another_person = create(User, :environment => environment).person
another_person.visible=true
another_person.save
another_person.add_badge(badge.id)
get "/api/v1/gamification_plugin/people/#{another_person.id}/badges?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal 'test_badge', json.first['name']
end
should 'get level of the public person' do
another_person = create(User, :environment => environment).person
another_person.visible=true
another_person.save
get "/api/v1/gamification_plugin/people/#{another_person.id}/level?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_not_nil json['level']
assert_not_nil json['percent']
end
should 'not get badges of the private person' do
badge = GamificationPlugin::Badge.create!(:owner => environment, :name => 'test_badge')
another_person = create(User, :environment_id => environment.id).person
another_person.visible=false
another_person.save
another_person.add_badge(badge.id)
get "/api/v1/gamification_plugin/people/#{another_person.id}/badges?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal 404, last_response.status
end
should 'not get level of the private person' do
another_person = create(User, :environment_id => environment.id).person
another_person.visible=false
another_person.save
get "/api/v1/gamification_plugin/people/#{another_person.id}/level?#{params.to_query}"
JSON.parse(last_response.body)
assert_equal 404, last_response.status
end
end