Comstack PM REST API - Behat

Travis CI

This module (Comstack Private Message) is integrated with Travis CI which runs Behat tests each time a commit is pushed to the Github mirror repo. This also runs tests for the REST API submodule. In order to effectively test the REST API custom steps have been defined to facilitate this. Here are some links!

Behat steps

"Given I have the payload…"

Send data to an endpoint on a POST or PUT request.

When constructing your JSON data object you'll start and end things with three double quotes as per the following POST example.

Given I have the payload:
"""
{
  "recipients": [123],
  "text": "Blah blah"
}
"""
When I request "POST /api/v1/cs-pm/conversations"
Then The REST API returns a 201 response

"When I request…"

Kick off a REST request, the first part of step is the HTTP method (GET, POST, PUT, DELETE) followed by the path starting with a /.

When I request "GET /api/v1/cs-pm/conversations"

"Then The REST API returns…"

Checks the HTTP status code returned from the endpoint, this step should not be confused with the standard Behat Then I should get a 200 HTTP response. Note there aren't any quote marks around the response code number.

Then The REST API returns a 200 response

"Then The response data has X items…"

Check that the request has responded with a number of results in the data property in the response body.

Then The response data has 5 items
Then The REST API returns a 200 response
and The response data has 5 items

"Given scope into the…"

Change "scope" into a property, this affects any steps which are noted as uses scope.

When I request "GET /api/v1/cs-pm/conversations"
Then The REST API returns a 200 response
and scope into the "data" property

"Given scope into the first…"

Change "scope" into the first property of a name, this affects any steps which are noted as uses scope.

When I request "GET /api/v1/cs-pm/conversations"
Then The REST API returns a 200 response
and scope into the first "data" property

"The property exists…"

Uses scope

Check that a property exists within the current scope.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "id" property exists

"The properties exist…"

Uses scope

Check that a list of properties exist within the current scope.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
  and the properties exist:
    """
    id
    participants
    historical_participants
    started_by
    last_updated_by
    started
    updated
    messages_count
    unread_count
    """

"The property equals…"

Uses scope

Check that a property within the current scope has a specified value.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "id" property exists
and the "id" property equals 1

"The property is an array…"

Uses scope

Check that a property within the current scope is an array.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "participants" property exists
and the "participants" property is an array

"The property is an empty array…"

Uses scope

Check that a property within the current scope is an empty array.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "participants" property exists
and the "participants" property is an empty array

"The property is an object…"

Uses scope

Check that a property within the current scope is an object.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "started_by" property exists
and the "started_by" property is an object

"The property is a integer…"

Uses scope

Check that a property within the current scope is a integer.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "id" property exists
and the "id" property is a integer

"The property is a integer equalling…"

Uses scope

Check that a property within the current scope is a integer.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "messages_count" property exists
and the "messages_count" property is a integer equalling "1"

"The property is a string…"

Uses scope

Check that a property within the current scope is a string.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "title" property exists
and the "title" property is a string

"The property is a string equalling…"

Uses scope

Check that a property within the current scope is a string and that it matches a value.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "title" property exists
and the "title" property is a string equalling "hi"

"The property is a boolean…"

Uses scope

Check that a property within the current scope is a boolean.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "pinned" property exists
and the "pinned" property is a boolean

"The property is a boolean equalling…"

Uses scope

Check that a property within the current scope is a boolean.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "pinned" property exists
and the "pinned" property is a boolean equalling "true"

"Reset scope…"

Uses scope

Reset the scope to the root of the response body.

When I request "GET /api/v1/cs-pm/conversations/1"
Then The REST API returns a 200 response
and scope into the "data" property
and the "pinned" property exists
and I reset scope