1 line
6.6 KiB
JSON
1 line
6.6 KiB
JSON
{"repo": "aryawiratama26/saveit-website", "files": {"tests/Unit/Services/DeepseekServiceTest.php": {"f9708ef0e90bfd9e437d22c02f2608a14916de27": {"t": 1785745775.9015539, "n": 3094, "h": "d9953e83eb51fad4", "c": "<?php\n\nnamespace Tests\\Unit\\Services;\n\nuse App\\Services\\DeepseekService;\nuse Illuminate\\Support\\Facades\\Config;\nuse Illuminate\\Support\\Facades\\Http;\nuse Tests\\TestCase;\n\nclass DeepseekServiceTest extends TestCase\n{\n public function test_throws_exception_when_api_key_is_missing(): void\n {\n Config::set('services.deepseek.api_key', '');\n\n $service = new DeepseekService();\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('DEEPSEEK_API_KEY belum dikonfigurasi');\n\n $service->parseFinancialDocument('test text');\n }\n\n public function test_parses_valid_response(): void\n {\n Config::set('services.deepseek.api_key', 'test-key');\n Config::set('services.deepseek.api_url', 'https://api.deepseek.com/chat/completions');\n\n Http::fake([\n 'api.deepseek.com/*' => Http::response([\n 'choices' => [[\n 'message' => [\n 'content' => json_encode([\n 'type' => 'expense',\n 'amount' => 150000,\n 'description' => 'Belanja bulanan',\n 'date' => '2026-07-21',\n 'category_suggestion' => 'Belanja',\n ]),\n ],\n ]],\n ], 200),\n ]);\n\n $service = new DeepseekService();\n $result = $service->parseFinancialDocument('Sample OCR text');\n\n $this->assertEquals('expense', $result['type']);\n $this->assertEquals(150000, $result['amount']);\n $this->assertEquals('Belanja bulanan', $result['description']);\n }\n\n public function test_throws_exception_on_api_error(): void\n {\n Config::set('services.deepseek.api_key', 'test-key');\n Config::set('services.deepseek.api_url', 'https://api.deepseek.com/chat/completions');\n\n Http::fake([\n 'api.deepseek.com/*' => Http::response(['error' => 'Unauthorized'], 401),\n ]);\n\n $service = new DeepseekService();\n\n $this->expectException(\\RuntimeException::class);\n\n $service->parseFinancialDocument('Sample text');\n }\n\n public function test_normalizes_negative_amount(): void\n {\n Config::set('services.deepseek.api_key', 'test-key');\n Config::set('services.deepseek.api_url', 'https://api.deepseek.com/chat/completions');\n\n Http::fake([\n 'api.deepseek.com/*' => Http::response([\n 'choices' => [[\n 'message' => [\n 'content' => json_encode([\n 'type' => 'expense',\n 'amount' => -50000,\n 'description' => 'Test',\n 'date' => '2026-07-21',\n ]),\n ],\n ]],\n ], 200),\n ]);\n\n $service = new DeepseekService();\n $result = $service->parseFinancialDocument('test');\n\n $this->assertEquals(50000, $result['amount']);\n }\n}\n"}, "e0daec2ba82231596c05511ccc19331794cf40e9": {"t": 1785756407.8582106, "n": 3094, "h": "d9953e83eb51fad4", "c": "<?php\n\nnamespace Tests\\Unit\\Services;\n\nuse App\\Services\\DeepseekService;\nuse Illuminate\\Support\\Facades\\Config;\nuse Illuminate\\Support\\Facades\\Http;\nuse Tests\\TestCase;\n\nclass DeepseekServiceTest extends TestCase\n{\n public function test_throws_exception_when_api_key_is_missing(): void\n {\n Config::set('services.deepseek.api_key', '');\n\n $service = new DeepseekService();\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('DEEPSEEK_API_KEY belum dikonfigurasi');\n\n $service->parseFinancialDocument('test text');\n }\n\n public function test_parses_valid_response(): void\n {\n Config::set('services.deepseek.api_key', 'test-key');\n Config::set('services.deepseek.api_url', 'https://api.deepseek.com/chat/completions');\n\n Http::fake([\n 'api.deepseek.com/*' => Http::response([\n 'choices' => [[\n 'message' => [\n 'content' => json_encode([\n 'type' => 'expense',\n 'amount' => 150000,\n 'description' => 'Belanja bulanan',\n 'date' => '2026-07-21',\n 'category_suggestion' => 'Belanja',\n ]),\n ],\n ]],\n ], 200),\n ]);\n\n $service = new DeepseekService();\n $result = $service->parseFinancialDocument('Sample OCR text');\n\n $this->assertEquals('expense', $result['type']);\n $this->assertEquals(150000, $result['amount']);\n $this->assertEquals('Belanja bulanan', $result['description']);\n }\n\n public function test_throws_exception_on_api_error(): void\n {\n Config::set('services.deepseek.api_key', 'test-key');\n Config::set('services.deepseek.api_url', 'https://api.deepseek.com/chat/completions');\n\n Http::fake([\n 'api.deepseek.com/*' => Http::response(['error' => 'Unauthorized'], 401),\n ]);\n\n $service = new DeepseekService();\n\n $this->expectException(\\RuntimeException::class);\n\n $service->parseFinancialDocument('Sample text');\n }\n\n public function test_normalizes_negative_amount(): void\n {\n Config::set('services.deepseek.api_key', 'test-key');\n Config::set('services.deepseek.api_url', 'https://api.deepseek.com/chat/completions');\n\n Http::fake([\n 'api.deepseek.com/*' => Http::response([\n 'choices' => [[\n 'message' => [\n 'content' => json_encode([\n 'type' => 'expense',\n 'amount' => -50000,\n 'description' => 'Test',\n 'date' => '2026-07-21',\n ]),\n ],\n ]],\n ], 200),\n ]);\n\n $service = new DeepseekService();\n $result = $service->parseFinancialDocument('test');\n\n $this->assertEquals(50000, $result['amount']);\n }\n}\n"}}}} |