-
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.
- Loading branch information
Showing
15 changed files
with
190 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Bill::DirectReceipts::Create do | ||
it "creates direct receipt" do | ||
response = ApiClient.exec(DirectReceipts::Create, transaction: { | ||
user_id: UserFactory.create.id, | ||
description: "New receipt", | ||
amount: 90 | ||
}) | ||
|
||
# ameba:disable Performance/AnyInsteadOfEmpty | ||
TransactionQuery.new.any?.should be_true | ||
response.status.should eq(HTTP::Status::FOUND) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Bill::DirectReceipts::Edit do | ||
it "renders edit page" do | ||
user = UserFactory.create | ||
transaction = TransactionFactory.create &.user_id(user.id) | ||
|
||
response = ApiClient.exec(DirectReceipts::Edit.with( | ||
transaction_id: transaction.id | ||
)) | ||
|
||
response.body.should eq("DirectReceipts::EditPage") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Bill::DirectReceipts::New do | ||
it "renders new page" do | ||
response = ApiClient.exec(DirectReceipts::New) | ||
|
||
response.body.should eq("DirectReceipts::NewPage") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "../../../spec_helper" | ||
|
||
describe Bill::DirectReceipts::Update do | ||
it "updates direct receipt" do | ||
new_description = "Another receipt" | ||
|
||
user = UserFactory.create | ||
|
||
transaction = TransactionFactory.create &.user_id(user.id) | ||
.description("New receipt") | ||
.status(:draft) | ||
|
||
response = ApiClient.exec( | ||
DirectReceipts::Update.with(transaction_id: transaction.id), | ||
transaction: {description: new_description} | ||
) | ||
|
||
transaction.reload.description.should eq(new_description) | ||
response.status.should eq(HTTP::Status::FOUND) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class DirectReceipts::Create < BrowserAction | ||
include Bill::DirectReceipts::Create | ||
|
||
post "/direct-receipts" do | ||
run_operation | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class DirectReceipts::Edit < BrowserAction | ||
include Bill::DirectReceipts::Edit | ||
|
||
get "/direct-receipts/:transaction_id/edit" do | ||
operation = UpdateDirectReceipt.new(transaction) | ||
html EditPage, operation: operation | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class DirectReceipts::New < BrowserAction | ||
include Bill::DirectReceipts::New | ||
|
||
get "/direct-receipts/new" do | ||
operation = ReceiveDirectPayment.new | ||
html NewPage, operation: operation | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class DirectReceipts::Update < BrowserAction | ||
include Bill::DirectReceipts::Update | ||
|
||
patch "/direct-receipts/:transaction_id" do | ||
run_operation | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
struct DirectReceipts::EditPage < MainLayout | ||
needs operation : UpdateDirectReceipt | ||
|
||
def content | ||
text "DirectReceipts::EditPage" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
struct DirectReceipts::NewPage < MainLayout | ||
needs operation : ReceiveDirectPayment | ||
|
||
def content | ||
text "DirectReceipts::NewPage" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Bill::DirectReceipts::Create | ||
macro included | ||
# post "/receipts" do | ||
# run_operation | ||
# end | ||
|
||
def run_operation | ||
ReceiveDirectPayment.create(params) do |operation, transaction| | ||
if operation.saved? | ||
do_run_operation_succeeded(operation, transaction.not_nil!) | ||
else | ||
response.status_code = 400 | ||
do_run_operation_failed(operation) | ||
end | ||
end | ||
end | ||
|
||
def do_run_operation_succeeded(operation, transaction) | ||
flash.success = Rex.t(:"action.receipt.create.success") | ||
redirect to: Transactions::Show.with(transaction_id: transaction.id) | ||
end | ||
|
||
def do_run_operation_failed(operation) | ||
flash.failure = Rex.t(:"action.receipt.create.failure") | ||
html NewPage, operation: operation | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Bill::DirectReceipts::Edit | ||
macro included | ||
# get "/receipts/:transaction_id/edit" do | ||
# operation = UpdateDirectReceipt.new(transaction) | ||
# html EditPage, operation: operation | ||
# end | ||
|
||
getter transaction : Transaction do | ||
TransactionQuery.find(transaction_id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Bill::DirectReceipts::New | ||
macro included | ||
# get "/receipts/new" do | ||
# operation = ReceiveDirectPayment.new | ||
# html NewPage, operation: operation | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Bill::DirectReceipts::Update | ||
macro included | ||
# patch "/receipts/:transaction_id" do | ||
# run_operation | ||
# end | ||
|
||
def run_operation | ||
UpdateDirectReceipt.update( | ||
transaction, | ||
params | ||
) do |operation, updated_transaction| | ||
if operation.saved? | ||
do_run_operation_succeeded(operation, updated_transaction) | ||
else | ||
response.status_code = 400 | ||
do_run_operation_failed(operation) | ||
end | ||
end | ||
end | ||
|
||
getter transaction : Transaction do | ||
TransactionQuery.find(transaction_id) | ||
end | ||
|
||
def do_run_operation_succeeded(operation, transaction) | ||
flash.success = Rex.t(:"action.receipt.update.success") | ||
redirect to: Transactions::Show.with(transaction_id: transaction.id) | ||
end | ||
|
||
def do_run_operation_failed(operation) | ||
flash.failure = Rex.t(:"action.receipt.update.failure") | ||
html EditPage, operation: operation | ||
end | ||
end | ||
end |