Add tests for #51

This commit is contained in:
Tom Naessens 2019-05-31 14:01:43 +12:00
parent 923c1ab286
commit 26d31b926a
2 changed files with 56 additions and 1 deletions

View file

@ -1,5 +1,56 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe RequestsController, type: :controller do RSpec.describe RequestsController, type: :controller do
describe "accepting request" do
let(:request) { create(:request, amount: 10) }
context "a request" do
it "can be accepted by the debtor" do
debtor_balance = request.debtor.balance
creditor_balance = request.creditor.balance
sign_in request.debtor
post :confirm, params: { request_id: request.id }
request.reload
expect(request.status).to eq("confirmed")
expect(debtor_balance - 10).to eq(request.debtor.balance)
expect(creditor_balance + 10).to eq(request.creditor.balance)
end
it "can not be accepted by the creditor" do
debtor_balance = request.debtor.balance
creditor_balance = request.creditor.balance
sign_in request.creditor
post :confirm, params: { request_id: request.id }
request.reload
expect(request.status).to eq("open")
expect(debtor_balance).to eq(request.debtor.balance)
expect(creditor_balance).to eq(request.creditor.balance)
end
it "can not be accepted by the issuer" do
debtor_balance = request.debtor.balance
creditor_balance = request.creditor.balance
sign_in request.issuer
post :confirm, params: { request_id: request.id }
request.reload
expect(request.status).to eq("open")
expect(debtor_balance).to eq(request.debtor.balance)
expect(creditor_balance).to eq(request.creditor.balance)
end
end
end end
end

View file

@ -16,7 +16,11 @@
FactoryBot.define do FactoryBot.define do
factory :request do factory :request do
status { :open }
association :issuer, factory: :user, name: 'Issuer'
association :debtor, factory: :user, name: 'Debtor'
association :creditor, factory: :user, name: 'Creditor'
amount { 5 }
end end
end end