Skip to content

Commit

Permalink
Add ImportEntityTableCheck to import task (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericaporter authored Apr 22, 2024
1 parent 9d89664 commit 3dd4d79
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/dfe/analytics/tasks/import_entities.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ namespace :dfe do
puts 'DfE Analytics is not enabled - Ignoring import_entity'

abort('You need to specify a model name as an argument to the Rake task, eg dfe:analytics:import_entity[Model]') unless args[:entity_name]

entity_tag = Time.now.strftime('%Y%m%d%H%M%S')
DfE::Analytics::LoadEntities.new(**args).run(entity_tag: entity_tag)
DfE::Analytics::Services::EntityTableChecks.call(
entity_name: args[:entity_name],
entity_type: 'import_entity_table_check',
entity_tag: entity_tag
)
end
end
end
36 changes: 36 additions & 0 deletions spec/dfe/analytics/tasks/import_entities_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rake'

RSpec.describe 'dfe:analytics:import_entity Rake task' do
with_model :Candidate do
table do |t|
t.string :email_address
end
end

let(:rake) { Rake::Application.new }
let(:task_name) { 'dfe:analytics:import_entity' }
let(:entity_name) { 'Candidate' }
let(:entity_tag) { Time.now.strftime('%Y%m%d%H%M%S') }

before do
Rake.application.rake_require('import_entities', [File.expand_path('../../../../lib/dfe/analytics/tasks', __dir__)])
Rake::Task.define_task(:environment)

allow(DfE::Analytics).to receive(:models_for_entity).and_return([Candidate])
allow(DfE::Analytics::LoadEntities).to receive_message_chain(:new, :run)
allow(DfE::Analytics::Services::EntityTableChecks).to receive(:call)
Candidate.create(email_address: 'known@address.com')
end

it 'invokes LoadEntities and EntityTableChecks with correct parameters' do
expect(DfE::Analytics::LoadEntities).to receive(:new).with(entity_name: entity_name).and_call_original
expect(DfE::Analytics::Services::EntityTableChecks).to receive(:call).with(
entity_name: entity_name,
entity_type: 'import_entity_table_check',
entity_tag: entity_tag
)

Rake::Task[task_name].reenable
Rake::Task[task_name].invoke(entity_name)
end
end

0 comments on commit 3dd4d79

Please sign in to comment.