Skip to content

Commit 0a580d3

Browse files
committed
Refactoring out direct API call to external service
- moving to webhooks
1 parent adea99b commit 0a580d3

2 files changed

Lines changed: 17 additions & 79 deletions

File tree

app/models/submitter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def export_submission_on_status_change
139139
status_fields = %w[completed_at declined_at opened_at sent_at]
140140
return unless saved_changes.keys.intersect?(status_fields)
141141

142-
ExportSubmissionService.new(submission).call
142+
# CP-12761: Disabled - migrating to webhooks. Remove when ATS /api/docuseal/submissions endpoint is cleaned up.
143+
# ExportSubmissionService.new(submission).call
143144
rescue StandardError => e
144145
Rails.logger.error("Failed to export submission on status change: #{e.message}")
145146
end

spec/models/submitter_spec.rb

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -134,93 +134,30 @@
134134
end
135135

136136
describe '#export_submission_on_status_change' do
137-
let(:export_location) { create(:export_location, :with_submissions_endpoint) }
138-
let(:export_service) { instance_double(ExportSubmissionService) }
139-
137+
# CP-12761: ExportSubmissionService is disabled - submission sync migrated to webhooks.
138+
# These tests verify the service is not called on any status change.
140139
before do
141-
allow(ExportLocation).to receive(:default_location).and_return(export_location)
142-
allow(ExportSubmissionService).to receive(:new).with(submission).and_return(export_service)
143-
allow(export_service).to receive(:call).and_return(true)
140+
allow(ExportSubmissionService).to receive(:new)
144141
end
145142

146-
context 'when status-related field changes' do
147-
it 'calls ExportSubmissionService when completed_at changes' do
148-
submitter.update!(completed_at: Time.current)
149-
expect(ExportSubmissionService).to have_received(:new).with(submission)
150-
expect(export_service).to have_received(:call)
151-
end
152-
153-
it 'calls ExportSubmissionService when declined_at changes' do
154-
submitter.update!(declined_at: Time.current)
155-
expect(ExportSubmissionService).to have_received(:new).with(submission)
156-
expect(export_service).to have_received(:call)
157-
end
158-
159-
it 'calls ExportSubmissionService when opened_at changes' do
160-
submitter.update!(opened_at: Time.current)
161-
expect(ExportSubmissionService).to have_received(:new).with(submission)
162-
expect(export_service).to have_received(:call)
163-
end
164-
165-
it 'calls ExportSubmissionService when sent_at changes' do
166-
submitter.update!(sent_at: Time.current)
167-
expect(ExportSubmissionService).to have_received(:new).with(submission)
168-
expect(export_service).to have_received(:call)
169-
end
143+
it 'does not call ExportSubmissionService when completed_at changes' do
144+
submitter.update!(completed_at: Time.current)
145+
expect(ExportSubmissionService).not_to have_received(:new)
170146
end
171147

172-
context 'when non-status field changes' do
173-
it 'does not call ExportSubmissionService when email changes' do
174-
submitter.update!(email: 'new@example.com')
175-
expect(ExportSubmissionService).not_to have_received(:new)
176-
expect(export_service).not_to have_received(:call)
177-
end
178-
179-
it 'does not call ExportSubmissionService when name changes' do
180-
submitter.update!(name: 'New Name')
181-
expect(ExportSubmissionService).not_to have_received(:new)
182-
expect(export_service).not_to have_received(:call)
183-
end
148+
it 'does not call ExportSubmissionService when declined_at changes' do
149+
submitter.update!(declined_at: Time.current)
150+
expect(ExportSubmissionService).not_to have_received(:new)
184151
end
185152

186-
context 'when export service raises an error' do
187-
before do
188-
allow(export_service).to receive(:call).and_raise(StandardError.new('Export failed'))
189-
allow(Rails.logger).to receive(:error)
190-
end
191-
192-
it 'logs the error and does not re-raise' do
193-
expect { submitter.update!(completed_at: Time.current) }.not_to raise_error
194-
expect(Rails.logger).to have_received(:error).with(
195-
'Failed to export submission on status change: Export failed'
196-
)
197-
end
198-
end
199-
200-
context 'when ExportLocation.default_location returns nil' do
201-
before do
202-
allow(ExportLocation).to receive(:default_location).and_return(nil)
203-
allow(export_service).to receive(:call).and_return(false)
204-
end
205-
206-
it 'calls ExportSubmissionService but service handles nil export location' do
207-
submitter.update!(completed_at: Time.current)
208-
expect(ExportSubmissionService).to have_received(:new).with(submission)
209-
expect(export_service).to have_received(:call)
210-
end
153+
it 'does not call ExportSubmissionService when opened_at changes' do
154+
submitter.update!(opened_at: Time.current)
155+
expect(ExportSubmissionService).not_to have_received(:new)
211156
end
212157

213-
context 'when export location has no submissions_endpoint' do
214-
before do
215-
allow(export_location).to receive(:submissions_endpoint).and_return(nil)
216-
allow(export_service).to receive(:call).and_return(false)
217-
end
218-
219-
it 'calls ExportSubmissionService but service handles missing endpoint' do
220-
submitter.update!(completed_at: Time.current)
221-
expect(ExportSubmissionService).to have_received(:new).with(submission)
222-
expect(export_service).to have_received(:call)
223-
end
158+
it 'does not call ExportSubmissionService when sent_at changes' do
159+
submitter.update!(sent_at: Time.current)
160+
expect(ExportSubmissionService).not_to have_received(:new)
224161
end
225162
end
226163

0 commit comments

Comments
 (0)