API testing example using the supertest Node.js library

In this integration test example, we hit the GET /projects (https://circleci.com/docs/api/v1-reference/#projects) endpoint in CircleCI. Here is the code testing this endpoint:

'use strict';const request = require('supertest');const assert = require('assert');const CIRCLECI_API = {    // List of all the projects you're following on CircleCI, with build information organized by branch    getProjects: 'https://circleci.com/api/v1.1'};describe('Testing CircleCI API Endpoints', function() {    it('the /projects endpoints should return 200 with a body', function() {        return request(CIRCLECI_API.getProjects)           .get(`/projects?circle-token=${process.env.CIRCLECI_API_TOKEN_GITHUB}`)            .set('Accept', 'application/json' ...

Get Hands-On Continuous Integration and Delivery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.