* Add a default message to badge award action Because: - The only badges routinely awarded manually use the same message - Right now, unfriendly/unsafe UI can result in an error notification The only badges that are currently awarded manually (afaik) have the message "Congrats!!!" so for the time being, if a message is not supplied to the UI, it will simply use the "Congrats!!!" message as a default. That being said, I'm not totally convinced this message won't work for the long term. Generally, if we are awarding badges by hand, I'd imagine we'd want a specific message explaining why we are doing that, or just be okay with "Congrats!" After talking with Peter about it, the longer term goal should be to move badge messages into the database so they can be modified in the app and not hardcoded. That also make sense regarding the effort to genericize the app eventually. * Test Badge notifications
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Admin awards badges", type: :system do
|
|
let(:admin) { create(:user, :super_admin) }
|
|
let(:user) { create(:user) }
|
|
let(:user2) { create(:user) }
|
|
let(:badges) { Badge.pluck(:title) }
|
|
|
|
def award_two_badges
|
|
find(:xpath, "//option[contains(text(), \"#{badges.last}\")]").select_option
|
|
fill_in "usernames", with: "#{user.username}, #{user2.username}"
|
|
fill_in "message_markdown", with: "He who controls the spice controls the universe."
|
|
click_on "Award Badges"
|
|
end
|
|
|
|
before do
|
|
create_list :badge, 5
|
|
sign_in admin
|
|
visit "/internal/badges"
|
|
end
|
|
|
|
it "loads the view" do
|
|
expect(page).to have_content("Badges")
|
|
end
|
|
|
|
it "lists the badges" do
|
|
badges.each do |badge|
|
|
expect(page).to have_content(badge)
|
|
end
|
|
end
|
|
|
|
it "awards badges" do
|
|
expect { award_two_badges }.to change { user.badges.count }.by(1).
|
|
and change { user2.badges.count }.by(1)
|
|
expect(page).to have_content("BadgeRewarder task ran!")
|
|
|
|
visit "/#{user.username}/"
|
|
|
|
expect(page).to have_link(href: "/badge/#{Badge.last.slug}")
|
|
end
|
|
|
|
it "notifies users of new badges" do
|
|
expect { award_two_badges }.to enqueue_job(Notifications::NewBadgeAchievementJob).
|
|
exactly(2).times.
|
|
and enqueue_job(BadgeAchievements::SendEmailNotificationJob).
|
|
exactly(2).times
|
|
end
|
|
end
|