diff --git a/tests/ConnectorTest.php b/tests/ConnectorTest.php new file mode 100644 index 0000000..515cf7d --- /dev/null +++ b/tests/ConnectorTest.php @@ -0,0 +1,69 @@ +toBeInstanceOf(Connector::class); +}); + +it('sends a request with default headers and authentication', function () { + // Set up a mock client with a mock response + $mockClient = new MockClient([ + MockResponse::make(['status' => 'success'], 200, [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'apikey' => 'test-api-key', + ]), + ]); + + // Configuration with specific headers + $configuration = new Configuration( + base: 'https://kong-admin.com', + uri: 'api', + apiKey: 'test-api-key', + keyName: 'apikey', + headers: [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ] + ); + + // Initialize Connector with MockClient + $connector = new Connector($configuration); + $connector->withMockClient($mockClient); + + // Create and send the test request using Connector + $request = new TestRequest; + $response = $connector->send($request); + + expect($response->headers()->get('Content-Type'))->toBe('application/json') + ->and($response->headers()->get('Accept'))->toBe('application/json') + ->and($response->headers()->get('apikey'))->toBe('test-api-key') + ->and($response->status())->toBe(200) + ->and($response->json())->toBe(['status' => 'success']); +});