spec/lib/bankserv/engine/engine_spec.rb in bankserv-0.2.3 vs spec/lib/bankserv/engine/engine_spec.rb in bankserv-0.2.4
- old
+ new
@@ -16,10 +16,11 @@
end
FileUtils.rm_rf(Dir.pwd + "/spec/examples/host2host/archives", secure: true)
File.delete(Dir.pwd + "/spec/tmp/harry.txt")
File.delete(Dir.pwd + "/spec/tmp/sally.txt")
+ File.delete(Dir.pwd + "/spec/tmp/molly.txt")
end
context "Prepare engine" do
it "should contain default values from the migration" do
@@ -40,11 +41,11 @@
end
context "Testing individual methods of engine" do
before(:all) do
- create(:configuration, client_code: "986", client_name: "TESTTEST", user_code: "9999", user_generation_number: 846, client_abbreviated_name: "TESTTEST")
+ Bankserv::DebitService.register(client_code: '12345', client_name: "RCTEST", client_abbreviated_name: 'RCTEST', user_code: "9534", transmission_status: "L", transmission_number: "1")
t = Time.local(2012, 1, 23, 10, 5, 0)
Timecop.travel(t)
file_contents = File.open("./spec/examples/eft_input_with_2_sets.txt", "rb").read
Bankserv::InputDocument.store(file_contents)
@@ -52,23 +53,23 @@
Bankserv::Engine.output_directory = Dir.pwd + "/spec/examples/host2host"
Bankserv::Engine.input_directory = Dir.pwd + "/spec/examples/host2host"
Bankserv::Engine.archive_directory = Dir.pwd + "/spec/examples/host2host/archives"
- @queue = Bankserv::Engine.new
+ @engine = Bankserv::Engine.new
end
it "should be able to start processing work" do
- @queue.start!.should be_true
+ @engine.start!.should be_true
end
it "should be set to running" do
- @queue.running?.should be_true
+ @engine.running?.should be_true
end
it "should be expecting a reply file" do
- @queue.expecting_reply_file?.should be_true
+ @engine.expecting_reply_file?.should be_true
end
it "should be able to return a list of reply files" do
Bankserv::Engine.reply_files.should == ["REPLY0412153000.txt"]
end
@@ -76,23 +77,23 @@
it "should be able to return a list of output files" do
Bankserv::Engine.output_files.should == ["OUTPUT0412153500.txt"]
end
it "should be able to process reply files" do
- @queue.process_reply_files
+ @engine.process_reply_files
Bankserv::Document.first.reply_status.should == "ACCEPTED"
- @queue.expecting_reply_file?.should be_false
+ @engine.expecting_reply_file?.should be_false
end
it "should be able to process output files" do
- @queue.process_output_files
+ @engine.process_output_files
end
it "should be able to set the process to finished" do
- @queue.finish!.should be_true
- @queue.running?.should be_false
- @queue.process.success.should be_true
+ @engine.finish!.should be_true
+ @engine.running?.should be_false
+ @engine.process.success.should be_true
end
it "should not have any processes running" do
Bankserv::Engine.running?.should be_false
end
@@ -104,52 +105,50 @@
before(:all) do
tear_it_down
Timecop.travel(Time.local(2008, 8, 8, 10, 5, 0))
Bankserv::EngineConfiguration.create!(interval_in_minutes: 15, input_directory: "/tmp", output_directory: "/tmp", archive_directory: "/tmp")
- create(:configuration, client_code: "986", client_name: "TESTTEST", user_code: "9999", user_generation_number: 846, client_abbreviated_name: "TESTTEST")
+ @service = Bankserv::CreditService.register(client_code: '12345', client_name: "RCTEST", client_abbreviated_name: 'RCTEST', user_code: "9534", transmission_status: "L", transmission_number: "1")
- create_credit_request
+ create_credit_request(@service)
- Bankserv::Configuration.stub!(:live_env?).and_return(true)
- Bankserv::InputDocument.stub!(:fetch_next_transmission_number).and_return("846")
- Bankserv::Transmission::UserSet::Eft.stub!(:last_sequence_number_today).and_return(77)
-
Bankserv::Engine.output_directory = Dir.pwd + "/spec/examples/host2host"
Bankserv::Engine.input_directory = Dir.pwd + "/spec/examples/host2host"
Bankserv::Engine.archive_directory = Dir.pwd + "/spec/examples/host2host/archives"
- @queue = Bankserv::Engine.new
- @queue.start! # create a process
+ @engine = Bankserv::Engine.new
+ @engine.start! # create a process
end
it "should process the document" do
- @queue.process_input_files
+ @engine.process_input_files
@document = Bankserv::Document.last
@document.processed.should be_true
- @queue.expecting_reply_file?.should be_true
+ @engine.expecting_reply_file?.should be_true
end
it "should write a file to the input directory" do
(Dir.glob(Dir.pwd + "/spec/examples/host2host/INPUT*.txt").size == 1).should be_true
end
end
context "integration testing" do
- before(:each) do
+ before(:all) do
+ tear_it_down
Timecop.travel(Time.local(2012, 4, 10, 10, 5, 0))
@tmpdir = Dir.pwd + "/spec/tmp"
- tear_it_down
- create(:configuration, client_code: "12345", client_name: "TESTTEST", user_code: "9999", user_generation_number: 1, client_abbreviated_name: "TESTTEST", department_code: "506")
+ @ahv_service = Bankserv::AHVService.register(client_code: '12345', internal_branch_code: '632005', department_code: "506", client_name: "TESTTEST", client_abbreviated_name: 'TESTTEST', generation_number: 1, transmission_status: "L", transmission_number: "1")
+ @debit_service = Bankserv::DebitService.register(client_code: '12346', client_name: "TESTTEST", client_abbreviated_name: 'TESTTEST', user_code: "9999", generation_number: 1, transmission_status: "L", transmission_number: "1")
+ @credit_service = Bankserv::CreditService.register(client_code: '12347', client_name: "TESTTEST", client_abbreviated_name: 'TESTTEST', user_code: "9999", generation_number: 1, transmission_status: "L", transmission_number: "1")
Bankserv::EngineConfiguration.create!(interval_in_minutes: 15, input_directory: @tmpdir, output_directory: @tmpdir, archive_directory: @tmpdir)
end
it "should process ahv requests" do
Bankserv::AccountHolderVerification.should_receive(:generate_reference_number).exactly(8).times.and_return("AHV67","AHV68","AHV69","AHV70","AHV71","AHV72","AHV73","AHV74")
- create_ahv_requests_scenario
+ create_ahv_requests_scenario(@ahv_service)
e = Bankserv::Engine.new
e.should_receive(:generate_input_file_name).and_return("harry.txt")
e.process!
expected_string = File.open("./spec/examples/INPUT.120410144410.txt", "rb").read
@@ -157,24 +156,32 @@
got_string.should == expected_string
end
it "should process debit requests" do
- create_debit_requests_scenario
+ create_debit_requests_scenario(@debit_service)
e = Bankserv::Engine.new
e.should_receive(:generate_input_file_name).and_return("sally.txt")
e.process!
- puts e.inspect
expected_string = File.open("./spec/examples/INPUT.120411110604.txt", "rb").read
got_string = File.open(@tmpdir + '/sally.txt', "rb").read
got_string.should == expected_string
end
it "should process credit requests" do
- pending
+ create_credit_requests_scenario(@credit_service)
+
+ e = Bankserv::Engine.new
+ e.should_receive(:generate_input_file_name).and_return("molly.txt")
+ e.process!
+
+ expected_string = File.open("./spec/examples/INPUT.120411124123.txt", "rb").read
+ got_string = File.open(@tmpdir + '/molly.txt', "rb").read
+
+ got_string.should == expected_string
end
end
end
\ No newline at end of file