Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/data_pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions spec/lib/data_pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -103,14 +117,17 @@

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'],
*users.map { |u| [u.email_addresses.first.email, u.uuid] },
['missing@example.com', '[NOT FOUND]'],
],
)

expect(result.subtask).to eq('uuid-lookup')
expect(result.uuids).to match_array(users.map(&:uuid))
end
end
end
Expand All @@ -125,14 +142,17 @@
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'],
*agency_identities.map { |a| [a.uuid, a.agency.name, a.user.uuid] },
['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
Expand All @@ -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'],
Expand All @@ -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
Expand Down