# Creating an HTTP Test

When creating a test function, use the `@test`annotation. This will execute when the functional tests run. The test method should contain a description of what the test is attempting to verify and should be in snake case to make it more readable in the terminal.

### Function Test Naming Convention:

Tests should be in snake case for readability when the test's name is rendered to the CI. The test name should follow this format:

> {% code overflow="wrap" %}
>
> ```
> [module_name]_[controller_name]_[http_method]_[controller method]_returns_[status code]
> ```
>
> {% endcode %}

{% hint style="success" %}
For example, testing the RotationScheduleController with the method index should be called: `clinical_rotations_get_index_returns_200`
{% endhint %}

{% hint style="success" %}
In instances where the controller has the same name as the module, then the word controller can be used instead of the controller name: `clinical_controller_get_index_returns_200`

This is to avoid \`Clinical\` twice in the name
{% endhint %}

**Example:**

```php
/**
 * Test that the GET /events returns 200
 *
 * @test
 * @return void
 */
public function events_get_method_index_returns_200(): void
{
    // ...
}
```

{% hint style="info" %}
The method's name has all the information to determine what and how it’s being tested.
{% endhint %}

To call an endpoint, we need to state what user is requesting the call before we send the request.

```php
/**
 * Test that the GET /events returns 200
 *
 * @test
 * @return void
 */
public function events_get_method_index_returns_200(): void
{
    $this->actingAs(User::find(2));
}
```

{% hint style="info" %}
If the acted-on user has an ID of 1 (default administrator), then `$this->actingAsAdmin()` can be used instead
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.elentra.org/api/automated-testing/functional-tests/testing-http-verbs/creating-an-http-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
