Skip to content

Commit b4deb1c

Browse files
committed
Update join column names.
We changed the join FK column names so that's it.
1 parent 052c056 commit b4deb1c

2 files changed

Lines changed: 21 additions & 31 deletions

File tree

app/jobs/salesforce/role_sync_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class RoleSyncJob < SalesforceSyncJob
66

77
FIELD_MAPPINGS = {
88
affiliation_id__c: :id,
9-
contact__c: :user_id,
10-
editor__c: :school_id,
9+
contact__r__pi_accounts_unique_id__c: :user_id,
10+
editor__r__editoruuid__c: :school_id,
1111
roletype__c: :role,
1212
createdat__c: :created_at,
1313
updatedat__c: :updated_at

spec/jobs/salesforce/role_sync_job_spec.rb

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,43 @@
55
RSpec.describe Salesforce::RoleSyncJob do
66
subject(:perform_job) { described_class.perform_now(role_id: role.id) }
77

8-
context 'when the job has run' do
9-
let(:role) { create(:role) }
10-
let(:sf_role) { Salesforce::Role.find(role.id) }
8+
let(:role) { create(:role) }
9+
let(:sf_role) { instance_double(Salesforce::Role) }
10+
let(:synced_attributes) { {} }
11+
12+
before do
13+
allow(Salesforce::Role).to receive(:find_or_initialize_by).with(affiliation_id__c: role.id).and_return(sf_role)
14+
allow(sf_role).to receive(:attributes=) { |attrs| synced_attributes.merge!(attrs) }
15+
allow(sf_role).to receive(:save!)
16+
end
1117

18+
context 'when the job has run' do
1219
before { perform_job }
1320

14-
it 'syncs the standard mappings' do
15-
described_class::FIELD_MAPPINGS.each do |sf_field, field|
16-
sf_value = sf_role.send(sf_field)
17-
role_value = role.send(field)
18-
column = Salesforce::Role.column_for_attribute(sf_field)
19-
20-
expected = if role_value.is_a?(String) && column.limit
21-
role_value.truncate(column.limit, omission: '…')
22-
elsif column.type == :string
23-
role_value.to_s
24-
else
25-
role_value
26-
end
27-
28-
expect(sf_value).to eq(expected), "Expected #{sf_field} to be #{expected.inspect} but was #{sf_value.inspect}"
21+
it 'syncs all FIELD_MAPPINGS to the correct role values' do
22+
described_class::FIELD_MAPPINGS.each do |sf_field, role_field|
23+
expect(synced_attributes[sf_field]).to eq(role.send(role_field)),
24+
"Expected #{sf_field} to equal role.#{role_field}"
2925
end
3026
end
27+
28+
it 'saves the Salesforce record' do
29+
expect(sf_role).to have_received(:save!)
30+
end
3131
end
3232

3333
context 'when the Salesforce role fails to save' do
34-
let(:role) { create(:role) }
35-
let(:sf_role) { instance_double(Salesforce::Role) }
36-
37-
before do
38-
allow(Salesforce::Role).to receive(:find_or_initialize_by).with(affiliation_id__c: role.id).and_return(sf_role)
39-
allow(sf_role).to receive(:attributes=)
40-
allow(sf_role).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
41-
end
34+
before { allow(sf_role).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) }
4235

4336
it 'raises an error' do
4437
expect { perform_job }.to raise_error ActiveRecord::RecordInvalid
4538
end
4639
end
4740

4841
context 'when SALESFORCE_ENABLED is false' do
49-
let(:role) { create(:role) }
50-
5142
before { stub_const('ENV', ENV.to_h.merge('SALESFORCE_ENABLED' => 'false')) }
5243

5344
it 'discards the job without syncing' do
54-
allow(Salesforce::Role).to receive(:find_or_initialize_by)
5545
perform_job
5646
expect(Salesforce::Role).not_to have_received(:find_or_initialize_by)
5747
end

0 commit comments

Comments
 (0)