akkounts/spec/features/settings/profile_spec.rb
Râu Cao 5f276ff349
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Release Drafter / Update release notes draft (pull_request) Failing after 10m9s
Queue XmppSetAvatarJob when new avatar is uploaded
And let job do nothing in development for now
2025-05-15 22:04:25 +04:00

115 lines
3.5 KiB
Ruby

require 'rails_helper'
RSpec.describe 'Profile settings', type: :feature do
let(:user) { create :user, cn: "mwahlberg" }
let(:avatar_jpeg) { File.binread("#{Rails.root}/spec/fixtures/files/taipei.jpg") }
before do
login_as user, :scope => :user
allow(user).to receive(:display_name).and_return("Mark")
allow_any_instance_of(User).to receive(:dn)
.and_return("cn=mwahlberg,ou=kosmos.org,cn=users,dc=kosmos,dc=org")
allow_any_instance_of(User).to receive(:ldap_entry)
.and_return({
uid: user.cn, ou: user.ou, display_name: "Mark", pgp_key: nil
})
end
feature "Update display name" do
scenario 'fails with validation error' do
visit setting_path(:profile)
fill_in 'Display name', with: "M"
click_button "Save"
expect(current_url).to eq(setting_url(:profile))
expect(page).to have_field('Display name', with: 'M')
within ".error-msg" do
expect(page).to have_content("is too short")
end
end
scenario 'works with valid input' do
expect(LdapManager::UpdateDisplayName).to receive(:call)
.with(dn: user.dn, display_name: "Marky Mark").and_return(true)
visit setting_path(:profile)
fill_in 'Display name', with: "Marky Mark"
click_button "Save"
expect(current_url).to eq(setting_url(:profile))
within ".flash-msg" do
expect(page).to have_content("Settings saved")
end
end
end
feature "Update avatar" do
scenario "fails with validation error for wrong content type" do
expect(LdapManager::UpdateAvatar).not_to receive(:call)
visit setting_path(:profile)
attach_file "Avatar", "#{Rails.root}/spec/fixtures/files/bitcoin.pdf"
click_button "Save"
expect(current_url).to eq(setting_url(:profile))
within ".error-msg" do
expect(page).to have_content("must be a JPEG or PNG file")
end
end
scenario "fails with validation error for file size too large" do
expect(LdapManager::UpdateAvatar).not_to receive(:call)
visit setting_path(:profile)
attach_file "Avatar", "#{Rails.root}/spec/fixtures/files/fsociety-irc.png"
click_button "Save"
expect(current_url).to eq(setting_url(:profile))
within ".error-msg" do
expect(page).to have_content("must be less than 1MB")
end
end
scenario 'works with valid JPG file' do
file_path = "#{Rails.root}/spec/fixtures/files/taipei.jpg"
expect(LdapManager::UpdateAvatar)
.to receive(:call).with(user: user)
.and_return(true)
expect(XmppSetAvatarJob)
.to receive(:perform_later).with(user: user)
.and_return(true)
visit setting_path(:profile)
attach_file "Avatar", file_path
click_button "Save"
expect(current_url).to eq(setting_url(:profile))
within ".flash-msg" do
expect(page).to have_content("Settings saved")
end
end
scenario 'works with valid PNG file' do
file_path = "#{Rails.root}/spec/fixtures/files/bender.png"
expect(LdapManager::UpdateAvatar)
.to receive(:call).with(user: user)
.and_return(true)
expect(XmppSetAvatarJob)
.to receive(:perform_later).with(user: user)
.and_return(true)
visit setting_path(:profile)
attach_file "Avatar", file_path
click_button "Save"
expect(current_url).to eq(setting_url(:profile))
within ".flash-msg" do
expect(page).to have_content("Settings saved")
end
end
end
end