Commit 3c5150a1 authored by James Lopez's avatar James Lopez

add more specs and grape entity stuff

parent 2f808329
...@@ -18,6 +18,11 @@ module API ...@@ -18,6 +18,11 @@ module API
expose :bio, :location, :skype, :linkedin, :twitter, :website_url, :organization expose :bio, :location, :skype, :linkedin, :twitter, :website_url, :organization
end end
class UserActivity < Grape::Entity
expose :username
expose :date
end
class Identity < Grape::Entity class Identity < Grape::Entity
expose :provider, :extern_uid expose :provider, :extern_uid
end end
......
...@@ -456,6 +456,23 @@ module API ...@@ -456,6 +456,23 @@ module API
email.destroy email.destroy
current_user.update_secondary_emails! current_user.update_secondary_emails!
end end
desc 'Get a list of user activities' do
success Entities::UserBasic
end
params do
optional :due_date, type: String, desc: 'Date time string in the format YEAR-MONTH-DAY'
use :pagination
end
get ":activities" do
authenticated_as_admin!
user_activities = Gitlab::UserActivities.query(from: params[:from],
page: params[:page],
per_page: params[:per_page])
present paginate(user_activities), with: Entities::UserActivity
end
end end
end end
end end
...@@ -5,7 +5,7 @@ describe Gitlab::UserActivities, :redis, lib: true do ...@@ -5,7 +5,7 @@ describe Gitlab::UserActivities, :redis, lib: true do
it 'shows the last user activities' do it 'shows the last user activities' do
Timecop.freeze do Timecop.freeze do
Users::ActivityService.new(user, 'type').execute user.record_activity
expect(described_class.query).to eq({ username: user.username, expect(described_class.query).to eq({ username: user.username,
last_activity: DateTime.now }) last_activity: DateTime.now })
...@@ -17,7 +17,7 @@ describe Gitlab::UserActivities, :redis, lib: true do ...@@ -17,7 +17,7 @@ describe Gitlab::UserActivities, :redis, lib: true do
Timecop.scale(3600) Timecop.scale(3600)
7.times do 7.times do
Users::ActivityService.new(create(:user), 'type').execute create(:user).record_activity
end end
end end
......
...@@ -1101,16 +1101,16 @@ describe API::Users, api: true do ...@@ -1101,16 +1101,16 @@ describe API::Users, api: true do
end end
end end
context "user activities" do context "user activities", :redis do
it_behaves_like 'a paginated resources' do it_behaves_like 'a paginated resources' do
let(:request) { get api("/users/activities", user) } let(:request) { get api("/users/activities", user) }
end end
context 'last activities' do context 'last activities' do
it 'returns the last activities' do it 'returns the last activities' do
Users::ActivityService.new(user, 'type').execute user.record_activity
get api("/users/activities", user) get api("/users/activities", admin)
activity = json_response.first activity = json_response.first
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment