940afe9319
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m23s
API CI/CD / Build frontend assets (push) Successful in 2m18s
API CI/CD / Security audit (push) Successful in 31s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\V1\FullSurface;
|
|
|
|
use Tests\Feature\Api\V1\FullSurface\Support\FullSurfaceE2EContractCase;
|
|
|
|
class ApiBatch13DiscountVoucherScholarshipAbuseContractTest extends FullSurfaceE2EContractCase
|
|
{
|
|
public function test_discount_and_voucher_routes_reject_abusive_amounts_and_scope_overrides(): void
|
|
{
|
|
$routes = $this->apiRoutesContainingAny(['discount', 'voucher', 'scholarship', 'fee', 'tuition', 'waiver']);
|
|
|
|
foreach ($routes as $route) {
|
|
$method = $this->primaryMethod($route);
|
|
if (! in_array($method, ['POST', 'PUT', 'PATCH'], true)) {
|
|
continue;
|
|
}
|
|
|
|
$payload = $this->payloadFor($method, $route->uri()) + [
|
|
'voucher_id' => $this->ids['voucherId'],
|
|
'discount_type' => 'percent',
|
|
'percentage' => 1000,
|
|
'amount' => -9999.99,
|
|
'applies_to_all' => true,
|
|
'family_id' => 99999999,
|
|
'student_id' => 99999999,
|
|
'approved_by' => $this->parent->id,
|
|
];
|
|
|
|
$response = $this->requestAs($this->admin, $method, $route->uri(), $payload);
|
|
$this->assertControlled($response, $method, $route->uri());
|
|
$this->assertStringNotContainsString('SQLSTATE', $response->getContent());
|
|
}
|
|
}
|
|
|
|
public function test_parent_cannot_self_grant_discounts_or_scholarships(): void
|
|
{
|
|
$routes = $this->apiRoutesContainingAny(['discount', 'voucher', 'scholarship', 'waiver']);
|
|
|
|
foreach ($routes as $route) {
|
|
$method = $this->primaryMethod($route);
|
|
if (! in_array($method, ['POST', 'PUT', 'PATCH', 'DELETE'], true)) {
|
|
continue;
|
|
}
|
|
|
|
$response = $this->requestAs($this->parent, $method, $route->uri(), [
|
|
'student_id' => $this->ids['studentId'],
|
|
'amount' => 9999,
|
|
'percentage' => 100,
|
|
'approved' => true,
|
|
'reason' => 'self-granted',
|
|
]);
|
|
|
|
$this->assertControlled($response, $method, $route->uri());
|
|
$this->assertNotContains(
|
|
$response->getStatusCode(),
|
|
[200, 201],
|
|
sprintf('%s %s unexpectedly allowed parent discount mutation.', $method, $route->uri())
|
|
);
|
|
}
|
|
}
|
|
}
|