|
35 | 35 |
|
36 | 36 | end |
37 | 37 |
|
38 | | - describe 'email notifications' do |
39 | | - let(:mailer_double) { instance_double(ActionMailer::MessageDelivery, deliver_now: true) } |
40 | | - |
41 | | - context 'when job succeeds' do |
42 | | - it 'sends completion email with attachments' do |
43 | | - fake_attachments = { |
44 | | - "fake_completed.csv" => { mime_type: 'text/csv', content: 'csvdata' } |
45 | | - } |
46 | | - |
47 | | - allow_any_instance_of(BibliographicJob) |
48 | | - .to receive(:generate_attatchments) |
49 | | - .and_return(fake_attachments) |
50 | | - |
51 | | - expect(RequestMailer) |
52 | | - .to receive(:bibliographic_email) |
53 | | - .with( |
54 | | - email, |
55 | | - fake_attachments, |
56 | | - 'Host Bibliographic Upload - Completed', |
57 | | - 'When there is an attached log file, please review unusual MMS ID information.' |
58 | | - ) |
59 | | - .and_return(mailer_double) |
60 | | - |
61 | | - BibliographicJob.perform_now(host_bib_task) |
62 | | - |
63 | | - expect(host_bib_task.reload.status).to eq('succeeded') |
64 | | - end |
65 | | - end |
66 | | - |
67 | | - context 'when job fails' do |
68 | | - it 'sends failure email' do |
69 | | - host_bib = host_bib_task.host_bibs.create(mms_id: mms_id1, marc_status: 'pending') |
70 | | - |
71 | | - allow(Bibliographic::HostBib) |
72 | | - .to receive(:create_linked_bibs) |
73 | | - .with(host_bib) |
74 | | - .and_raise(StandardError.new('Error')) |
75 | | - |
76 | | - expect(RequestMailer) |
77 | | - .to receive(:bibliographic_email) |
78 | | - .with( |
79 | | - email, |
80 | | - [], |
81 | | - 'Host Bibliographic Upload - Failed', |
82 | | - 'Host Bibliographic upload failed, please reach out to our support team.' |
83 | | - ) |
84 | | - .and_return(mailer_double) |
85 | | - |
86 | | - expect { |
87 | | - BibliographicJob.perform_now(host_bib_task) |
88 | | - }.to raise_error(StandardError) |
89 | | - |
90 | | - expect(host_bib_task.reload.status).to eq('failed') |
91 | | - end |
92 | | - end |
93 | | - end |
| 38 | + describe 'email notifications' do |
| 39 | + let(:mailer_double) { instance_double(ActionMailer::MessageDelivery, deliver_now: true) } |
| 40 | + |
| 41 | + context 'when job succeeds' do |
| 42 | + it 'sends completion email with attachments' do |
| 43 | + fake_attachments = { |
| 44 | + 'fake_completed.csv' => { mime_type: 'text/csv', content: 'csvdata' } |
| 45 | + } |
| 46 | + |
| 47 | + allow_any_instance_of(BibliographicJob) |
| 48 | + .to receive(:generate_attatchments) |
| 49 | + .and_return(fake_attachments) |
| 50 | + |
| 51 | + expect(RequestMailer) |
| 52 | + .to receive(:bibliographic_email) |
| 53 | + .with( |
| 54 | + email, |
| 55 | + fake_attachments, |
| 56 | + 'Host Bibliographic Upload - Completed', |
| 57 | + 'When there is an attached log file, please review unusual MMS ID information.' |
| 58 | + ).and_return(mailer_double) |
| 59 | + |
| 60 | + BibliographicJob.perform_now(host_bib_task) |
| 61 | + |
| 62 | + expect(host_bib_task.reload.status).to eq('succeeded') |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + context 'when job fails' do |
| 67 | + it 'sends failure email' do |
| 68 | + host_bib = host_bib_task.host_bibs.create(mms_id: mms_id1, marc_status: 'pending') |
| 69 | + |
| 70 | + allow(Bibliographic::HostBib) |
| 71 | + .to receive(:create_linked_bibs) |
| 72 | + .with(host_bib) |
| 73 | + .and_raise(StandardError.new('Error')) |
| 74 | + |
| 75 | + expect(RequestMailer) |
| 76 | + .to receive(:bibliographic_email) |
| 77 | + .with( |
| 78 | + email, |
| 79 | + [], |
| 80 | + 'Host Bibliographic Upload - Failed', |
| 81 | + 'Host Bibliographic upload failed, please reach out to our support team.' |
| 82 | + ).and_return(mailer_double) |
| 83 | + |
| 84 | + expect { BibliographicJob.perform_now(host_bib_task) }.to raise_error(StandardError) |
| 85 | + |
| 86 | + expect(host_bib_task.reload.status).to eq('failed') |
| 87 | + end |
| 88 | + end |
| 89 | + end |
94 | 90 | end |
0 commit comments