From 0ea2b7d9efa8f0a4158adac1cfef11ac0fd3a879 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Fri, 10 Jul 2026 16:51:34 +0500 Subject: [PATCH] test(vikon): add ViconApiConfig unit tests - token returns value from DB - apiUrl returns value from DB - apiUrl falls back to constant when not in payload - token throws RuntimeException when not configured - token throws when payload is empty - inactive credential is ignored --- tests/Feature/Vicon/ViconApiConfigTest.php | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/Feature/Vicon/ViconApiConfigTest.php diff --git a/tests/Feature/Vicon/ViconApiConfigTest.php b/tests/Feature/Vicon/ViconApiConfigTest.php new file mode 100644 index 0000000..6fb4c45 --- /dev/null +++ b/tests/Feature/Vicon/ViconApiConfigTest.php @@ -0,0 +1,89 @@ + 'vikon_api', + 'payload' => $payload, + 'is_active' => $active, + ]); + } + + public function test_token_returns_value_from_db(): void + { + $this->createCredential(['token' => 'test-jwt-token-123', 'api_url' => 'https://api.example.com']); + + $config = app(ViconApiConfig::class); + + $this->assertEquals('test-jwt-token-123', $config->token()); + } + + public function test_api_url_returns_value_from_db(): void + { + $this->createCredential(['token' => 'tok', 'api_url' => 'https://custom.api.com/v2']); + + $config = app(ViconApiConfig::class); + + $this->assertEquals('https://custom.api.com/v2', $config->apiUrl()); + } + + public function test_api_url_falls_back_when_not_in_payload(): void + { + $this->createCredential(['token' => 'tok']); + + $config = app(ViconApiConfig::class); + + $this->assertEquals('https://db-nica.ru/api/v1', $config->apiUrl()); + } + + public function test_token_throws_when_not_configured(): void + { + $config = app(ViconApiConfig::class); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('VIKON API token not configured'); + + $config->token(); + } + + public function test_token_throws_when_payload_empty(): void + { + $this->createCredential(['token' => '', 'api_url' => 'https://api.example.com']); + + $config = app(ViconApiConfig::class); + + $this->expectException(\RuntimeException::class); + + $config->token(); + } + + public function test_inactive_credential_is_ignored(): void + { + $this->createCredential(['token' => 'inactive-tok', 'api_url' => 'https://api.example.com'], active: false); + + $config = app(ViconApiConfig::class); + + $this->expectException(\RuntimeException::class); + + $config->token(); + } +}