Skip to content

Cicero API Integration

Kendall Trudick edited this page Oct 25, 2023 · 4 revisions

Overview

The representatives.test.js file contains tests for the /api/representatives/:zipCode endpoint of an Express.js application. The tests use the Jest testing framework and Supertest library to simulate HTTP requests and responses. The tests mock the Axios library to simulate requests to the Cicero API, which returns data about elected representatives based on a zip code.

Test Breakdown

The first test checks that the API returns a 200 status code and a single representative object in the response when a valid zip code is provided. The test mocks the Axios library to return a pre-defined response from the Cicero API.

The second test is similar to the first, but it uses the full zip code instead of just the first five digits.

The third test checks that the API returns a 400 status code and an error message in the response when an invalid zip code is provided. The test sets an invalid zip code and expects the API to return an error message that includes the invalid zip code.

The fourth test is commented out, but it would check that the API returns a 500 status code and an error message in the response when the Cicero API is down or not responding to requests from the application server.

Clone this wiki locally