Skip to content

Commit

Permalink
test(feature): handle errors properly
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Aug 26, 2023
1 parent fe989b7 commit a73c0b2
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions t/Feature/Resource/FrozenPeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature\Resource;

use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\I18n\Time;
use CodeIgniter\Test\Fabricator;

Expand Down Expand Up @@ -124,21 +125,21 @@ public function testDefaultShow()
"adjusted_credit_amount" => $recorded_normal_financial_entry
->credit_amount
->minus($closed_financial_entry->debit_amount)
]);
])->create();
$asset_summary_calculation = $summary_calculation_fabricator->setOverrides([
"account_id" => $asset_account->id,
"unadjusted_debit_amount" => $recorded_normal_financial_entry->debit_amount,
"unadjusted_credit_amount" => $recorded_expense_financial_entry->credit_amount,
"adjusted_debit_amount" => $recorded_normal_financial_entry->debit_amount,
"adjusted_credit_amount" => $recorded_expense_financial_entry->credit_amount
]);
$expenses_summary_calculation = $summary_calculation_fabricator->setOverrides([
])->create();
$expense_summary_calculation = $summary_calculation_fabricator->setOverrides([
"account_id" => $expense_account->id,
"unadjusted_debit_amount" => $recorded_expense_financial_entry->debit_amount,
"unadjusted_credit_amount" => "0",
"adjusted_debit_amount" => "0",
"adjusted_credit_amount" => "0"
]);
])->create();

$result = $authenticated_info
->getRequest()
Expand Down Expand Up @@ -294,12 +295,17 @@ public function testDefaultUpdate()
])->create();
$new_details = $frozen_period_fabricator->make();

$result = $authenticated_info
->getRequest()
->withBodyFormat("json")
->put("/api/v1/frozen_periods/$frozen_period->id", [
"frozen_period" => $new_details->toArray()
]);
try {
$result = $authenticated_info
->getRequest()
->withBodyFormat("json")
->put("/api/v1/frozen_periods/$frozen_period->id", [
"frozen_period" => $new_details->toArray()
]);
$result->assertTrue(false);
} catch(PageNotFoundException $error) {
$result->assertTrue(true);
}

$result->assertStatus(404);
}
Expand Down Expand Up @@ -336,11 +342,14 @@ public function testDefaultDelete()
"user_id" => $authenticated_info->getUser()->id
])->create();

$result = $authenticated_info
->getRequest()
->delete("/api/v1/frozen_periods/$financial_entry->id");

$result->assertStatus(404);
try {
$result = $authenticated_info
->getRequest()
->delete("/api/v1/frozen_periods/$financial_entry->id");
$result->assertTrue(false);
} catch(PageNotFoundException $error) {
$result->assertTrue(true);
}
}

public function testDefaultRestore()
Expand Down Expand Up @@ -376,11 +385,14 @@ public function testDefaultRestore()
])->create();
model(FrozenPeriodModel::class)->delete($frozen_period->id);

$result = $authenticated_info
->getRequest()
->patch("/api/v1/frozen_periods/$financial_entry->id");

$result->assertStatus(404);
try {
$result = $authenticated_info
->getRequest()
->patch("/api/v1/frozen_periods/$financial_entry->id");
$result->assertTrue(false);
} catch(PageNotFoundException $error) {
$result->assertTrue(true);
}
}

public function testDefaultForceDelete()
Expand Down

0 comments on commit a73c0b2

Please sign in to comment.