🚀 مُصادَق: تحديث وتطوير النظام 2026-05-03 13:49
This commit is contained in:
@@ -23,9 +23,9 @@ final class HmacTest extends TestCase
|
||||
$timestamp = (string)time();
|
||||
$payload = json_encode(['foo' => 'bar']);
|
||||
|
||||
$signature = $this->service->sign($payload, $secret, $nonce, $timestamp);
|
||||
$signature = $this->service->sign($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $payload);
|
||||
|
||||
$this->assertTrue($this->service->verify($payload, $signature, $secret, $nonce, $timestamp));
|
||||
$this->assertTrue($this->service->verify($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $payload, $signature));
|
||||
}
|
||||
|
||||
public function test_it_rejects_tampered_payload(): void
|
||||
@@ -35,10 +35,10 @@ final class HmacTest extends TestCase
|
||||
$timestamp = (string)time();
|
||||
$payload = json_encode(['foo' => 'bar']);
|
||||
|
||||
$signature = $this->service->sign($payload, $secret, $nonce, $timestamp);
|
||||
$signature = $this->service->sign($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $payload);
|
||||
|
||||
$tamperedPayload = json_encode(['foo' => 'baz']);
|
||||
|
||||
$this->assertFalse($this->service->verify($tamperedPayload, $signature, $secret, $nonce, $timestamp));
|
||||
$this->assertFalse($this->service->verify($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $tamperedPayload, $signature));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,34 +18,35 @@ final class TaxValidationTest extends TestCase
|
||||
|
||||
public function test_it_validates_standard_invoice(): void
|
||||
{
|
||||
$data = [
|
||||
'invoice_type' => '001', // Standard
|
||||
'total_tax_exclusive_amount' => 100,
|
||||
'total_tax_amount' => 16,
|
||||
'grand_total' => 116,
|
||||
'tax_items' => [
|
||||
['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100]
|
||||
]
|
||||
$invoice = [
|
||||
'invoice_number' => 'INV-001',
|
||||
'invoice_date' => date('Y-m-d'),
|
||||
'subtotal' => 100,
|
||||
'discount_total' => 0,
|
||||
'grand_total' => 116
|
||||
];
|
||||
$lines = [
|
||||
['line_number' => 1, 'quantity' => 1, 'unit_price' => 100, 'tax_rate' => 0.16, 'tax_amount' => 16, 'line_total' => 116]
|
||||
];
|
||||
|
||||
$result = $this->service->validate($data);
|
||||
$result = $this->service->validate($invoice, $lines);
|
||||
$this->assertTrue($result['is_valid']);
|
||||
}
|
||||
|
||||
public function test_it_detects_mismatching_totals(): void
|
||||
{
|
||||
$data = [
|
||||
'invoice_type' => '001',
|
||||
'total_tax_exclusive_amount' => 100,
|
||||
'total_tax_amount' => 16,
|
||||
'grand_total' => 110, // Error: should be 116
|
||||
'tax_items' => [
|
||||
['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100]
|
||||
]
|
||||
$invoice = [
|
||||
'invoice_number' => 'INV-002',
|
||||
'invoice_date' => date('Y-m-d'),
|
||||
'subtotal' => 100,
|
||||
'discount_total' => 0,
|
||||
'grand_total' => 110 // Mismatch
|
||||
];
|
||||
$lines = [
|
||||
['line_number' => 1, 'quantity' => 1, 'unit_price' => 100, 'tax_rate' => 0.16, 'tax_amount' => 16, 'line_total' => 116]
|
||||
];
|
||||
|
||||
$result = $this->service->validate($data);
|
||||
$result = $this->service->validate($invoice, $lines);
|
||||
$this->assertFalse($result['is_valid']);
|
||||
$this->assertContains('Grand total mismatch', $result['errors']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user