diff --git a/lib/data_pull.rb b/lib/data_pull.rb index 89b99d65110..3ee39913917 100644 --- a/lib/data_pull.rb +++ b/lib/data_pull.rb @@ -11,7 +11,8 @@ def initialize(argv:, stdout:, stderr:) Result = Struct.new( :table, # tabular output, rendered as an ASCII table or as CSV - :log_message, # summary message used for audit logging, DO NOT PUT PII HERE + :subtask, # name of subtask, used for audit logging + :uuids, # Array of UUIDs entered or returned, used for audit logging keyword_init: true, ) @@ -38,13 +39,17 @@ def run subtask_class = subtask(argv.shift) if config.show_help? || !subtask_class + stderr.puts '*Task*: `help`' + stderr.puts '*UUIDs*: N/A' + stdout.puts option_parser return end result = subtask_class.new.run(args: argv, include_missing: config.include_missing?) - stderr.puts result.log_message + stderr.puts "*Task*: `#{result.subtask}`" + stderr.puts "*UUIDs*: #{result.uuids.map { |uuid| "`#{uuid}`" }.join(', ')}" render_output(result.table) end @@ -156,8 +161,9 @@ def run(args:, include_missing:) end Result.new( - log_message: "uuid-lookup, uuids: #{uuids.join(', ')}", + subtask: 'uuid-lookup', table:, + uuids:, ) end end @@ -181,7 +187,8 @@ def run(args:, include_missing:) end Result.new( - log_message: "uuid-convert, uuids: #{identities.map { |u| u.user.uuid }.join(', ')}", + subtask: 'uuid-convert', + uuids: identities.map { |u| u.user.uuid }, table:, ) end @@ -209,7 +216,8 @@ def run(args:, include_missing:) end Result.new( - log_message: "email-lookup, uuids: #{users.map(&:uuid).join(', ')}", + subtask: 'email-lookup', + uuids: users.map(&:uuid), table:, ) end diff --git a/spec/lib/data_pull_spec.rb b/spec/lib/data_pull_spec.rb index 04a1621690f..4abec8ef71a 100644 --- a/spec/lib/data_pull_spec.rb +++ b/spec/lib/data_pull_spec.rb @@ -20,6 +20,13 @@ expect(stdout.string).to include('Options:') end + + it 'prints help to stderr', aggregate_failures: true do + data_pull.run + + expect(stderr.string).to include('*Task*: `help`') + expect(stderr.string).to include('*UUIDs*: N/A') + end end describe '--csv' do @@ -50,6 +57,13 @@ end end + it 'logs UUIDs and the command name to STDERR formatted for Slack', aggregate_failures: true do + data_pull.run + + expect(stderr.string).to include('`uuid-lookup`') + expect(stderr.string).to include("`#{user.uuid}`") + end + describe '--json' do before { argv << '--json' } it 'formats output as JSON' do @@ -103,7 +117,7 @@ subject(:result) { subtask.run(args:, include_missing:) } - it 'looks up the UUIDs for the given email addresses' do + it 'looks up the UUIDs for the given email addresses', aggregate_failures: true do expect(result.table).to eq( [ ['email', 'uuid'], @@ -111,6 +125,9 @@ ['missing@example.com', '[NOT FOUND]'], ], ) + + expect(result.subtask).to eq('uuid-lookup') + expect(result.uuids).to match_array(users.map(&:uuid)) end end end @@ -125,7 +142,7 @@ let(:include_missing) { true } subject(:result) { subtask.run(args:, include_missing:) } - it 'converts the agency agency identities to internal UUIDs' do + it 'converts the agency agency identities to internal UUIDs', aggregate_failures: true do expect(result.table).to eq( [ ['partner_uuid', 'source', 'internal_uuid'], @@ -133,6 +150,9 @@ ['does-not-exist', '[NOT FOUND]', '[NOT FOUND]'], ], ) + + expect(result.subtask).to eq('uuid-convert') + expect(result.uuids).to match_array(agency_identities.map(&:user).map(&:uuid)) end end end @@ -147,7 +167,7 @@ let(:include_missing) { true } subject(:result) { subtask.run(args:, include_missing:) } - it 'loads email addresses for the user' do + it 'loads email addresses for the user', aggregate_failures: true do expect(result.table).to match( [ ['uuid', 'email', 'confirmed_at'], @@ -157,6 +177,9 @@ ['does-not-exist', '[NOT FOUND]', nil], ], ) + + expect(result.subtask).to eq('email-lookup') + expect(result.uuids).to eq([user.uuid]) end end end