Merge pull request #53 from ZeusWPI/tests/51/add-confirm-request-tests

Add tests for #51
This commit is contained in:
redfast00 2019-05-31 17:07:37 +02:00 committed by GitHub
commit 91e9ae2379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View file

@ -1,5 +1,56 @@
require 'rails_helper'
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

View file

@ -16,7 +16,11 @@
FactoryBot.define 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