Skip to content

Commit

Permalink
test(feature): ensure flow calculations are shown
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed May 25, 2024
1 parent ba4f381 commit 3dd3aa8
Showing 1 changed file with 86 additions and 37 deletions.
123 changes: 86 additions & 37 deletions t/Feature/Resource/FrozenPeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Models\CashFlowCategoryModel;
use App\Models\CurrencyModel;
use App\Models\FinancialEntryModel;
use App\Models\FlowCalculationModel;
use App\Models\FrozenPeriodModel;
use App\Models\ModifierModel;
use App\Models\SummaryCalculationModel;
Expand All @@ -31,6 +32,15 @@ public function testDefaultIndex()
$currency = $currency_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id
])->create();
$cash_flow_category_fabricator = new Fabricator(CashFlowCategoryModel::class);
$liquid_cash_flow_category = $cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id,
"kind" => LIQUID_CASH_FLOW_CATEGORY_KIND
])->create();
$illiquid_cash_flow_category = $cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id,
"kind" => ILLIQUID_CASH_FLOW_CATEGORY_KIND
])->create();
$account_fabricator = new Fabricator(AccountModel::class);
$asset_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
Expand All @@ -43,7 +53,9 @@ public function testDefaultIndex()
$modifier_fabricator = new Fabricator(ModifierModel::class);
$modifier = $modifier_fabricator->setOverrides([
"debit_account_id" => $asset_account->id,
"credit_account_id" => $equity_account->id
"credit_account_id" => $equity_account->id,
"debit_cash_flow_category_id" => $liquid_cash_flow_category->id,
"credit_cash_flow_category_id" => $illiquid_cash_flow_category->id
])->create();
$financial_entry_fabricator = new Fabricator(FinancialEntryModel::class);
$financial_entry_fabricator->setOverrides([
Expand Down Expand Up @@ -74,39 +86,51 @@ public function testDefaultShow()
$currency = $currency_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id
])->create();
$cash_flow_category_fabricator = new Fabricator(CashFlowCategoryModel::class);
$cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id
]);
$liquid_cash_flow_category = $cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id,
"kind" => LIQUID_CASH_FLOW_CATEGORY_KIND
])->create();
$illiquid_cash_flow_category = $cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id,
"kind" => ILLIQUID_CASH_FLOW_CATEGORY_KIND
])->create();
$account_fabricator = new Fabricator(AccountModel::class);
$equity_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
"increase_cash_flow_category_id"=> null,
"decrease_cash_flow_category_id"=> null,
"kind" => EQUITY_ACCOUNT_KIND
])->create();
$asset_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
"increase_cash_flow_category_id"=> null,
"decrease_cash_flow_category_id"=> null,
"kind" => ASSET_ACCOUNT_KIND
])->create();
$expense_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
"increase_cash_flow_category_id"=> null,
"decrease_cash_flow_category_id"=> null,
"kind" => EXPENSE_ACCOUNT_KIND
])->create();
$modifier_fabricator = new Fabricator(ModifierModel::class);
$normal_record_modifier = $modifier_fabricator->setOverrides([
"debit_account_id" => $asset_account->id,
"credit_account_id" => $equity_account->id,
"debit_cash_flow_category_id" => $liquid_cash_flow_category->id,
"credit_cash_flow_category_id" => $illiquid_cash_flow_category->id,
"action" => RECORD_MODIFIER_ACTION
])->create();
$expense_record_modifier = $modifier_fabricator->setOverrides([
"debit_account_id" => $expense_account->id,
"credit_account_id" => $asset_account->id,
"debit_cash_flow_category_id" => $illiquid_cash_flow_category->id,
"credit_cash_flow_category_id" => $liquid_cash_flow_category->id,
"action" => RECORD_MODIFIER_ACTION
])->create();
$close_modifier = $modifier_fabricator->setOverrides([
"debit_account_id" => $equity_account->id,
"credit_account_id" => $expense_account->id,
"debit_cash_flow_category_id" => $illiquid_cash_flow_category->id,
"credit_cash_flow_category_id" => $illiquid_cash_flow_category->id,
"action" => CLOSE_MODIFIER_ACTION
])->create();
$financial_entry_fabricator = new Fabricator(FinancialEntryModel::class);
Expand Down Expand Up @@ -169,6 +193,21 @@ public function testDefaultShow()
"closed_debit_amount" => "0",
"closed_credit_amount" => "0"
])->create();
$flow_calculation_fabricator = new Fabricator(FlowCalculationModel::class);
$asset_flow_calculation = $flow_calculation_fabricator->setOverrides([
"frozen_period_id" => $frozen_period->id,
"cash_flow_category_id" => $liquid_cash_flow_category->id,
"account_id" => $asset_account->id,
"net_amount" => $recorded_normal_financial_entry
->debit_amount
->minus($recorded_expense_financial_entry->credit_amount)
])->create();
$equity_flow_calculation = $flow_calculation_fabricator->setOverrides([
"frozen_period_id" => $frozen_period->id,
"cash_flow_category_id" => $illiquid_cash_flow_category->id,
"account_id" => $equity_account->id,
"net_amount" => $recorded_normal_financial_entry->credit_amount
])->create();

$result = $authenticated_info
->getRequest()
Expand Down Expand Up @@ -200,8 +239,20 @@ public function testDefaultShow()
],
"cash_flow_statement" => [
"opened_liquid_amount" => "0",
"closed_liquid_amount" => "0",
"subtotals" => []
"closed_liquid_amount" => $recorded_normal_financial_entry
->debit_amount
->minus($closed_financial_entry->credit_amount),
"subtotals" => [
[
"cash_flow_category_id" => $illiquid_cash_flow_category->id,
"net_income" => $recorded_normal_financial_entry
->debit_amount
->negated(),
"subtotal" => $recorded_normal_financial_entry
->debit_amount
->minus($closed_financial_entry->credit_amount)
]
]
],
"adjusted_trial_balance" => [
"debit_total" => $recorded_normal_financial_entry
Expand All @@ -222,16 +273,23 @@ public function testDefaultShow()
])),
"currencies" => [ $currency ],
"frozen_period" => json_decode(json_encode($frozen_period)),
"cash_flow_categories" => [],
"cash_flow_categories" => json_decode(json_encode([
$liquid_cash_flow_category,
$illiquid_cash_flow_category,
])),
"summary_calculations" => json_decode(json_encode([
$equity_summary_calculation,
$asset_summary_calculation,
$expense_summary_calculation
])),
"flow_calculations" => json_decode(json_encode([
$equity_flow_calculation,
$asset_flow_calculation,
])),
]);
}

public function testFlowedShow()
public function testUnflowedShow()
{
$authenticated_info = $this->makeAuthenticatedInfo();

Expand All @@ -240,26 +298,28 @@ public function testFlowedShow()
"user_id" => $authenticated_info->getUser()->id
])->create();
$cash_flow_category_fabricator = new Fabricator(CashFlowCategoryModel::class);
$cash_flow_category = $cash_flow_category_fabricator->setOverrides([
$cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id
]);
$liquid_cash_flow_category = $cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id,
"kind" => LIQUID_CASH_FLOW_CATEGORY_KIND
])->create();
$illiquid_cash_flow_category = $cash_flow_category_fabricator->setOverrides([
"user_id" => $authenticated_info->getUser()->id,
"kind" => ILLIQUID_CASH_FLOW_CATEGORY_KIND
])->create();
$account_fabricator = new Fabricator(AccountModel::class);
$equity_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
"increase_cash_flow_category_id" => $cash_flow_category->id,
"decrease_cash_flow_category_id" => $cash_flow_category->id,
"kind" => EQUITY_ACCOUNT_KIND
])->create();
$asset_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
"increase_cash_flow_category_id" => null,
"decrease_cash_flow_category_id" => null,
"kind" => ASSET_ACCOUNT_KIND
])->create();
$expense_account = $account_fabricator->setOverrides([
"currency_id" => $currency->id,
"increase_cash_flow_category_id" => $cash_flow_category->id,
"decrease_cash_flow_category_id" => $cash_flow_category->id,
"kind" => EXPENSE_ACCOUNT_KIND
])->create();
$modifier_fabricator = new Fabricator(ModifierModel::class);
Expand Down Expand Up @@ -319,8 +379,10 @@ public function testFlowedShow()
"account_id" => $asset_account->id,
"opened_debit_amount" => "0",
"opened_credit_amount" => "0",
"unadjusted_debit_amount" => $recorded_normal_financial_entry->debit_amount,
"unadjusted_credit_amount" => $recorded_expense_financial_entry->credit_amount,
"unadjusted_debit_amount" => $recorded_normal_financial_entry
->debit_amount
->minus($recorded_expense_financial_entry->credit_amount),
"unadjusted_credit_amount" => "0",
"closed_debit_amount" => $recorded_normal_financial_entry
->debit_amount
->minus($recorded_expense_financial_entry->credit_amount),
Expand Down Expand Up @@ -367,20 +429,8 @@ public function testFlowedShow()
],
"cash_flow_statement" => [
"opened_liquid_amount" => "0",
"closed_liquid_amount" => $recorded_normal_financial_entry
->credit_amount
->minus($closed_financial_entry->debit_amount),
"subtotals" => [
[
"cash_flow_category_id" => $cash_flow_category->id,
"net_income" => $recorded_expense_financial_entry
->debit_amount
->negated(),
"subtotal" => $recorded_normal_financial_entry
->credit_amount
->minus($closed_financial_entry->debit_amount)
]
]
"closed_liquid_amount" => "0",
"subtotals" => []
],
"adjusted_trial_balance" => [
"debit_total" => $recorded_normal_financial_entry
Expand All @@ -401,14 +451,13 @@ public function testFlowedShow()
])),
"currencies" => [ $currency ],
"frozen_period" => json_decode(json_encode($frozen_period)),
"cash_flow_categories" => [
$cash_flow_category
],
"cash_flow_categories" => [],
"summary_calculations" => json_decode(json_encode([
$equity_summary_calculation,
$asset_summary_calculation,
$expense_summary_calculation
])),
"flow_calculations" => [],
]);
}

Expand Down

0 comments on commit 3dd3aa8

Please sign in to comment.