Skip to content

Commit

Permalink
Merged in r2-2655-api-disabling-notifications (pull request #6601)
Browse files Browse the repository at this point in the history
R2-2655 - API Disabling send push and email notifications
  • Loading branch information
aespinoza-quoin authored and pnabutovsky committed Nov 21, 2023
2 parents a1ffbcf + 6d14b34 commit 3bdc77d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/models/assign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class Assign < Transition
MAX_BULK_RECORDS = 100

attr_accessor :from_bulk_export

def perform
return if transitioned_to_user.nil?

Expand All @@ -25,4 +27,8 @@ def consent_given?
def notified_statuses
[Transition::STATUS_DONE]
end

def should_notify?
!from_bulk_export && super
end
end
6 changes: 5 additions & 1 deletion app/models/transition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ def notified_statuses
end

def notify
return unless notified_statuses.include?(status)
return unless should_notify?

TransitionNotifyJob.perform_later(id)
end

def should_notify?
notified_statuses.include?(status)
end

def index_record
Sunspot.index(record) if record
end
Expand Down
3 changes: 2 additions & 1 deletion app/services/bulk_assign_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def create_assignment(record)
record:,
transitioned_to: @args[:transitioned_to],
transitioned_by: @transitioned_by.user_name,
notes: @args[:notes]
notes: @args[:notes],
from_bulk_export: true
)
end

Expand Down
24 changes: 24 additions & 0 deletions spec/jobs/bulk_assign_records_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
disclosure_other_orgs: true, module_id: PrimeroModule::CP)
end

before :each do
BulkAssignService.any_instance.stub(:search_results).and_return([child])
end

describe 'perform_later' do
before do
ActiveJob::Base.queue_adapter = :test
Expand All @@ -53,6 +57,26 @@
end
end

describe 'when job is performed' do
let(:bulk_assign_params) do
{
transitioned_to: user2.user_name,
transitioned_by: user.user_name,
notes: 'this is a note',
filters: { short_id: [child.short_id] }
}
end

it 'should not enqueue a TransitionNotifyJob' do
ActiveJob::Base.queue_adapter = :test
BulkAssignRecordsJob.perform_now(Child, user, **bulk_assign_params)

expect(
ActiveJob::Base.queue_adapter.enqueued_jobs.select { |j| j[:job] == TransitionNotifyJob }.size
).to eq(0)
end
end

after :each do
clean_data(User, Role, PrimeroModule, PrimeroProgram, Field, FormSection, UserGroup, Agency, Child, Transition)
end
Expand Down
24 changes: 24 additions & 0 deletions spec/models/assign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require 'rails_helper'

describe Assign do
include ActiveJob::TestHelper

before do
clean_data(User, Role, PrimeroModule, UserGroup, Agency, Transition, Incident, Child)

Expand Down Expand Up @@ -150,6 +152,28 @@
end
end
end

describe '.notify' do
context 'when should_notify? is true' do
it 'should enqueue a TransitionNotifyJob' do
expect(
ActiveJob::Base.queue_adapter.enqueued_jobs.select { |j| j[:job] == TransitionNotifyJob }.size
).to eq(1)
end
end
context 'when should_notify? is false' do
before do
clear_enqueued_jobs
Assign.create!(transitioned_by: 'user1', transitioned_to: 'user2', record: @case, from_bulk_export: true)
end

it 'should enqueue a TransitionNotifyJob' do
expect(
ActiveJob::Base.queue_adapter.enqueued_jobs.select { |j| j[:job] == TransitionNotifyJob }.size
).to eq(0)
end
end
end
end

context 'and the user has permission within the user group' do
Expand Down
3 changes: 2 additions & 1 deletion spec/services/bulk_assign_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
{
transitioned_to: user2.user_name,
transitioned_by: user.user_name,
notes: 'this is a note'
notes: 'this is a note',
from_bulk_export: true
}
end

Expand Down

0 comments on commit 3bdc77d

Please sign in to comment.