-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated openstax_salesforce, fixed cassettes, added routine to update SF assignable fields * Added spec for routine that updates Salesforce Assignable fields, fixed error in query
- Loading branch information
Showing
8 changed files
with
110 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class UpdateSalesforceAssignableFields | ||
def self.call(created_after = nil) | ||
new.call(created_after) | ||
end | ||
|
||
def call(created_after) | ||
created_after ||= 1.month.ago | ||
|
||
# Currently ExternalIds are only used by Assignable | ||
# If this will change at some point, migrate ExternalIds first to add a field to distinguish them | ||
ExternalId.select(:user_id, ExternalId.arel_table[:created_at].minimum.as('min_created_at')) | ||
.group(:user_id) | ||
.having(ExternalId.arel_table[:created_at].minimum.gt(created_after)) | ||
.preload(:user) | ||
.each do |external_id| | ||
contact_id = external_id.user.salesforce_contact_id | ||
next if contact_id.nil? | ||
|
||
contact = OpenStax::Salesforce::Remote::Contact.find(contact_id) | ||
contact.assignable_interest = 'Fully Integrated' | ||
contact.assignable_adoption_date = external_id.min_created_at | ||
contact.save! | ||
end | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
spec/cassettes/Change_Salesforce_contact_manually/can_be_set_if_the_Contact_exists_in_SF.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../Change_Salesforce_contact_manually/cannot_be_set_if_the_Contact_does_not_exist_in_SF.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../cassettes/Change_Salesforce_contact_manually/cannot_be_set_if_the_ID_is_of_malformed.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe UpdateSalesforceAssignableFields, type: :routine do | ||
let!(:non_assignable_student) { FactoryBot.create :user } | ||
|
||
let!(:non_assignable_instructor) { FactoryBot.create :user, salesforce_contact_id: 'TESTCONTACT1' } | ||
|
||
let!(:assignable_student) do | ||
FactoryBot.create(:user).tap do |user| | ||
FactoryBot.create :external_id, user: user | ||
FactoryBot.create :external_id, user: user | ||
end | ||
end | ||
|
||
let!(:assignable_instructor) do | ||
FactoryBot.create(:user, salesforce_contact_id: 'TESTCONTACT2').tap do |user| | ||
FactoryBot.create :external_id, user: user | ||
FactoryBot.create :external_id, user: user | ||
end | ||
end | ||
|
||
context 'new School' do | ||
it "updates Salesforce Contact with Assignable user's info" do | ||
stub_contacts [ non_assignable_instructor, assignable_instructor ] | ||
|
||
expect_any_instance_of(OpenStax::Salesforce::Remote::Contact).to( | ||
receive(:assignable_interest=).with('Fully Integrated').and_call_original | ||
) | ||
expect_any_instance_of(OpenStax::Salesforce::Remote::Contact).to( | ||
receive(:assignable_adoption_date=).with( | ||
assignable_instructor.external_ids.map(&:created_at).min | ||
).and_call_original | ||
) | ||
expect_any_instance_of(OpenStax::Salesforce::Remote::Contact).to receive(:save!) | ||
|
||
described_class.call | ||
end | ||
end | ||
|
||
def stub_contacts(users) | ||
sf_contacts = [users].flatten.map do |user| | ||
id = user.salesforce_contact_id | ||
[ id, OpenStax::Salesforce::Remote::Contact.new(id: id) ] | ||
end.to_h | ||
|
||
expect(OpenStax::Salesforce::Remote::Contact).to receive(:find) { |id| sf_contacts[id] } | ||
end | ||
end |