mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-14 17:57:09 +00:00
* feat: add email for disabling automation rule * feat: disable automation rules and notify admin * feat: reset error count after update * feat: trigger invalid_condition_error if rule is invalid * feat: setup error trackable concern * refactor: use ErrorTrackable in Reauthorizable * fix: optional argument * feat: separate reauthorization_required_key * test: update case to use ERROR_TRACKABLE_COUNT * Revert "test: update case to use ERROR_TRACKABLE_COUNT" This reverts commit f439847147556a02759a7597a7fcf1d66091cafc. * Revert "feat: separate reauthorization_required_key" This reverts commit f4514fce217b0a2f2c2bf701a15de0a8b47acbc4. * Revert "fix: optional argument" This reverts commit 93b4194ec3f10f67e2402388c966c071c4d3b4fd. * Revert "refactor: use ErrorTrackable in Reauthorizable" This reverts commit 513c2a522bc782e73ea4b0f5ae34ce01e70e042c. * Revert "feat: setup error trackable concern" This reverts commit 278683060cf422f60af5d5c77100aa5272141141. * feat: use reauthorizable for automation rule * feat: remove redis key * test: fix method names * chore: refactor --------- Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> Co-authored-by: Sojan <sojan@pepalo.com>
58 lines
2.0 KiB
Ruby
58 lines
2.0 KiB
Ruby
require 'rails_helper'
|
|
|
|
shared_examples_for 'reauthorizable' do
|
|
let(:model) { described_class } # the class that includes the concern
|
|
|
|
it 'authorization_error!' do
|
|
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
|
|
expect(obj.authorization_error_count).to eq 0
|
|
|
|
obj.authorization_error!
|
|
|
|
expect(obj.authorization_error_count).to eq 1
|
|
end
|
|
|
|
it 'prompts reauthorization when error threshold is passed' do
|
|
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
|
|
expect(obj.reauthorization_required?).to be false
|
|
|
|
obj.class::AUTHORIZATION_ERROR_THRESHOLD.times do
|
|
obj.authorization_error!
|
|
end
|
|
|
|
expect(obj.reauthorization_required?).to be true
|
|
end
|
|
|
|
it 'prompt_reauthorization!' do
|
|
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
|
|
mailer = double
|
|
mailer_method = double
|
|
allow(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).and_return(mailer)
|
|
# allow mailer to receive any methods and return mailer
|
|
allow(mailer).to receive(:method_missing).and_return(mailer_method)
|
|
allow(mailer_method).to receive(:deliver_later)
|
|
|
|
expect(obj.reauthorization_required?).to be false
|
|
|
|
obj.prompt_reauthorization!
|
|
expect(obj.reauthorization_required?).to be true
|
|
expect(AdministratorNotifications::ChannelNotificationsMailer).to have_received(:with).with(account: obj.account)
|
|
expect(mailer_method).to have_received(:deliver_later)
|
|
end
|
|
|
|
it 'reauthorized!' do
|
|
obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym)
|
|
# setting up the object with the errors to validate its cleared on action
|
|
obj.authorization_error!
|
|
obj.prompt_reauthorization!
|
|
expect(obj.reauthorization_required?).to be true
|
|
expect(obj.authorization_error_count).not_to eq 0
|
|
|
|
obj.reauthorized!
|
|
|
|
# authorization errors are reset
|
|
expect(obj.authorization_error_count).to eq 0
|
|
expect(obj.reauthorization_required?).to be false
|
|
end
|
|
end
|