|
17 | 17 | @original_secret = ENV['PDF_REMEDIATION_WEBHOOK_SECRET'] |
18 | 18 | ENV['PDF_REMEDIATION_WEBHOOK_SECRET'] = secret |
19 | 19 | allow(BuildAutoRemediatedWorkVersionJob).to receive(:perform_later).and_return(nil) |
| 20 | + allow(AutoRemediationFailedJob).to receive(:perform_later).and_return(nil) |
20 | 21 | end |
21 | 22 |
|
22 | 23 | after do |
|
70 | 71 | expect(BuildAutoRemediatedWorkVersionJob).to have_received(:perform_later) |
71 | 72 | .with(file.remediation_job_uuid, 'https://example.com/out.pdf') |
72 | 73 | end |
| 74 | + |
| 75 | + context 'when an error occurs enqueuing the job' do |
| 76 | + before do |
| 77 | + allow(BuildAutoRemediatedWorkVersionJob).to receive(:perform_later).and_raise(StandardError.new('Redis error')) |
| 78 | + allow(Rails.logger).to receive(:error) |
| 79 | + end |
| 80 | + |
| 81 | + it 'stores the failure timestamp and returns 500 with the error message' do |
| 82 | + post :create, params: params, as: :json |
| 83 | + |
| 84 | + expect(response).to have_http_status(:internal_server_error) |
| 85 | + expect(response.parsed_body).to include('error' => 'Redis error') |
| 86 | + expect(file.reload.auto_remediation_failed_at).not_to be_nil |
| 87 | + end |
| 88 | + end |
73 | 89 | end |
74 | 90 |
|
75 | 91 | describe 'job.failed handling' do |
|
82 | 98 | allow(Rails.logger).to receive(:error) |
83 | 99 | end |
84 | 100 |
|
85 | | - it 'logs the failure and returns 200 with the processing message' do |
| 101 | + it 'logs the failure, enqueues the failed job, stores the failure timestamp and returns 200 with the processing message' do |
86 | 102 | post :create, params: params, as: :json |
87 | 103 |
|
88 | 104 | expect(response).to have_http_status(:ok) |
89 | 105 | expect(response.parsed_body).to include('message' => error_message) |
90 | 106 | expect(Rails.logger).to have_received(:error) |
91 | 107 | .with("Auto-remediation job failed: #{error_message}") |
| 108 | + expect(AutoRemediationFailedJob).to have_received(:perform_later).with(file.remediation_job_uuid) |
| 109 | + expect(file.reload.auto_remediation_failed_at).not_to be_nil |
92 | 110 | end |
93 | 111 | end |
94 | 112 | end |
|
0 commit comments