Feature: Mass award badge (#8694)

* UI: Mass grant a badge from the admin ui

* Send the uploaded CSV and badge ID to the backend

* Read the CSV and grant badge in batches

* UX: Communicate the result to the user

* Don't award if badge is disabled

* Create a 'send_notification' method to remove duplicated code, slightly shrink badge image. Replace router transition with href.

* Dynamically discover current route
This commit is contained in:
Roman Rizzi
2020-01-13 11:20:26 -03:00
committed by GitHub
parent eb105ba79d
commit d69c5eebcf
15 changed files with 291 additions and 34 deletions

View File

@@ -177,5 +177,38 @@ describe Admin::BadgesController do
end
end
end
describe '#mass_award' do
it 'does nothing when there is no file' do
post "/admin/badges/award/#{badge.id}.json", params: { file: '' }
expect(response.status).to eq(400)
end
it 'does nothing when the badge id is not valid' do
post '/admin/badges/award/fake_id.json', params: { file: fixture_file_upload(Tempfile.new) }
expect(response.status).to eq(400)
end
it 'does nothing when the file is not a csv' do
file = file_from_fixtures('cropped.png')
post "/admin/badges/award/#{badge.id}.json", params: { file: fixture_file_upload(file) }
expect(response.status).to eq(400)
end
it 'creates the badge for an existing user' do
Jobs.run_immediately!
user = Fabricate(:user, email: 'user1@test.com')
file = file_from_fixtures('user_emails.csv', 'csv')
post "/admin/badges/award/#{badge.id}.json", params: { file: fixture_file_upload(file) }
expect(UserBadge.exists?(user: user, badge: badge)).to eq(true)
end
end
end
end