Elentra API
  • Introduction
  • Developers
    • Getting Started
    • Quickstart Guide
      • Set up Repositories
      • Validate the setup
      • Exploring the API
      • Creating a new Module
      • Setup Routing
      • Introduction to Postman
      • Create a Controller
      • Using Eloquent Models
      • Input Validation
      • API Resource Authorization
  • Elentra API Standards
    • HTTP Methods & Status Codes
    • Routing & Parameters
      • Example Routing Patterns with HTTP Method
        • /courses/{course}/contacts
        • /courses/{course}/contacts?type={contact_type}
        • /courses/{course}/contacts/{contact}
        • /courses/{course}/syllabus
      • Common Mistakes
        • [GET] /admissions/file-review/file/rubric-score/{cycle_id}/{pool_id}/{subpool_id}
        • [DELETE] /notices/1,2,3
        • [GET] /cbe/curriculum/framework/{framework_id}/hierarchy-by-depth
        • [GET] /admissions/file-review/file/rubric-score/delete/{id}
        • [GET] /portfolio/entries/{entry_id}/get-file
        • [POST] /cbe/curriculum/updateframework
  • Automated Testing
    • Getting Started
      • Setting up a testing environment
      • Running Automated Tests
    • Seed Data
      • Folder Structure
      • Creating Seed Data
    • Functional Tests
      • Creating a Functional Test File
      • Testing HTTP Verbs
        • Creating an HTTP Test
        • GET Requests
        • POST / PUT / DELETE Requests
        • GraphQL Requests
      • Asserting API Response
      • Annotations
    • Code Style Linting
Powered by GitBook
On this page
  1. Automated Testing
  2. Functional Tests
  3. Testing HTTP Verbs

POST / PUT / DELETE Requests

PreviousGET RequestsNextGraphQL Requests

Last updated 2 years ago

POST / PUT / DELETE Requests

When calling a POST / PUT / DELETE method, three pieces of information are required:

  1. The URL (This could also contain the query parameters)

  2. The authentication token

  3. The payload

POST, PUT and DELETE requests modify the original seed data that might affect other tests. Use to restore the data to the original state before the test was executed.

These requirements also apply to PATCH requests.

POST Example:

/**
 * Test that the route /user/role returns 201
 *
 * @transaction auth
 * @test
 * @return void
 */
public function user_post_method_user_role_returns_201(): void
{
  $this->actingAsAdmin()
       ->authenticate()
       ->post('/user/role', [
          'organisation_id' => '1',
          'access_id' => '1',
       ]);
}
  1. The URL in this example is /user/role

  2. authenticate() authenticates the token

  3. The third piece of information is the payload.

PUT Example:

$this->actingAsAdmin()
     ->authenticate()
     ->put('/user/mobilenumber', [
          "number" => "1555".rand(100000,999999)
     ])
  1. The URL in this example is /user/mobilenumber

  2. authenticate() authenticates the token

  3. The third piece of information is the payload.

DELETE Example:

$this->actingAsAdmin()
     ->authenticate()
     ->delete('/courses/1', []);
  1. The URL in this example is /courses/1

  2. authenticate() authenticates the token

  3. The third piece of information is the payload.

Even if there is no data, pass an empty array otherwise the response will be 403 forbidden.

annotations