-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from ZeusWPI/tests/51/add-confirm-request-tests
Add tests for #51
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters