Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

api-server-sim

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-server-sim

Api Server Simulator so you can mock api Rest services easily. Also, find an integrated Spy on api calls and an SMTP Server to catch emails.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

API Server Simulator Node.js CI

This Simulator allows for a Test Automation System to control and observe the universe of a Backend system that depends upon external API services. The two main features are:

  1. Simulate requests and responses for a REST Api server specified as scenarios in Excel files.
  2. Spy on API calls and emails being sent by your backend, so you can verify and use information sent to external systems.
  3. Contract testing
  • Validate simulation scenarios (requests and responses) against a swagger file
  1. Dynamically create API simulations during your tests
  2. Make your test automation aware of external dependencies:
  • Spy on calls made
  • Spy on emails sent

How to use

First, install the library:

Install the required libraries.

npm install api-server-sim

Then, create a JS file containing the next code, named sim.js for example. Here we will configure and start an API server as specified in a list of Excel files located in your NodeJS project.

const ExcelServer = require("api-server-sim");

// Parameters
const files = ['./endpoints.xlsx'];
const port = 3000;
const validations = {
    apiSpec: undefined,
    validateRequests: false,
    validateResponses: false
};
// start the server without validating open api spec
const sim = new ExcelServer({ files, port }, validations);
sim.run();

The endpoints.xlsx file contains the REST API endpoints to run. For example, the Excel can contain a table such as the next one as a "GET Hello World" endpoint:

scenariomethodurlheadersbodyquerystatusresponse
Hello Worldget/hello200{ "message": "Hello World" }-

The headers, body, query and response columns must be valid json objects or paths to a valid json file.

Finally, execute the sim.js file, by running node:

node sim.js

... or creating a script in your package.json and running with NPM:

npm run sim

For Developers: Running the acceptance tests

1. Download this code repository and install the required libraries.

npm install

2. Run the server

npm run start

3. Run the acceptance tests

After running the sample server provided in this library, run the sample Jasmine tests. Every test should pass.

npm test

Authors

License

This project is licensed under the MIT License - see the license.txt file for details.

Contributing

Feel free to report suggestions and issues! Thanks.

FAQs

Package last updated on 04 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc