-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubjects_retirement_worker_spec.rb
More file actions
71 lines (57 loc) · 2.43 KB
/
subjects_retirement_worker_spec.rb
File metadata and controls
71 lines (57 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe SubjectsRetirementWorker, type: :job do
describe '#perform' do
let(:worker) { described_class.new }
let(:context) { Context.first }
let(:subject_set_id) { context.active_subject_set_id }
before do
allow(worker).to receive(:with_panoptes_retry).and_yield
allow(NotifyProjectOwnerJob).to receive(:perform_async)
end
context 'when a context does not exist' do
it 'returns early when no context is found' do
local_subject_set_id = 20
worker.perform(local_subject_set_id)
expect(worker).not_to have_received(:with_panoptes_retry)
expect(NotifyProjectOwnerJob).not_to have_received(:perform_async)
end
end
context 'when a context with a workflow id exists' do
let(:workflow_id) { context.workflow_id }
let(:panoptes_client) { instance_double(Panoptes::Client) }
before do
allow(Panoptes::Api).to receive(:client).and_return(panoptes_client)
end
context 'and the Panoptes response lacks completeness' do
before do
allow(panoptes_client).to receive(:subject_set).with(subject_set_id).and_return('completeness' => {})
end
it 'does not enqueue a notification' do
worker.perform(subject_set_id)
expect(NotifyProjectOwnerJob).not_to have_received(:perform_async)
end
end
context 'and the completion rate is below the threshold' do
before do
allow(panoptes_client).to receive(:subject_set).with(subject_set_id).and_return('completeness' => { workflow_id.to_s => 0.25 })
end
it 'does not enqueue a notification' do
worker.perform(subject_set_id)
expect(NotifyProjectOwnerJob).not_to have_received(:perform_async)
end
end
context 'and the completion rate meets the threshold' do
let(:completeness_value) { 0.96 }
before do
allow(panoptes_client).to receive(:subject_set).with(subject_set_id).and_return('completeness' => { workflow_id.to_s => completeness_value })
end
it 'enqueues a notification with the completion rate' do
worker.perform(subject_set_id)
expect(NotifyProjectOwnerJob).to have_received(:perform_async).with(subject_set_id, completeness_value)
expect(worker).to have_received(:with_panoptes_retry).with(max_retries: 3)
end
end
end
end
end