Files
openfoodnetwork/spec/lib/tasks/enterprises_rake_spec.rb
David Cook df81e8ed35 Add task to connect all enterprises
Example usage:
 rake ofn:enterprises:activate_connected_app_type[affiliate_sales_data]
2024-07-25 21:14:04 +10:00

46 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
require 'rake'
RSpec.describe 'enterprises.rake' do
before(:all) do
Rake.application.rake_require("tasks/enterprises")
Rake::Task.define_task(:environment)
end
describe ':remove_enterprise' do
context 'when the enterprises exists' do
it 'removes the enterprise' do
enterprise = create(:enterprise)
expect {
Rake.application.invoke_task "ofn:remove_enterprise[#{enterprise.id}]"
}.to change { Enterprise.count }.by(-1)
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