1. Timothy Corbett-Clark
  2. rest-api-blueprint

Source

rest-api-blueprint / restapiblueprint / features / add_person.feature

Feature: Add a person
  As an API client
  I want to be able to create a new person

  Background: Set server URL and reset database
    Given I am using server "http://localhost:5000/v1"
    And I set Accept header to "application/json"
    When I send a DELETE request to "people"
    Then the response status should be "200"

  Scenario: Add a new person, declare json, but don't send anything
    Given I set Content-Type header to "application/json"
    When I send a PUT request to "people/fred"
    Then the response status should be "400"

  Scenario: Add a new person, declare json, but send invalid json
    Given I set Content-Type header to "application/json"
    When I send a PUT request to "people/fred"
      """
      {"email": "forgot the end quote}
      """
    Then the response status should be "400"

  Scenario: Add a person but with non-JSON Content-Type
    Given I set Content-Type header to "application/xml"
    When I send a PUT request to "people/tim"
      """
      <something></something>
      """
    Then the response status should be "406"

  Scenario: Add a person with data of unspecified Content-Type
    When I send a PUT request to "people/tim"
      """
      some unspecified format (no Content-Type set)
      """
    Then the response status should be "406"

  Scenario: Add a new person
    When I send a PUT request to "people/fred"
    Then the response status should be "200"
    And the JSON should be:
      """
      {"status": "ok"}
      """
    When I send a GET request to "people/fred"
    Then the response status should be "200"

  Scenario: Add new person with no email address
    When I send a PUT request to "people/fred"
    Then the response status should be "200"
    When I send a GET request to "people/fred"
    Then the response status should be "200"
    And the JSON at path "result.email" should be null

  Scenario: Add new person with invalid email address
    Given I set Content-Type header to "application/json"
    When I send a PUT request to "people/fred":
      """
      {"email": "not-a-valid-email-address"}
      """
    Then the response status should be "400"
    And the JSON at path "message" should be "Invalid partial specification for a person"

  Scenario: Add new person with valid email address
    Given I set Content-Type header to "application/json"
    When I send a PUT request to "people/fred":
      """
      {"email": "a@b.c"}
      """
    Then the response status should be "200"
    When I send a GET request to "people/fred"
    Then the response status should be "200"
    And the JSON at path "result.email" should be "a@b.c"

  Scenario: Add the same person twice
    When I send a PUT request to "people/fred"
    And I send a PUT request to "people/fred"
    Then the response status should be "200"
    And the JSON at path "status" should be "ok"

  Scenario: Add a new person but with a list not a dict
    Given I set Content-Type header to "application/json"
    When I send a PUT request to "people/fred"
      """
      []
      """
    Then the JSON at path "message" should be "Invalid partial specification for a person"
    And the response status should be "400"