From 15bc0e555a0387af102a879229f9297c260722f4 Mon Sep 17 00:00:00 2001 From: Guillermo Moreno Date: Fri, 17 Mar 2017 12:52:34 -0300 Subject: [PATCH] remove even more tests --- coverage/.last_run.json | 2 +- coverage/.resultset.json | 458 +++++++++++++++++- .../transaction_service_spec.rb | 180 ------- 3 files changed, 458 insertions(+), 182 deletions(-) delete mode 100644 spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 3cb5e70..c6c24b4 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 100.0 + "covered_percent": 66.49 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index c7b46ba..db0e7c2 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -1,7 +1,463 @@ { "RSpec": { "coverage": { + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/spec/models/punto_pagos_rails/transaction_spec.rb": [ + 1, + null, + 1, + 1, + 2, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/rails_helper.rb": [ + 1, + null, + 1, + 1, + 1, + 1, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + 1, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/environment.rb": [ + null, + 1, + null, + null, + 1 + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/application.rb": [ + 1, + null, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/boot.rb": [ + null, + 1, + null, + 1, + 1 + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/lib/punto_pagos_rails.rb": [ + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/lib/punto_pagos_rails/engine.rb": [ + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/lib/punto_pagos_rails/payable.rb": [ + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + null, + 1, + 0, + null, + 0, + 0, + null, + null, + null, + null, + null, + 0, + 0, + null, + null, + 0, + 0, + 0, + null, + null, + null, + 1, + 1, + 0, + 0, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/lib/punto_pagos_rails/transaction_service.rb": [ + 1, + 1, + 1, + 1, + null, + 1, + 1, + null, + 1, + 0, + null, + null, + 1, + 0, + 0, + null, + null, + 0, + 0, + 0, + null, + null, + 0, + 0, + null, + null, + null, + 1, + null, + 1, + 0, + 0, + null, + 0, + null, + null, + 0, + 0, + 0, + null, + null, + 0, + null, + null, + 1, + 0, + null, + null, + 1, + 1, + 0, + 0, + 0, + null, + 0, + 0, + 0, + null, + 0, + 0, + null, + null, + null, + 1, + 0, + 0, + 0, + 0, + null, + 0, + 0, + null, + 0, + null, + null, + null, + 1, + null, + 1, + 0, + 0, + 0, + 0, + null, + null, + 0, + null, + null, + 1, + 0, + null, + 0, + 0, + null, + null, + 0, + null, + null, + 1, + 0, + 0, + 0, + 0, + null, + null, + 1, + 0, + 0, + 0, + null, + null, + 1, + 0, + 0, + 0, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/environments/test.rb": [ + 1, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/assets.rb": [ + null, + null, + null, + 1, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/backtrace_silencers.rb": [ + null, + null, + null, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/cookies_serializer.rb": [ + null, + null, + 1 + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/filter_parameter_logging.rb": [ + null, + null, + null, + 1 + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/inflections.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/mime_types.rb": [ + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/session_store.rb": [ + null, + null, + 1 + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/initializers/wrap_parameters.rb": [ + null, + null, + null, + null, + null, + null, + 1, + 1, + null, + null, + null, + null, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/config/routes.rb": [ + 1, + null, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + null, + 1, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/config/routes.rb": [ + 1, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/dummy/app/helpers/application_helper.rb": [ + 1, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/factories/tickets.rb": [ + 1, + 1, + 1, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/spec/factories/transaction.rb": [ + 1, + 1, + 1, + 1, + null, + null + ], + "/Users/gmq/Documents/Trabajo/Platanus/punto_pagos_rails/app/models/punto_pagos_rails/transaction.rb": [ + 1, + null, + 1, + 1, + 1, + null, + 1, + null, + 1, + null, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + null, + 1, + 0, + 0, + null, + null, + 1, + 0, + null, + null, + 1, + 0, + 0, + null, + null, + null + ] }, - "timestamp": 1489764955 + "timestamp": 1489765941 } } diff --git a/spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb b/spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb deleted file mode 100644 index 6dd5e4e..0000000 --- a/spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb +++ /dev/null @@ -1,180 +0,0 @@ -require "rails_helper" - -include PuntoPagosRails - -RSpec.describe TransactionService do - let(:ticket) { Ticket.create amount: 22 } - let(:service) { TransactionService.new(ticket) } - let(:request) { double } - let(:response) { double } - let(:token) { "XXXXX" } - let(:payment_process_url) { double } - let(:notification) { double } - let(:status) { double } - let(:transaction) do - PuntoPagosRails::Transaction.create(payable: ticket, token: SecureRandom.base64) - end - - before do - allow(PuntoPagos::Request).to receive(:new).and_return(request) - allow(request).to receive(:create).and_return(response) - allow(response).to receive(:success?).and_return(false) - end - - describe "#create" do - it "creates transaction" do - expect { service.create }.to change { ticket.reload.transactions.size }.by(1) - end - - context "success" do - before do - allow(response).to receive(:success?).and_return(true) - end - - context "with succesful initialization" do - before do - allow(response).to receive(:get_token).and_return(token) - allow(response).to receive(:payment_process_url).and_return(payment_process_url) - end - - it "returns true" do - expect(service.create).to eq(true) - end - - it "has the correct token" do - service.create - expect(ticket.transactions.last.token).to eq(token) - end - - it "returns payment process url" do - service.create - expect(service.process_url).to eq(payment_process_url) - end - end - - context "with unsuccesful initialization" do - it "returns false with invalid token" do - allow(response).to receive(:get_token).and_return(nil) - expect(service.create).to eq(false) - end - - it "fails with repeated token" do - Transaction.create(token: "REPEATED_TOKEN") - allow(response).to receive(:get_token).and_return("REPEATED_TOKEN") - expect(service.create).to eq(false) - end - end - end - - context "error" do - it "returns false" do - expect(service.create).to eq(false) - end - - it "sets payable error" do - allow(Ticket).to receive(:find).with(ticket.id).and_return(ticket) - service.create - expect(ticket.errors[:base]).to include( - I18n.t("punto_pagos_rails.errors.invalid_puntopagos_response")) - end - end - end - - describe "#xxx_by_token" do - it "returns payable (ticket) by token" do - payable = TransactionService.ticket_by_token(token: transaction.token) - expect(payable.class).to eq(Ticket) - expect(payable.id).to eq(ticket.id) - expect(payable.errors).to be_empty - end - end - - describe "#failed_xxx_by_token" do - it "returns payable (ticket) by token with loaded error" do - payable = TransactionService.failed_ticket_by_token(token: transaction.token) - expect(payable.class).to eq(Ticket) - expect(payable.id).to eq(ticket.id) - expect(payable.errors.messages[:base]).not_to be_empty - end - end - - describe "#notificate" do - let(:params) { { token: transaction.token } } - before { allow(PuntoPagos::Notification).to receive(:new).and_return(notification) } - - context "with valid notification" do - before { allow(notification).to receive(:valid?).with({}, params).and_return(true) } - - it "completes transaction" do - expect(TransactionService.notificate(params, {})).to eq( - respuesta: "99", token: transaction.token) - expect(transaction.reload.state).to eq("completed") - end - - context "when notification is completed" do - before { transaction.update_column(:state, "completed") } - - it "does not change status" do - TransactionService.notificate(params, {}) - expect(transaction.reload.state).to eq("completed") - end - end - - context "when notification is rejected" do - before { transaction.update_column(:state, "rejected") } - - it "does not change status" do - TransactionService.notificate(params, {}) - expect(transaction.reload.state).to eq("rejected") - end - end - end - - context "with invalid notification" do - before do - params[:error] = "error!" - allow(notification).to receive(:valid?).with({}, params).and_return(false) - end - - it "rejects the transaction" do - expect(TransactionService.notificate(params, {})).to eq( - respuesta: "00", error: params[:error], token: transaction.token) - expect(transaction.reload.state).to eq("rejected") - expect(transaction.error).to eq(params[:error]) - end - end - end - - describe "#complete" do - let(:params) { { token: transaction.token } } - before do - allow(PuntoPagos::Status).to receive(:new).and_return(status) - allow(status).to receive(:check).with( - transaction.token, transaction.id.to_s, transaction.amount_to_s).and_return(true) - end - - context "with valid status" do - before { allow(status).to receive(:valid?).and_return(true) } - - it "completes transaction" do - expect(TransactionService.complete(params)).to be_truthy - expect(transaction.reload.state).to eq("completed") - expect(ticket.reload.payment_state).to eq("completed") - end - end - - context "with invalid status" do - before do - allow(status).to receive(:valid?).and_return(false) - allow(status).to receive(:error).and_return("error") - end - - it "completes transaction" do - expect(TransactionService.complete(params)).to be_truthy - expect(transaction.reload.state).to eq("rejected") - expect(transaction.error).to eq("error") - expect(ticket.reload.payment_state).to eq("rejected") - end - end - end -end