Giter Site home page Giter Site logo

full-rest-api-test's Introduction

Full-rest-api-test

Overview

This service tests the JSONPlaceholder API, including the following endpoints:

  • GET /posts
  • GET /posts/{Id}
  • GET /posts/1/comments
  • GET /comments?postId={Id}
  • GET /posts?userId={Id}
  • POST /posts
  • PUT /posts/{Id}
  • PATCH /posts/{Id}
  • DELETE /posts/{Id}

Observations of the JSONPlaceholder API during testing:

  • The DELETE /posts/{Id} returns 200 and not 204, which deviates from REST principles as a DELETE endpoint returns no content in the response body.
  • Test data provided to the POST, PUT and PATCH endpoints are not persisted.
  • There is no validation implemented in the backend as it accepts data that deviates from the expected request payload schema and also that the user is unable to carry out testing endpoint validation (i.e. invalid request payload).
  • There is no version number in the URL of the API

Test service

The daigram below shows an architectural overview of the test service. Test framework architecture

The adapters are developed to reduce code duplication The config includes the rool URL of the API being tested. Log is used for stack trace purposes. The test service makes use of the adapters and contains logic that tests JSONPlaceholder API endpoints.

Below is the folder structure of the service:

.
├── .circleci
├── mochawesome-report
├── test
	├── adapters
		├── .
	├── config
		├── .
	├── testdata
		├── .
	├── run.js
	├── testdata.js
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── Makefile
├── package.json
├── README.md                    # readme file
└── ...

Requirements

  • Node.js
  • npm

Installation

Install node.js and npm from the below link:

https://nodejs.org/en/download

Create dependency package

$ npm init

Install dependencies in a terminal

$ npm install supertest --save

$ npm install chai --save

$ npm install mocha --save

$ npm install body-parser --save

$ npm install mocha-junit-reporter --save

$ npm install mocha-html-reporter --save

$ npm install logger --save

$ npm install fs --save

$ npm install convert-csv-to-json --save

Install dependencies using the makefile (alternative installation of dependencies)

Ensure that you're in the root of the service

$ cd full-rest-api-test

$ make deps

Run the API tests

$ npm test

$ mocha test/run.js --reporter mochawesome

$ mocha testdata - run data driven tests

Run the tests from the Makefile

$ make all

To view the test report, run the following command: $ open mochawesome-report/mochawesome.html

Run the API tests inside a docker container

$ docker-compose build && docker-compose up

$ docker-compose logs - To see the results in the last ran docker container

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.