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
4 changes: 2 additions & 2 deletions app/services/gpo_confirmation_uploader.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class GpoConfirmationUploader
def initialize
@now = Time.zone.now
def initialize(now = Time.zone.now)
@now = now
end

def run
Expand Down
12 changes: 7 additions & 5 deletions spec/services/gpo_confirmation_uploader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'rails_helper'

RSpec.describe GpoConfirmationUploader do
let(:uploader) { described_class.new }
let(:uploader) { described_class.new(now) }
let(:now) { Time.zone.now }

let(:export) { 'foo|bar' }
let(:confirmations) do
Expand Down Expand Up @@ -52,12 +53,13 @@
subject { uploader.send(:upload_export, export) }

let(:sftp_connection) { instance_double('Net::SFTP::Session') }
let(:string_io) { StringIO.new(export) }

it 'uploads the export via sftp' do
expect(Net::SFTP).to receive(:start).with(*sftp_options).and_yield(sftp_connection)
expect(StringIO).to receive(:new).with(export).and_return(string_io)
expect(sftp_connection).to receive(:upload!).with(string_io, upload_folder)
expect(sftp_connection).to receive(:upload!) do |string_io, folder|
expect(string_io.string).to eq(export)
expect(folder).to eq(upload_folder)
end

subject
end
Expand Down Expand Up @@ -115,7 +117,7 @@ def sftp_options
end

def upload_folder
timestamp = Time.zone.now.strftime('%Y%m%d-%H%M%S')
timestamp = now.strftime('%Y%m%d-%H%M%S')
File.join(IdentityConfig.store.usps_upload_sftp_directory, "batch#{timestamp}.psv")
end

Expand Down