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

wiremock-mapper

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wiremock-mapper

DSL for setting up WireMock mappings.

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53
increased by89.29%
Maintainers
0
Weekly downloads
 
Created
Source

Node.js CI Code Climate Test Coverage npm version

wiremock-mapper

DSL for setting up WireMock mappings

Installation

npm install wiremock-mapper

Configuring

import { Configuration } from 'wiremock-mapper';

Configuration.wireMockBaseUrl = 'http://localhost:8080/some_path_prefix'; // default is 'http://localhost:8080'

Creating a global mapping

Global mappings are a way to predefine part o

import { Configuration } from 'wiremock-mapper';

Configration.createGlobalMapping((request, response) => {});

Reset global mapping

import { Configration } from 'wiremock-mapper';

Configration.reset();

Create a mapping

Import the library

import { WireMockMapper } from 'wiremock-mapper';

Mappings are created with WireMockMapper.createMapping() which takes a function argument defining the mock behavior. It asyncronously sends the configuration to the WireMock server.

await WireMockMapper.createMapping((req, res) => {});

Define matching parameters

All request modifiers are set from req provided by createMapping, and return an instance of RequestBuilder, MatchBuilder, or UrlMatchBuilder. These can be chained together to form a complete request expectation.

It should read like a sentence when set up properly.

await WireMockMapper.createMapping((req, res) => {
  req.isAGet.withUrlPath.matching('/my/.*/path');
});
Interfaces

RequestBuilder

MethodArgument(s)EffectReturns
isAGetnonesets request method to GETRequestBuilder
isAPostnonesets request method to POSTRequestBuilder
isAPutnonesets request method to PUTRequestBuilder
isADeletenonesets request method to DELETERequestBuilder
isAHeadnonesets request method to HEADRequestBuilder
isAnOptionsnonesets request method to OPTIONSRequestBuilder
isATracenonesets request method to TRACERequestBuilder
isAnyVerbnonesets request method to ANYRequestBuilder
withBodynonesets request bodyRequestBuilder
withBasicAuthusername: string, password: stringsets basic authRequestBuilder
withUrlnonesets expected URLUrlMatchBuilder
withUrlPathnonesets URL path match to urlPathPatternUrlMatchBuilder
withCookiekey: stringsets request cookieMatchBuilder
withHeaderkey: stringsets request headerMatchBuilder
withQueryParamkey: stringsets request query parameterMatchBuilder

UrlMatchBuilder

MethodArgumentsEffectReturns
equalTourl: stringMatches text givenRequestBuilder
matchingregexp: stringMatches with regular expressionRequestBuilder

MatchBuilder

MethodArgument(s)Returns
absentnoneRequestBuilder
containingvalue: stringRequestBuilder
equalTovalue: stringRequestBuilder
equalToJsonjson: any, ignoreArrayOrder: boolean, ignoreExtraElements: booleanRequestBuilder
equalToXmlxml: stringRequestBuilder
macthingvalue: stringRequestBuilder
matchingJsonPathpath: stringRequestBuilder
matchingXPathxpath: stringRequestBuilder
notMatchingvalue: stringRequestBuilder

Define response behavior

Responses are created from res provided by WireMockMapper.createMapping()

await WireMockMapper.createMapping((req, res) => {
  res
    .withJsonBody({
      someKey: 'theValue',
      otherKey: 'otherValue'
    })
    .withStatus(200)
    .withStatusMessage('ok');
});
Interface

ResponseBuilder

MethodArgument(s)Returns
withBodyvalue: stringResponseBuilder
withDelaymilliseconds: numberResponseBuilder
withHeaderkey: stringResponseBuilder
withJsonBodyvalue: objectResponseBuilder
withStatusstatusCode: objectResponseBuilder
withStatusMessagestatusMessage: stringResponseBuilder
withTransformertransformerName: stringResponseBuilder

Example

await WireMockMapper.createMapping((req, res) => {
  req.isAGet.withUrlPath.equalTo('/my/api/path');
  res
    .withJsonBody({
      someKey: 'theValue',
      otherKey: 'otherValue'
    })
    .withStatus(200)
    .withStatusMessage('ok');
});

Get Requests Received

Get all requests

await WireMockMapper.getRequests();

Get all requests for a given stub id

await WireMockMapper.getRequests({ stubId: 'some_stub_id' });

The interface for the returned object can be found here.

Keywords

FAQs

Package last updated on 11 Oct 2024

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