Skip to content

Postman collection testing the Petfinder.com API. Uses GitHub Actions, Newman, and Newman Reporter.

Notifications You must be signed in to change notification settings

StephanieJF/petfinder-api-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RESTful API testing with CI using GitHub Actions

A Postman collection created to test the Petfinder.com RESTful API.

This project was created to practice using the Postman GUI for API testing and authentication methods, as well as exporting and automating the collection to run with the Newman CLI, and generating HTML reports of test outcomes via the Newman Reporter in a continuous integration fashion with GitHub Actions.

Overview

Project Highlights:

  • Authentication using OAuth 2.0
  • Automated continuous integration (CI) set to run the test collection with Newman any time an update is made to the main repository branch via GitHub Actions
  • Generates an HTML report of the test outcomes at runtime and exports the report to a folder called Artifacts

Links:

Test Details

Base Url: https://api.petfinder.com/v2

Authentication

Get token

POST /oauth2/token

Steps

  1. Send a request for an access token, passing in encrypted variables for client_id and client_secret
  2. Capture the access token from the response body and store in an encrypted variable to be included in the header to authorize subsequent requests

Expected Results

  • Returned successful status code of 200
Happy Path API Requests

Get all animals

Returns one "page" of animals (default of 20 animals per page)

GET /animals

Expected Results

  • Returns successful status code of 200
  • Response time is less than 2 seconds
  • Returns one page with the default number of animals (20)
  • Returns a JSON object containing an "animals" array of objects

Get animals by location

Accepts a string query parameter for location and returns animals within the default 100 mile proximity

GET /animals?location={city, state}
GET /animals?location={postal_code}

Expected Results

  • Accepts a string parameter
  • Returns successful status code of 200
  • Response time is less than 2 seconds
  • Animals returned have distance property value less than the default 100 miles

Get animals by distance

Accepts an integer query parameter for distance in miles and returns animals within the specified proximity of the set location

GET /animals?location={postal_code}&distance={miles}

Expected Results

  • Accepts an integer, max: 500
  • Returns successful status code of 200
  • Response time is less than 2 seconds
  • Animal objects returned have distance property values less than miles parameter requested

Get all animal types

Returns an array with every animal type

GET /types

Expected Results

  • Returns successful status code of 200
  • Response time is less than 2 seconds
  • Response includes every animal type in the database

Get animal by ID

Returns details on a specific animal based on an integer ID

GET /animals/{id}

Expected Results

  • Accepts an integer
  • Only succeeds if there is an ID match in the database
  • Returns successful status code of 200
  • Response time is less than 2 seconds
  • Response contains an object
  • Animal returned has an ID that matches the ID sent in the request
Sad Path API Requests

Invalid token passed to /animals

Attempts to make a request with an invalid token

GET /animals
header: 'Authorization: Bearer abc123'

Expected Results

  • Returns status code of 401 Unauthorized
  • Returns message with "Access token invalid or expired"

Invalid token passed to /types

Attempts to make a request with an invalid token

GET /types
header: 'Authorization: Bearer abc---123'

Expected Results

  • Returns status code of 401 Unauthorized
  • Returns message with "Access token invalid or expired"

Missing token

Attempts to make a request without a token

GET /animals

Expected Results

  • Returns status code of 401 Unauthorized
  • Returns message with "Access token invalid or expired"

Incorrect authorization type

Attempts to make a request using Basic Auth and passing a Username and Password

GET /animals

Expected Results

  • Returns status code of 401 Unauthorized
  • Returns message with "Access token invalid or expired"

Invalid endpoint /animal

Attempts to make a request to an invalid endpoint

GET /animal

Expected Results

  • Returns status code of 404
  • Returns status title "Not Found"
  • Response detail contains "No route found"

Invalid endpoint /animals/types

Attempts to make a request to an invalid endpoint

GET /animals/types

Expected Results

  • Returns status code of 404
  • Returns status title "Not Found"
  • Response detail contains "No route found"

Get animal by ID, with ID as a string

Attempts to request animal by ID, where ID is a string

GET /animals/abcdefg

Expected Results

  • Returns status code of 404
  • Returns status title "Not Found"
  • Returns response detail "Not Found"

Get animal by ID that does not exist

Attempts to request animal by ID, where ID does not exist

GET /animals/11111111

Expected Results

  • Returns status code of 404
  • Returns status title "Not Found"
  • Returns response detail "Not Found"

Get animal by ID containing special characters

Attempts to request animal by ID, where ID contains special characters

GET /animals/65289840!

Expected Results

  • Returns status code of 404
  • Returns status title "Not Found"
  • Returns response detail "Not Found"

Actual Results

  • Returns status code of 200
  • Returns an animal with ID 65289840

Get animals by incomplete location parameter

Attempts to request animals by city without including the state parameter

GET /animals?location=denver

Expected Results

  • Returns status code of 400 bad request
  • Returns response detail "The request contains invalid parameters."
  • Returns error type "ERR-00002"
  • Response with invalid-params array indicating an error in the "query"
  • Response with invalid-params array indicating an error in the parameter named, "location"
  • Response with invalid-params array indicating a parameter error reason of "Could not determine location."

Get animals by state parameter with special characters

Attempts to request animals by state with special characters

GET /animals?location=washington*

Expected Results

  • Returns status code of 400 bad request
  • Returns response detail "The request contains invalid parameters."
  • Returns error type "ERR-00002"
  • Response with invalid-params array indicating an error in the "query"
  • Response with invalid-params array indicating an error in the parameter named, "location"
  • Response with invalid-params array indicating a parameter error reason of "Could not determine location."

Get animals by postal code parameter with special characters

Attempts to request animals by postal code with special characters

GET /animals?location=34787!

Expected Results

  • Returns status code of 400 bad request
  • Returns response detail "The request contains invalid parameters."
  • Returns error type "ERR-00002"
  • Response with invalid-params array indicating an error in the "query"
  • Response with invalid-params array indicating an error in the parameter named, "location"
  • Response with invalid-params array indicating a parameter error reason of "Could not determine location."

Get animals by distance miles, with distance as a string

Attempts to request animals by distance from a location in miles, where distance is a string

GET /animals?location=34787&distance=twenty

Expected Results

  • Returns status code of 400 bad request
  • Returns response detail "The request contains invalid parameters."
  • Returns error type "ERR-00002"
  • Response with invalid-params array indicating an error in the "query"
  • Response with invalid-params array indicating an error in the parameter named, "distance"
  • Response with invalid-params array indicating a parameter error reason of "This value should be a valid number."

About

Postman collection testing the Petfinder.com API. Uses GitHub Actions, Newman, and Newman Reporter.

Resources

Stars

Watchers

Forks