Skip to content

Commit

Permalink
Add task to connect all enterprises
Browse files Browse the repository at this point in the history
Example usage:
 rake ofn:enterprises:activate_connected_app_type[affiliate_sales_data]
  • Loading branch information
dacook committed Jul 25, 2024
1 parent e9d7a0b commit df81e8e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/tasks/enterprises.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ namespace :ofn do
enterprise.destroy
end

namespace :enterprises do
desc "Activate connected app type for ALL enterprises"
task :activate_connected_app_type, [:type] => :environment do |_task, args|
Enterprise.find_each do |enterprise|
next if enterprise.connected_apps.public_send(args.type.underscore).exists?

"ConnectedApps::#{args.type.camelize}".constantize.new(enterprise:).connect({})
puts "Enterprise #{enterprise.id} connected."
end
end
end

namespace :dev do
desc 'export enterprises to CSV'
task export_enterprises: :environment do
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/tasks/enterprises_rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,26 @@
end
end
end

describe ':enterprises' do
describe ':activate_connected_app_type' do
it 'updates only disconnected enterprises' do
# enterprise with affiliate sales data
enterprise_asd = create(:enterprise)
enterprise_asd.connected_apps.create type: 'ConnectedApps::AffiliateSalesData'
# enterprise with different type
enterprise_diff = create(:enterprise)
enterprise_diff.connected_apps.create

expect {
Rake.application.invoke_task(
"ofn:enterprises:activate_connected_app_type[affiliate_sales_data]"
)
}.to change { ConnectedApps::AffiliateSalesData.count }.by(1)

expect(enterprise_asd.connected_apps.affiliate_sales_data.count).to eq 1
expect(enterprise_diff.connected_apps.affiliate_sales_data.count).to eq 1
end
end
end
end

0 comments on commit df81e8e

Please sign in to comment.