custom_emoji_batch_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Form::CustomEmojiBatch do
  4. describe '#save' do
  5. subject { described_class.new({ current_account: account }.merge(options)) }
  6. let(:options) { {} }
  7. let(:account) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  8. context 'with empty custom_emoji_ids' do
  9. let(:options) { { custom_emoji_ids: [] } }
  10. it 'does nothing if custom_emoji_ids is empty' do
  11. expect(subject.save).to be_nil
  12. end
  13. end
  14. describe 'the update action' do
  15. let(:custom_emoji) { Fabricate(:custom_emoji, category: Fabricate(:custom_emoji_category)) }
  16. let(:custom_emoji_category) { Fabricate(:custom_emoji_category) }
  17. context 'without anything to change' do
  18. let(:options) { { action: 'update' } }
  19. it 'silently exits without updating any custom emojis' do
  20. expect { subject.save }.to_not change(Admin::ActionLog, :count)
  21. end
  22. end
  23. context 'with a category_id' do
  24. let(:options) { { action: 'update', custom_emoji_ids: [custom_emoji.id], category_id: custom_emoji_category.id } }
  25. it 'updates the category of the emoji' do
  26. subject.save
  27. expect(custom_emoji.reload.category).to eq(custom_emoji_category)
  28. end
  29. end
  30. context 'with a category_name' do
  31. let(:options) { { action: 'update', custom_emoji_ids: [custom_emoji.id], category_name: custom_emoji_category.name } }
  32. it 'updates the category of the emoji' do
  33. subject.save
  34. expect(custom_emoji.reload.category).to eq(custom_emoji_category)
  35. end
  36. end
  37. end
  38. describe 'the list action' do
  39. let(:custom_emoji) { Fabricate(:custom_emoji, visible_in_picker: false) }
  40. let(:options) { { action: 'list', custom_emoji_ids: [custom_emoji.id] } }
  41. it 'updates the picker visibility of the emoji' do
  42. subject.save
  43. expect(custom_emoji.reload.visible_in_picker).to be(true)
  44. end
  45. end
  46. describe 'the unlist action' do
  47. let(:custom_emoji) { Fabricate(:custom_emoji, visible_in_picker: true) }
  48. let(:options) { { action: 'unlist', custom_emoji_ids: [custom_emoji.id] } }
  49. it 'updates the picker visibility of the emoji' do
  50. subject.save
  51. expect(custom_emoji.reload.visible_in_picker).to be(false)
  52. end
  53. end
  54. describe 'the enable action' do
  55. let(:custom_emoji) { Fabricate(:custom_emoji, disabled: true) }
  56. let(:options) { { action: 'enable', custom_emoji_ids: [custom_emoji.id] } }
  57. it 'updates the disabled value of the emoji' do
  58. subject.save
  59. expect(custom_emoji.reload).to_not be_disabled
  60. end
  61. end
  62. describe 'the disable action' do
  63. let(:custom_emoji) { Fabricate(:custom_emoji, visible_in_picker: false) }
  64. let(:options) { { action: 'disable', custom_emoji_ids: [custom_emoji.id] } }
  65. it 'updates the disabled value of the emoji' do
  66. subject.save
  67. expect(custom_emoji.reload).to be_disabled
  68. end
  69. end
  70. describe 'the copy action' do
  71. let(:custom_emoji) { Fabricate(:custom_emoji) }
  72. let(:options) { { action: 'copy', custom_emoji_ids: [custom_emoji.id] } }
  73. it 'makes a copy of the emoji' do
  74. expect { subject.save }
  75. .to change(CustomEmoji, :count).by(1)
  76. end
  77. end
  78. describe 'the delete action' do
  79. let(:custom_emoji) { Fabricate(:custom_emoji) }
  80. let(:options) { { action: 'delete', custom_emoji_ids: [custom_emoji.id] } }
  81. it 'destroys the emoji' do
  82. subject.save
  83. expect { custom_emoji.reload }.to raise_error(ActiveRecord::RecordNotFound)
  84. end
  85. end
  86. end
  87. end