You are here

public function ApiRequestTest::testZoomApiConnection in Zoom API 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/ApiRequestTest.php \Drupal\Tests\zoomapi\Functional\ApiRequestTest::testZoomApiConnection()

Will fail, but that's ok.

File

tests/src/Functional/ApiRequestTest.php, line 57

Class

ApiRequestTest
API request tests.

Namespace

Drupal\Tests\zoomapi\Functional

Code

public function testZoomApiConnection() {

  // Create test keys.
  // Api Key.
  $this
    ->createTestKey('test_zoomapi_key', 'authentication', 'config');

  // API Secret.
  $this
    ->createTestKey('test_zoomapi_secret', 'authentication', 'config');

  // Update Zoomapi config.
  $this
    ->drupalGet(Url::fromRoute('zoomapi.settings'));
  $edit = [
    'base_uri' => 'https://api.zoom.us/v2',
    'api_key' => 'test_zoomapi_key',
    'api_secret' => 'test_zoomapi_secret',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save configuration');

  // Post to the webhook controller.
  $client = \Drupal::service('zoomapi.client');
  try {
    $client
      ->request('GET', '/users');
  } catch (RequestException $exception) {

    // We are expecting failure.
    $message = $exception
      ->getMessage();
    $this
      ->assertStringContainsString('401 Unauthorized', $message, '401 Unauthorized was returned.');
    $this
      ->assertStringContainsString('Client error', $message, 'Asserting client error exists.');
  }
}