🚀 مُصادَق: تحديث وتطوير النظام 2026-05-03 13:49
This commit is contained in:
@@ -23,9 +23,9 @@ final class HmacTest extends TestCase
|
|||||||
$timestamp = (string)time();
|
$timestamp = (string)time();
|
||||||
$payload = json_encode(['foo' => 'bar']);
|
$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
|
public function test_it_rejects_tampered_payload(): void
|
||||||
@@ -35,10 +35,10 @@ final class HmacTest extends TestCase
|
|||||||
$timestamp = (string)time();
|
$timestamp = (string)time();
|
||||||
$payload = json_encode(['foo' => 'bar']);
|
$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']);
|
$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
|
public function test_it_validates_standard_invoice(): void
|
||||||
{
|
{
|
||||||
$data = [
|
$invoice = [
|
||||||
'invoice_type' => '001', // Standard
|
'invoice_number' => 'INV-001',
|
||||||
'total_tax_exclusive_amount' => 100,
|
'invoice_date' => date('Y-m-d'),
|
||||||
'total_tax_amount' => 16,
|
'subtotal' => 100,
|
||||||
'grand_total' => 116,
|
'discount_total' => 0,
|
||||||
'tax_items' => [
|
'grand_total' => 116
|
||||||
['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100]
|
];
|
||||||
]
|
$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']);
|
$this->assertTrue($result['is_valid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_detects_mismatching_totals(): void
|
public function test_it_detects_mismatching_totals(): void
|
||||||
{
|
{
|
||||||
$data = [
|
$invoice = [
|
||||||
'invoice_type' => '001',
|
'invoice_number' => 'INV-002',
|
||||||
'total_tax_exclusive_amount' => 100,
|
'invoice_date' => date('Y-m-d'),
|
||||||
'total_tax_amount' => 16,
|
'subtotal' => 100,
|
||||||
'grand_total' => 110, // Error: should be 116
|
'discount_total' => 0,
|
||||||
'tax_items' => [
|
'grand_total' => 110 // Mismatch
|
||||||
['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100]
|
];
|
||||||
]
|
$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->assertFalse($result['is_valid']);
|
||||||
$this->assertContains('Grand total mismatch', $result['errors']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user