Skip to content

Commit ff9a2dd

Browse files
fspeirscursoragent
andcommitted
Assert retry enqueue instead of raise in parent-guard specs
`SalesforceSyncJob` retries on `SalesforceRecordNotFound`, so when `perform_now` raises it ActiveJob catches the error and re-enqueues the job rather than propagating. The new contexts asserted `raise_error`, which never matched. Mirror the existing `ContactSyncJob` spec pattern and assert `have_enqueued_job` (plus, for the side-effect tests, that no `Salesforce::Role` row is written). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4c67ee3 commit ff9a2dd

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

spec/jobs/salesforce/role_sync_job_spec.rb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,46 +62,42 @@
6262
context 'when the parent Editor__c is not yet synced to Salesforce' do
6363
before { sf_school.update!(sfid: nil) }
6464

65-
it 'raises SalesforceRecordNotFound to defer the affiliation write' do
66-
expect { perform_job }
67-
.to raise_error(Salesforce::SalesforceSyncJob::SalesforceRecordNotFound, /Editor__c not yet synced/)
65+
it 'retries the job to defer the affiliation write' do
66+
expect { perform_job }.to have_enqueued_job(described_class).with(role_id: role.id)
6867
end
6968

7069
it 'does not write the affiliation to the mirror' do
71-
expect { perform_job }.to raise_error(Salesforce::SalesforceSyncJob::SalesforceRecordNotFound)
70+
perform_job
7271
expect(Salesforce::Role.find_by(affiliation_id__c: role.id)).to be_nil
7372
end
7473
end
7574

7675
context 'when there is no Salesforce::School row for the role school' do
7776
before { sf_school.destroy }
7877

79-
it 'raises SalesforceRecordNotFound' do
80-
expect { perform_job }
81-
.to raise_error(Salesforce::SalesforceSyncJob::SalesforceRecordNotFound, /Editor__c not yet synced/)
78+
it 'retries the job' do
79+
expect { perform_job }.to have_enqueued_job(described_class).with(role_id: role.id)
8280
end
8381
end
8482

8583
context 'when the parent Contact is not yet synced to Salesforce' do
8684
before { sf_contact.update!(sfid: nil) }
8785

88-
it 'raises SalesforceRecordNotFound to defer the affiliation write' do
89-
expect { perform_job }
90-
.to raise_error(Salesforce::SalesforceSyncJob::SalesforceRecordNotFound, /Contact not yet synced/)
86+
it 'retries the job to defer the affiliation write' do
87+
expect { perform_job }.to have_enqueued_job(described_class).with(role_id: role.id)
9188
end
9289

9390
it 'does not write the affiliation to the mirror' do
94-
expect { perform_job }.to raise_error(Salesforce::SalesforceSyncJob::SalesforceRecordNotFound)
91+
perform_job
9592
expect(Salesforce::Role.find_by(affiliation_id__c: role.id)).to be_nil
9693
end
9794
end
9895

9996
context 'when there is no Salesforce::Contact row for the role user' do
10097
before { sf_contact.destroy }
10198

102-
it 'raises SalesforceRecordNotFound' do
103-
expect { perform_job }
104-
.to raise_error(Salesforce::SalesforceSyncJob::SalesforceRecordNotFound, /Contact not yet synced/)
99+
it 'retries the job' do
100+
expect { perform_job }.to have_enqueued_job(described_class).with(role_id: role.id)
105101
end
106102
end
107103

0 commit comments

Comments
 (0)