activities_test.rb
5.12 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
require_relative 'test_helper'
class ActivitiesTest < ActiveSupport::TestCase
def setup
create_and_activate_user
login_api
end
should 'get own activities' do
create_activity(:target => person)
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert 1, json["activities"].count
assert_equivalent person.activities.map(&:activity).map(&:id), json["activities"].map{|c| c["id"]}
end
should 'not get private community activities' do
community = fast_create(Community, :public_profile => false)
create_activity(:target => community)
get "/api/v1/profiles/#{community.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_nil json["activities"]
assert_equal 403, last_response.status
end
should 'not get community activities if not member and community is private' do
community = fast_create(Community, public_profile: false)
other_person = fast_create(Person)
community.add_member(other_person) # so there is an activity in community
get "/api/v1/profiles/#{community.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_nil json["activities"]
assert_equal 403, last_response.status
end
should 'get community activities for member' do
community = fast_create(Community)
create_activity(:target => community)
community.add_member(person)
get "/api/v1/profiles/#{community.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent community.activities.map(&:activity).map(&:id), json["activities"].map{|c| c["id"]}
end
should 'not get other person activities' do
other_person = fast_create(Person)
create_activity(:target => other_person)
get "/api/v1/profiles/#{other_person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_nil json["activities"]
assert_equal 403, last_response.status
end
should 'get friend activities' do
other_person = fast_create(Person)
other_person.add_friend(person)
create_activity(:target => other_person)
get "/api/v1/profiles/#{other_person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent other_person.activities.map(&:activity).map(&:id), json["activities"].map{|c| c["id"]}
end
should 'get activities for non logged user in a public community' do
community = fast_create(Community)
create_activity(:target => community)
community.add_member(person)
get "/api/v1/profiles/#{community.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent community.activities.map(&:activity).map(&:id), json["activities"].map{|c| c["id"]}
end
should 'not crash api if an scrap activity is in the list' do
create_activity(:target => person)
create(Scrap, :sender_id => person.id, :receiver_id => person.id)
assert_nothing_raised NoMethodError do
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
end
end
should 'scrap activity be returned in acitivities list' do
create_activity(:target => person)
create(Scrap, :sender_id => person.id, :receiver_id => person.id)
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent person.activities.map(&:activity).map(&:id), json["activities"].map{|c| c["id"]}
end
should 'always return the activity verb parameter' do
ActionTracker::Record.destroy_all
ProfileActivity.destroy_all
create_activity(:target => person)
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal 'create_article', json["activities"].last['verb']
end
should 'scrap activity return leave_scrap verb' do
ActionTracker::Record.destroy_all
create(TinyMceArticle, :name => 'Tracked Article 1', :profile_id => person.id)
create(Scrap, :sender_id => person.id, :receiver_id => person.id)
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent ['create_article', 'leave_scrap'], json["activities"].map{|a|a['verb']}
end
should 'the content be returned in scrap activities' do
ActionTracker::Record.destroy_all
content = 'some content'
create(Scrap, :sender_id => person.id, :receiver_id => person.id, :content => content)
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal content, json["activities"].last['content']
end
should 'not return the content in other kind of activities except scrap' do
ActionTracker::Record.destroy_all
create_activity(:target => person)
get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_nil json["activities"].last['content']
end
def create_activity(params = {})
params[:verb] ||= 'create_article'
ActionTracker::Record.create! :verb => params[:verb], :user => person, :target => params[:target]
end
end