Skip to content

Commit

Permalink
Merge pull request #18 from The-Public-Radio/test-fixup
Browse files Browse the repository at this point in the history
Test fixup
  • Loading branch information
gabe-ochoa authored Mar 17, 2018
2 parents 638417b + f4116be commit b9269e4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 29 deletions.
20 changes: 11 additions & 9 deletions lib/tasks/orders/import_orders_from_email.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ namespace :orders do

emails.each_with_index do |email,i|
failed_orders = []
Rails.logger.info("Processing email #{i}")
Rails.logger.info("Processing email #{i}")

# We need this instantiated before we loop over emails
csv_source = nil

email.message.attachments.each do |a|
Rails.logger.info("Reading attachments")
Expand All @@ -35,20 +38,20 @@ namespace :orders do

Rails.logger.debug("Checking headers for determine csv source: #{headers}")
if source_check_headers.eql?(uncommon_goods_headers)
@csv_source = 'uncommon_goods'
csv_source = 'uncommon_goods'
elsif source_check_headers.eql?(generic_csv_headers)
@csv_source = 'generic'
csv_source = 'generic'
end

raise UnknownOrderHeaders.new(source_check_headers) if @csv_source.nil?
raise UnknownOrderHeaders.new(source_check_headers) if csv_source.nil?

# For each row in the csv, map to TPR params and create order while handling input errors
csv.each do |row|
# Map row into TPR order parameters
order = map_order_row(headers, row)
Rails.logger.debug("Mapped csv rows: #{order}")
begin
case @csv_source
case csv_source
when 'uncommon_goods'
order_params = parse_ucg_row(order)
when 'generic'
Expand Down Expand Up @@ -89,10 +92,9 @@ namespace :orders do
end
end
email.read!
end

if ENV['SEND_IMPORT_NOTIFICATION_EMAILS'] == true || emails.count != 0
TaskHelper.notify_of_import(@csv_source, all_failed_orders)
if ENV['SEND_IMPORT_NOTIFICATION_EMAILS'] == true || emails.count != 0
TaskHelper.notify_of_import(csv_source, all_failed_orders)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/shipments/shipments_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace :shipments do
if shippo_response['tracking_status'].nil?
Rails.logger.error("Tracking status is nil")
else
tracking_status = Shippo::Track.get(shipment.tracking_number, 'usps')['tracking_status']['status']
tracking_status = shippo_response['tracking_status']['status']
# Update shipment status
status_whitelist = %w{DELIVERED TRANSIT FAILURE RETURNED}
if status_whitelist.include?(tracking_status)
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/unknown_orders.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
date_created,expected_ship_date,order_id,quantity,sku,vendor_name,item_name,customer_name,st_address_line1,st_address_line2,city,state,postal_code,shipping_upgrade,shipment_id,external_order_id,bill_last_name,bill_address1,bill_address2,bill_city,bill_zip,bill_phonenum,bill_code,giftmessage,radio
dat_created,expected_ship_date,order_id,quantity,sku,vendor_name,item_name,customer_name,st_address_line1,st_address_line2,city,state,postal_code,shipping_upgrade,shipment_id,external_order_id,bill_last_name,bill_address1,bill_address2,bill_city,bill_zip,bill_phonenum,bill_code,giftmessage,radio
07/25/2017 00:00:00,2017-11-15 00:00:00.0,7875723,1,468810000000,Centerline Labs LLC,The Public Radio &#160;,mar medrd,238 Fairview Rd,,Raleigh,NC,27608,Economy 3-8 Business Days <br> (Final delivery likely to be by US Postal Service),8581381,0,mtha,meford,2308 Fairview Road,,Raleigh,27608,919-781-5957,,NC,,Choose a station- FM Frequency (US only):/^91.5
07/25/2017 00:00:00,2017-11-15 00:00:00.0,7875751,1,468810000000,Centerline Labs LLC,The Public Radio &#160;,cathy mulvney,43 Green Valley Rd,,Wallingford,PA,19086-6050,Economy 3-8 Business Days <br> (Final delivery likely to be by US Postal Service),8581411,mulaney,43 Green Vally Rd,,Wallingford,19086-6050,610-608-7120,,PA,,Choose a station- FM Frequency (US only):/^100.1
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ENV['UNCOMMON_GOODS_INVOICING_EMAILS'] = '[email protected],[email protected]'
ENV['INVOICE_FROM_EMAIL_ADDRESS'] = '[email protected]'
ENV['EMAILS_TO_NOTIFY_OF_IMPORT'] = '[email protected]'
ENV['EMAILS_TO_NOTIFY_OF_ORDERS'] = '[email protected]'
ENV['SQUARESPACE_API_KEY'] = 'test-key'
ENV['SQUARESPACE_APP_NAME'] = 'test-app'
ENV['TPR_ORDER_SOURCES'] = 'squarespace,kickstarter,uncommon_goods,other,WBEZ,warranty,KUER,LGA,WFAE,KERA,KXT'
Expand Down
17 changes: 2 additions & 15 deletions spec/tasks/orders/import_orders_from_email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:ucg_message) { double('message', attachments: [ucg_attachment]) }
let(:ucg_email) { double('ucg_email', message: ucg_message) }

# UCG order fixture
# Unknown order fixture
let(:unknown_fixture) { load_order_fixture('unknown_orders') }
let(:unknown_attachment) { double('attachment', decoded: unknown_fixture) }
let(:unknown_message) { double('message', attachments: [unknown_attachment]) }
Expand Down Expand Up @@ -110,27 +110,14 @@

it 'raises a error when no order source can be matched' do
expect_any_instance_of(TaskHelper).to receive(:find_unread_emails).and_return([unknown_email])
expect_any_instance_of(TaskHelper).to receive(:create_order)
expect(unknown_email).to receive(:message).and_return(unknown_message)
expect(unknown_message).to receive(:attachments).and_return([unknown_attachment])
expect(unknown_attachment).to receive(:decoded).and_return(unknown_fixture)
expect(unknown_email).to receive(:read!)
expect(unknown_attachment).to receive(:decoded).and_return(unknown_fixture)

expect{ task.execute }.to raise_error(UnknownOrderHeaders)
end

context 'cleans up any stray orders, shipments, and radios when the order' do
# error_email_params = {
# body: "There were 3 orders with errors. See 'error' collumn of attached csv for details."
# add_file: 'some/error/csv'
# }

# error_order_csv = CSV.parse(error_fixture)
# bad_address_params = error_order_csv[1]
# bad_frequency_params = error_order_csv[2]
# order_already_imported_params = error_order_csv[4]
# expect_any_instance_of(TaskHelper).to receive(:send_reply).with(error_email_params)

before(:each) do
expect_any_instance_of(TaskHelper).to receive(:find_unread_emails).and_return([error_email])
expect_any_instance_of(TaskHelper).to receive(:send_email)
Expand Down
2 changes: 1 addition & 1 deletion spec/tasks/orders/import_orders_from_squarespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

context 'from squarespace' do
it 'import all pendings orders' do
ENV['SEND_IMPORT_NOTIFICATION_EMAILS_SQUARESPACE'] = 'true'
api_key = ENV['SQUARESPACE_API_KEY']
app_name = ENV['SQUARESPACE_APP_NAME']

Expand All @@ -21,7 +22,6 @@
.and_return(stub_client)

expect(stub_client).to receive(:get_orders).with('pending').and_return(stub_orders)
expect_any_instance_of(TaskHelper).to receive(:notify_of_import).with('squarespace', [])

squarespace_order_fixture['result'].each do |test_order|
shipping_address = test_order['shippingAddress']
Expand Down
2 changes: 1 addition & 1 deletion spec/tasks/radios/send_radios_created_today_email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
expect(task.prerequisites).to include "environment"
end

it 'notifies ops@tpr of how many orders were imported that day' do
it 'notifies of how many orders were imported that day' do
radio_count = 4
create(:radio_boxed)
create_list(:radio_inital_order, 3)
Expand Down
2 changes: 1 addition & 1 deletion spec/tasks/shipments/shipments_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
shippo_response['tracking_status']['status'] = k

# Mock the shippo call
expect(Shippo::Track).to receive(:get).with(shipments[0].tracking_number, 'usps').and_return(shippo_response).exactly(3).times
expect(Shippo::Track).to receive(:get).with(shipments[0].tracking_number, 'usps').and_return(shippo_response).exactly(6).times
expect(Shippo::Track).to receive(:get).with(shipments[1].tracking_number, 'usps').and_return(shippo_response)

task.execute
Expand Down

0 comments on commit b9269e4

Please sign in to comment.