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

wiremock-mapper

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wiremock-mapper - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.nvmrc

19

CHANGELOG.md

@@ -5,4 +5,4 @@ # Change Log

<a name="0.0.1"></a>
## 0.0.1 (2017-07-30)
<a name="0.0.2"></a>
## 0.0.2 (2017-08-01)

@@ -18,16 +18,1 @@

## 0.0.1 (2017-07-30)
<a name="0.0.1"></a>
## 0.0.1 (2017-07-30)
<a name="0.0.1"></a>
## 0.0.1 (2017-07-30)
<a name="0.0.1"></a>
## 0.0.1 (2017-07-30)
const gulp = require('gulp');
const ts = require('gulp-typescript');
const jasmine = require('gulp-jasmine');
const istanbul = require('gulp-istanbul');
const clean = require('gulp-clean');
const runSequence = require('run-sequence');
const merge = require('merge2');
const tslint = require('gulp-tslint');
gulp.task('build', function() {
const merge = require('merge2');
const tsProject = ts.createProject('tsconfig.json');

@@ -25,7 +27,21 @@

gulp.task('test:run', function() {
return gulp.src('dist/spec/**')
.pipe(jasmine())
gulp.task('lint', function() {
return gulp.src(['lib/**', 'spec/**'])
.pipe(tslint({ formatter: 'stylish' }))
.pipe(tslint.report());
});
gulp.task('pre-test', function () {
return gulp.src(['dist/lib/**/*.ts'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
gulp.task('test:run', ['pre-test'], function() {
return gulp.src('dist/spec/**')
.pipe(jasmine())
.pipe(istanbul.writeReports({ reporters: ['lcov', 'html'] }))
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
});
gulp.task('watch', ['default'], function() {

@@ -36,3 +52,3 @@ gulp.watch('src/*.ts', ['default']);

gulp.task('test', [], function(cb) {
runSequence('clean', 'build', 'test:run', cb);
runSequence('clean', 'lint', 'build', 'test:run', cb);
});

@@ -39,0 +55,0 @@ gulp.task('default', [], function(cb) {

@@ -1,15 +0,13 @@

import { RequestBuilder } from '../../lib/builders/request_builder'
import { RequestBuilder } from "../../lib/builders/request_builder";
export class MatchBuilder {
private matchType: string;
private options: any = {};
private value: string | boolean;
constructor(private readonly requestBuilder: RequestBuilder) {}
private _type: string;
private _value: string | boolean;
private _options: any = {};
public toJSON = () => Object.assign({}, { [this._type]: this._value }, this._options);
public absent(): RequestBuilder {
this._type = 'absent';
this._value = true;
this.matchType = "absent";
this.value = true;
return this.requestBuilder;

@@ -19,4 +17,4 @@ }

public containing(value: string): RequestBuilder {
this._type = 'contains';
this._value = value;
this.matchType = "contains";
this.value = value;
return this.requestBuilder;

@@ -26,4 +24,4 @@ }

public equalTo(value: string): RequestBuilder {
this._type = 'equalTo';
this._value = value;
this.matchType = "equalTo";
this.value = value;
return this.requestBuilder;

@@ -33,11 +31,11 @@ }

public equalToJson(json: any, ignoreArrayOrder: boolean = false, ignoreExtraElements: boolean = false) {
this._type = 'equalToJson';
this._value = json;
this.matchType = "equalToJson";
this.value = json;
if(ignoreArrayOrder) {
this._options['ignoreArrayOrder'] = ignoreArrayOrder;
if (ignoreArrayOrder) {
this.options.ignoreArrayOrder = ignoreArrayOrder;
}
if(ignoreExtraElements) {
this._options['ignoreExtraElements'] = ignoreExtraElements;
if (ignoreExtraElements) {
this.options.ignoreExtraElements = ignoreExtraElements;
}

@@ -49,4 +47,4 @@

public equalToXml(xml: string) {
this._type = 'equalToXml';
this._value = xml;
this.matchType = "equalToXml";
this.value = xml;
return this.requestBuilder;

@@ -56,4 +54,4 @@ }

public matching(value: string) {
this._type = 'matches';
this._value = value;
this.matchType = "matches";
this.value = value;
return this.requestBuilder;

@@ -63,4 +61,4 @@ }

public matchingJsonPath(value: string) {
this._type = 'matchesJsonPath';
this._value = value;
this.matchType = "matchesJsonPath";
this.value = value;
return this.requestBuilder;

@@ -70,4 +68,4 @@ }

public matchingXPath(xpath: string) {
this._type = 'matchesXPath';
this._value = xpath;
this.matchType = "matchesXPath";
this.value = xpath;
return this.requestBuilder;

@@ -77,6 +75,8 @@ }

public notMatching(value: string) {
this._type = 'doesNotMatch';
this._value = value;
this.matchType = "doesNotMatch";
this.value = value;
return this.requestBuilder;
}
public toJSON = () => ({ [this.matchType]: this.value, ...this.options });
}

@@ -1,6 +0,5 @@

import { MatchBuilder } from '../../lib/builders/match_builder'
import { UrlMatchBuilder } from '../../lib/builders/url_match_builder'
import { MatchBuilder } from "../../lib/builders/match_builder";
import { UrlMatchBuilder } from "../../lib/builders/url_match_builder";
export interface RequestBuilder {
isAnyVerb(): RequestBuilder;
isADelete(): RequestBuilder;

@@ -10,6 +9,7 @@ isAGet(): RequestBuilder;

isAnOptions(): RequestBuilder;
isAnyVerb(): RequestBuilder;
isAPost(): RequestBuilder;
isAPut(): RequestBuilder;
isATrace(): RequestBuilder;
withBasicAuth(username: string, password: String): RequestBuilder;
withBasicAuth(username: string, password: string): RequestBuilder;
withBody(): MatchBuilder;

@@ -24,14 +24,14 @@ withCookie(key: string): MatchBuilder;

export class RequestBuilderImpl implements RequestBuilder {
private _options: any = {};
private _urlMatchBuilder: UrlMatchBuilder = new UrlMatchBuilder(this);
protected options: any = {};
protected urlMatchBuilder: UrlMatchBuilder = new UrlMatchBuilder(this);
public toJSON = () => Object.assign({}, this._options, this._urlMatchBuilder.toJSON());
public isAnyVerb() {
this._options['method'] = 'ANY';
return this;
public clone() {
const clone = new RequestBuilderImpl();
clone.options = {...this.options};
clone.urlMatchBuilder = this.urlMatchBuilder;
return clone;
}
public isADelete() {
this._options['method'] = 'DELETE';
this.options.method = "DELETE";
return this;

@@ -41,3 +41,3 @@ }

public isAGet() {
this._options['method'] = 'GET';
this.options.method = "GET";
return this;

@@ -47,3 +47,3 @@ }

public isAHead() {
this._options['method'] = 'HEAD';
this.options.method = "HEAD";
return this;

@@ -53,8 +53,13 @@ }

public isAnOptions() {
this._options['method'] = 'OPTIONS';
this.options.method = "OPTIONS";
return this;
}
public isAnyVerb() {
this.options.method = "ANY";
return this;
}
public isAPost() {
this._options['method'] = 'POST';
this.options.method = "POST";
return this;

@@ -64,3 +69,3 @@ }

public isAPut() {
this._options['method'] = 'PUT';
this.options.method = "PUT";
return this;

@@ -70,8 +75,10 @@ }

public isATrace() {
this._options['method'] = 'TRACE';
this.options.method = "TRACE";
return this;
}
public toJSON = () => ({ ...this.options, ...this.urlMatchBuilder.toJSON() });
public withBasicAuth(username: string, password: string): RequestBuilder {
this._options['basicAuth'] = { 'username': username, 'password': password };
this.options.basicAuth = { username, password };
return this;

@@ -81,7 +88,7 @@ }

public withBody(): MatchBuilder {
if (!this._options['bodyPatterns']) {
this._options['bodyPatterns'] = []
if (!this.options.bodyPatterns) {
this.options.bodyPatterns = [];
}
const matchBuilder = new MatchBuilder(this);
this._options['bodyPatterns'].push(matchBuilder);
this.options.bodyPatterns.push(matchBuilder);
return matchBuilder;

@@ -91,7 +98,7 @@ }

public withCookie(key: string): MatchBuilder {
if (!this._options['cookies']) {
this._options['cookies'] = {}
if (!this.options.cookies) {
this.options.cookies = {};
}
const matchBuilder = new MatchBuilder(this);
this._options['cookies'][key] = matchBuilder;
this.options.cookies[key] = matchBuilder;
return matchBuilder;

@@ -101,7 +108,7 @@ }

public withHeader(key: string): MatchBuilder {
if (!this._options['headers']) {
this._options['headers'] = {}
if (!this.options.headers) {
this.options.headers = {};
}
const matchBuilder = new MatchBuilder(this);
this._options['headers'][key] = matchBuilder;
this.options.headers[key] = matchBuilder;
return matchBuilder;

@@ -111,7 +118,7 @@ }

public withQueryParam(key: string): MatchBuilder {
if (!this._options['queryParameters']) {
this._options['queryParameters'] = {}
if (!this.options.queryParameters) {
this.options.queryParameters = {};
}
const matchBuilder = new MatchBuilder(this);
this._options['queryParameters'][key] = matchBuilder;
this.options.queryParameters[key] = matchBuilder;
return matchBuilder;

@@ -121,10 +128,10 @@ }

public withUrl(): UrlMatchBuilder {
this._urlMatchBuilder = new UrlMatchBuilder(this);
return this._urlMatchBuilder;
this.urlMatchBuilder = new UrlMatchBuilder(this);
return this.urlMatchBuilder;
}
public withUrlPath(): UrlMatchBuilder {
this._urlMatchBuilder = new UrlMatchBuilder(this, true);
return this._urlMatchBuilder;
this.urlMatchBuilder = new UrlMatchBuilder(this, true);
return this.urlMatchBuilder;
}
}

@@ -11,8 +11,14 @@ export interface ResponseBuilder {

export class ResponseBuilderImpl implements ResponseBuilder {
private _jsonObject: any = {};
protected jsonObject: any = {};
public toJSON = () => this._jsonObject;
public clone() {
const clone = new ResponseBuilderImpl();
clone.jsonObject = {...this.jsonObject};
return clone;
}
public toJSON = () => this.jsonObject;
public withBody(value: string): ResponseBuilder {
this._jsonObject['body'] = value;
this.jsonObject.body = value;
return this;

@@ -22,3 +28,3 @@ }

public withDelay(milliseconds: number): ResponseBuilder {
this._jsonObject['fixedDelayMilliseconds'] = milliseconds;
this.jsonObject.fixedDelayMilliseconds = milliseconds;
return this;

@@ -28,6 +34,6 @@ }

public withHeader(key: string, value: string): ResponseBuilder {
if(!this._jsonObject['headers']) {
this._jsonObject['headers'] = {};
if (!this.jsonObject.headers) {
this.jsonObject.headers = {};
}
this._jsonObject['headers'][key] = value;
this.jsonObject.headers[key] = value;
return this;

@@ -37,3 +43,3 @@ }

public withStatus(statusCode: number): ResponseBuilder {
this._jsonObject['status'] = statusCode;
this.jsonObject.status = statusCode;
return this;

@@ -43,3 +49,3 @@ }

public withStatusMessage(statusMessage: string): ResponseBuilder {
this._jsonObject['statusMessage'] = statusMessage;
this.jsonObject.statusMessage = statusMessage;
return this;

@@ -49,5 +55,5 @@ }

public withTransformer(transformerName: string): ResponseBuilder {
this._jsonObject['transformer'] = transformerName;
this.jsonObject.transformer = transformerName;
return this;
}
}

@@ -1,14 +0,12 @@

import { RequestBuilder } from './request_builder';
import { RequestBuilder } from "./request_builder";
export class UrlMatchBuilder {
constructor(private readonly requestBuilder: RequestBuilder, private readonly path: boolean = false) {};
private jsonObject = {};
private _jsonObject = {};
constructor(private readonly requestBuilder: RequestBuilder, private readonly path: boolean = false) {}
public toJSON = () => this._jsonObject;
public equalTo(url: string): RequestBuilder {
let urlType = this.path ? 'urlPath' : 'url';
this._jsonObject = { [urlType]: url };
const urlType = this.path ? "urlPath" : "url";
this.jsonObject = { [urlType]: url };
return this.requestBuilder;

@@ -18,6 +16,8 @@ }

public matching(regexp: string): RequestBuilder {
let urlType = this.path ? 'urlPathPattern' : 'urlPattern';
this._jsonObject = { [urlType]: regexp };
const urlType = this.path ? "urlPathPattern" : "urlPattern";
this.jsonObject = { [urlType]: regexp };
return this.requestBuilder;
}
public toJSON = () => this.jsonObject;
}

@@ -1,17 +0,14 @@

import { WireMockMapping } from './wiremock_mapping';
import { RequestBuilder, RequestBuilderImpl } from './builders/request_builder';
import { ResponseBuilder, ResponseBuilderImpl } from './builders/response_builder';
import { RequestBuilderImpl } from "./builders/request_builder";
import { ResponseBuilderImpl } from "./builders/response_builder";
import { WireMockMapping } from "./wiremock_mapping";
class NotImplementedException extends Error {};
export class Configuration {
public static readonly requestBuilder: RequestBuilder = new RequestBuilderImpl();
public static readonly responseBuilder: ResponseBuilder = new ResponseBuilderImpl();
public static wireMockHost: string = 'localhost';
public static wireMockPort: number = 8080;
public static readonly requestBuilder: RequestBuilderImpl = new RequestBuilderImpl();
public static readonly responseBuilder: ResponseBuilderImpl = new ResponseBuilderImpl();
public static wireMockHost = "localhost";
public static wireMockPort = 8080;
public static createGlobalMapping(wireMockMapping: WireMockMapping) {
wireMockMapping(this.requestBuilder, this.responseBuilder);
throw new NotImplementedException('If you know how to deep clone an object in typescript, submit a pull request and make the pending tests pass.');
}
}

@@ -1,6 +0,4 @@

import { WireMockMapping } from './wiremock_mapping';
import { WireMockService } from './wiremock_service';
// import { Configuration } from './configuration';
import { RequestBuilderImpl } from './builders/request_builder';
import { ResponseBuilderImpl } from './builders/response_builder';
import { Configuration } from "./configuration";
import { WireMockMapping } from "./wiremock_mapping";
import { WireMockService } from "./wiremock_service";

@@ -13,13 +11,10 @@ export class WireMockMapper {

public static createMapping(wireMockMapping: WireMockMapping): Promise<string> {
//TODO: fix global mapping by deep cloning somehow
// const requestBuilder = Configuration.requestBuilder;
// const requestBuilder = Configuration.requestBuilder;
const requestBuilder = new RequestBuilderImpl();
const responseBuilder = new ResponseBuilderImpl();
const requestBuilder = Configuration.requestBuilder.clone();
const responseBuilder = Configuration.responseBuilder.clone();
wireMockMapping(requestBuilder, responseBuilder);
return new Promise<string>((resolve, reject) => {
let response = WireMockService.sendToWireMock({ request: requestBuilder, response: responseBuilder });
const response = WireMockService.sendToWireMock({ request: requestBuilder, response: responseBuilder });
response.then((data) => resolve(JSON.parse(data).id))
.catch((error) => reject(error)) ;
.catch(reject) ;
});

@@ -26,0 +21,0 @@ }

@@ -1,4 +0,4 @@

import { RequestBuilder } from './builders/request_builder';
import { ResponseBuilder } from './builders/response_builder';
import { RequestBuilder } from "./builders/request_builder";
import { ResponseBuilder } from "./builders/response_builder";
export type WireMockMapping = (request: RequestBuilder, response: ResponseBuilder) => void;

@@ -1,9 +0,5 @@

import * as http from 'http';
import { Configuration } from './configuration';
import * as http from "http";
import { Configuration } from "./configuration";
export class WireMockService {
static readonly WIREMOCK_MAPPINGS_PATH = '/__admin/mappings';
static readonly WIREMOCK_CLEAR_MAPPINGS_PATH = '/__admin/mappings/reset';
public static async clearWireMockMappings(): Promise<void> {

@@ -13,16 +9,16 @@ return new Promise<void>((resolve, reject) => {

hostname: Configuration.wireMockHost,
method: 'POST',
method: "POST",
path: this.WIREMOCK_CLEAR_MAPPINGS_PATH,
port: Configuration.wireMockPort,
}, (response) => {
if (response.statusCode != 200) {
reject(new Error("Unexpected Status Code: " + response.statusCode));
}, (response) => {
if (response.statusCode !== 200) {
reject(new Error(`Unexpected Status Code: ${response.statusCode}`));
}
let data = '';
response.on('data', (chunk) => data += chunk);
response.on('end', () => resolve());
let data = "";
response.on("data", (chunk) => data += chunk);
response.on("end", resolve);
});
request.on('error', (error) => reject(error));
request.on("error", reject);
request.end();

@@ -36,13 +32,13 @@ });

hostname: Configuration.wireMockHost,
method: 'DELETE',
path: [this.WIREMOCK_MAPPINGS_PATH, mappingId].join('/'),
method: "DELETE",
path: [this.WIREMOCK_MAPPINGS_PATH, mappingId].join("/"),
port: Configuration.wireMockPort,
}, (response) => {
if (response.statusCode != 200) {
reject(new Error("Unexpected Status Code: " + response.statusCode));
}, (response) => {
if (response.statusCode !== 200) {
reject(new Error(`Unexpected Status Code: ${response.statusCode}`));
}
response.on('end', () => resolve());
response.on("end", resolve);
});
request.on('error', (error) => reject(error));
request.on("error", reject);
request.end();

@@ -52,21 +48,22 @@ });

public static async sendToWireMock(body: any): Promise<string> {
public static async sendToWireMock(body: {}): Promise<string> {
return new Promise<string>((resolve, reject) => {
const request = http.request({
headers: { 'Content-Type': 'application/json' },
headers: { "Content-Type": "application/json" },
hostname: Configuration.wireMockHost,
method: 'POST',
method: "POST",
path: this.WIREMOCK_MAPPINGS_PATH,
port: Configuration.wireMockPort
}, (response) => {
if (response.statusCode != 201) {
reject(new Error("Unexpected Status Code: " + response.statusCode));
port: Configuration.wireMockPort,
}, (response) => {
if (response.statusCode !== 201) {
reject(new Error(`Unexpected Status Code: ${response.statusCode}`));
}
let data = '';
response.on('data', (chunk) => data += chunk);
response.on('end', () => resolve(data));
let data = "";
response.on("data", (chunk) => data += chunk);
response.on("end", () => resolve(data));
});
request.on('error', (error) => reject(error));
request.on("error", reject);
request.write(JSON.stringify(body));

@@ -76,2 +73,5 @@ request.end();

}
private static readonly WIREMOCK_CLEAR_MAPPINGS_PATH = "/__admin/mappings/reset";
private static readonly WIREMOCK_MAPPINGS_PATH = "/__admin/mappings";
}
{
"name": "wiremock-mapper",
"version": "0.0.1",
"version": "0.0.2",
"description": "DSL for setting up WireMock mappings.",

@@ -11,4 +11,6 @@ "main": "dist/index.js",

"scripts": {
"test": "gulp test",
"release": "standard-version"
"coverage": "gulp coverage",
"lint": "gulp lint",
"release": "standard-version",
"test": "gulp test"
},

@@ -32,5 +34,8 @@ "repository": {

"@types/node": "^8.0.17",
"codeclimate-test-reporter": "^0.5.0",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-istanbul": "^1.1.2",
"gulp-jasmine": "^2.4.2",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^3.2.1",

@@ -41,2 +46,3 @@ "jasmine": "^2.6.0",

"run-sequence": "^2.1.0",
"standard-version": "^4.2.0",
"tslint": "^5.5.0",

@@ -43,0 +49,0 @@ "typescript": "^2.4.2"

@@ -0,2 +1,7 @@

[![Build Status](https://travis-ci.org/ike18t/wiremock_mapper_node.png?branch=master)](https://travis-ci.org/ike18t/wiremock_mapper_node)
[![Code Climate](https://codeclimate.com/github/ike18t/wiremock_mapper_node/badges/gpa.svg)](https://codeclimate.com/github/ike18t/wiremock_mapper_node)
[![Test Coverage](https://codeclimate.com/github/ike18t/wiremock_mapper_node/badges/coverage.svg)](https://codeclimate.com/github/ike18t/wiremock_mapper_node/coverage)
[![npm version](https://badge.fury.io/js/wiremock-mapper.svg)](https://badge.fury.io/js/wiremock-mapper)
# wiremock_mapper_node
DSL for setting up WireMock mappings

@@ -1,15 +0,15 @@

import { MatchBuilder } from '../../lib/builders/match_builder'
import { RequestBuilderImpl } from '../../lib/builders/request_builder'
import { MatchBuilder } from "../../lib/builders/match_builder";
import { RequestBuilderImpl } from "../../lib/builders/request_builder";
describe('MatchBuilder', () => {
describe('absent', () => {
it('json stringifies to { absent: true }', () => {
describe("MatchBuilder", () => {
describe("absent", () => {
it("json stringifies to { absent: true }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.absent();
const expectedJSON = JSON.stringify({ 'absent': true });
const expectedJSON = JSON.stringify({ absent: true });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();

@@ -21,153 +21,153 @@ const builder = new MatchBuilder(requestBuilder);

describe('containing', () => {
it('json stringifies to { contains: value }', () => {
describe("containing", () => {
it("json stringifies to { contains: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.containing('foo');
builder.containing("foo");
const expectedJSON = JSON.stringify({ 'contains': 'foo' });
const expectedJSON = JSON.stringify({ contains: "foo" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.containing('')).toEqual(requestBuilder);
expect(builder.containing("")).toEqual(requestBuilder);
});
});
describe('equalTo', () => {
it('json stringifies to { equalTo: value }', () => {
describe("equalTo", () => {
it("json stringifies to { equalTo: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalTo('foo');
builder.equalTo("foo");
const expectedJSON = JSON.stringify({ 'equalTo': 'foo' });
const expectedJSON = JSON.stringify({ equalTo: "foo" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.equalTo('')).toEqual(requestBuilder);
expect(builder.equalTo("")).toEqual(requestBuilder);
});
});
describe('equalToJson', () => {
it('json stringifies to { equalToJson: value }', () => {
describe("equalToJson", () => {
it("json stringifies to { equalToJson: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo');
builder.equalToJson("foo");
const expectedJSON = JSON.stringify({ 'equalToJson': 'foo' });
const expectedJSON = JSON.stringify({ equalToJson: "foo" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('json stringifies to { equalToJson: value, ignoreArrayOrder: true }', () => {
it("json stringifies to { equalToJson: value, ignoreArrayOrder: true }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo', true);
builder.equalToJson("foo", true);
const expectedJSON = JSON.stringify({ 'equalToJson': 'foo', 'ignoreArrayOrder': true });
const expectedJSON = JSON.stringify({ equalToJson: "foo", ignoreArrayOrder: true });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('json stringifies to { equalToJson: value, ignoreExtraElements: true }', () => {
it("json stringifies to { equalToJson: value, ignoreExtraElements: true }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo', false, true);
builder.equalToJson("foo", false, true);
const expectedJSON = JSON.stringify({ 'equalToJson': 'foo', 'ignoreExtraElements': true });
const expectedJSON = JSON.stringify({ equalToJson: "foo", ignoreExtraElements: true });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('json stringifies to { equalToJson: value, ignoreArrayOrder: true, ignoreExtraElements: true }', () => {
it("json stringifies to { equalToJson: value, ignoreArrayOrder: true, ignoreExtraElements: true }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo', true, true);
builder.equalToJson("foo", true, true);
const expectedJSON = JSON.stringify({ 'equalToJson': 'foo', 'ignoreArrayOrder': true, 'ignoreExtraElements': true });
const expectedJSON = JSON.stringify({ equalToJson: "foo", ignoreArrayOrder: true, ignoreExtraElements: true });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.equalToJson('foo')).toEqual(requestBuilder);
expect(builder.equalToJson("foo")).toEqual(requestBuilder);
});
});
describe('equalToXml', () => {
it('json stringifies to { equalToXml: value }', () => {
describe("equalToXml", () => {
it("json stringifies to { equalToXml: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToXml('<foo>bar</foo>');
builder.equalToXml("<foo>bar</foo>");
const expectedJSON = JSON.stringify({ 'equalToXml': '<foo>bar</foo>' });
const expectedJSON = JSON.stringify({ equalToXml: "<foo>bar</foo>" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.equalToXml('')).toEqual(requestBuilder);
expect(builder.equalToXml("")).toEqual(requestBuilder);
});
});
describe('matching', () => {
it('json stringifies to { matches: value }', () => {
describe("matching", () => {
it("json stringifies to { matches: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.matching('hi');
builder.matching("hi");
const expectedJSON = JSON.stringify({ 'matches': 'hi' });
const expectedJSON = JSON.stringify({ matches: "hi" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.matching('')).toEqual(requestBuilder);
expect(builder.matching("")).toEqual(requestBuilder);
});
});
describe('matchingJsonPath', () => {
it('json stringifies to { matchesJsonPath: value }', () => {
describe("matchingJsonPath", () => {
it("json stringifies to { matchesJsonPath: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.matchingJsonPath('hi');
builder.matchingJsonPath("hi");
const expectedJSON = JSON.stringify({ 'matchesJsonPath': 'hi' });
const expectedJSON = JSON.stringify({ matchesJsonPath: "hi" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.matchingJsonPath('')).toEqual(requestBuilder);
expect(builder.matchingJsonPath("")).toEqual(requestBuilder);
});
});
describe('matchingXPath', () => {
it('json stringifies to { matchesXPath: value }', () => {
describe("matchingXPath", () => {
it("json stringifies to { matchesXPath: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.matchingXPath('hi');
builder.matchingXPath("hi");
const expectedJSON = JSON.stringify({ 'matchesXPath': 'hi' });
const expectedJSON = JSON.stringify({ matchesXPath: "hi" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.matchingXPath('')).toEqual(requestBuilder);
expect(builder.matchingXPath("")).toEqual(requestBuilder);
});
});
describe('notMatching', () => {
it('json stringifies to { doesNotMatch: value }', () => {
describe("notMatching", () => {
it("json stringifies to { doesNotMatch: value }", () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.notMatching('hi');
builder.notMatching("hi");
const expectedJSON = JSON.stringify({ 'doesNotMatch': 'hi' });
const expectedJSON = JSON.stringify({ doesNotMatch: "hi" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new MatchBuilder(requestBuilder);
expect(builder.notMatching('')).toEqual(requestBuilder);
expect(builder.notMatching("")).toEqual(requestBuilder);
});
});
});

@@ -1,13 +0,13 @@

import { RequestBuilderImpl } from '../../lib/builders/request_builder'
import { RequestBuilderImpl } from "../../lib/builders/request_builder";
describe('RequestBuilderImpl', () => {
describe('isAnyVerb', () => {
describe("RequestBuilderImpl", () => {
describe("isAnyVerb", () => {
it('should json stringify to { method: "ANY" }', () => {
const builder = new RequestBuilderImpl();
builder.isAnyVerb();
const expectedJSON = JSON.stringify({ method: 'ANY' });
const expectedJSON = JSON.stringify({ method: "ANY" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -18,11 +18,11 @@ expect(builder.isAnyVerb()).toEqual(builder);

describe('isADelete', () => {
describe("isADelete", () => {
it('should json stringify to { method: "DELETE" }', () => {
const builder = new RequestBuilderImpl();
builder.isADelete();
const expectedJSON = JSON.stringify({ method: 'DELETE' });
const expectedJSON = JSON.stringify({ method: "DELETE" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -33,11 +33,11 @@ expect(builder.isADelete()).toEqual(builder);

describe('isAGet', () => {
describe("isAGet", () => {
it('should json stringify to { method: "GET" }', () => {
const builder = new RequestBuilderImpl();
builder.isAGet();
const expectedJSON = JSON.stringify({ method: 'GET' });
const expectedJSON = JSON.stringify({ method: "GET" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -48,11 +48,11 @@ expect(builder.isAGet()).toEqual(builder);

describe('isAHead', () => {
describe("isAHead", () => {
it('should json stringify to { method: "HEAD" }', () => {
const builder = new RequestBuilderImpl();
builder.isAHead();
const expectedJSON = JSON.stringify({ method: 'HEAD' });
const expectedJSON = JSON.stringify({ method: "HEAD" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -63,11 +63,11 @@ expect(builder.isAHead()).toEqual(builder);

describe('isAnOptions', () => {
describe("isAnOptions", () => {
it('should json stringify to { method: "Options" }', () => {
const builder = new RequestBuilderImpl();
builder.isAnOptions();
const expectedJSON = JSON.stringify({ method: 'OPTIONS' });
const expectedJSON = JSON.stringify({ method: "OPTIONS" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -78,11 +78,11 @@ expect(builder.isAnOptions()).toEqual(builder);

describe('isAPost', () => {
describe("isAPost", () => {
it('should json stringify to { method: "POST" }', () => {
const builder = new RequestBuilderImpl();
builder.isAPost();
const expectedJSON = JSON.stringify({ method: 'POST' });
const expectedJSON = JSON.stringify({ method: "POST" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -93,11 +93,11 @@ expect(builder.isAPost()).toEqual(builder);

describe('isAPut', () => {
describe("isAPut", () => {
it('should json stringify to { method: "PUT" }', () => {
const builder = new RequestBuilderImpl();
builder.isAPut();
const expectedJSON = JSON.stringify({ method: 'PUT' });
const expectedJSON = JSON.stringify({ method: "PUT" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -108,11 +108,11 @@ expect(builder.isAPut()).toEqual(builder);

describe('isATrace', () => {
describe("isATrace", () => {
it('should json stringify to { method: "TRACE" }', () => {
const builder = new RequestBuilderImpl();
builder.isATrace();
const expectedJSON = JSON.stringify({ method: 'TRACE' });
const expectedJSON = JSON.stringify({ method: "TRACE" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();

@@ -123,18 +123,18 @@ expect(builder.isATrace()).toEqual(builder);

describe('withBasicAuth', () => {
it('should json stringify to { basicAuth: { username: value, password: value } }', () => {
describe("withBasicAuth", () => {
it("should json stringify to { basicAuth: { username: value, password: value } }", () => {
const builder = new RequestBuilderImpl();
builder.withBasicAuth('ike', '1234');
const expectedJSON = JSON.stringify({ basicAuth: { username: 'ike', password: '1234' } });
builder.withBasicAuth("ike", "1234");
const expectedJSON = JSON.stringify({ basicAuth: { username: "ike", password: "1234" } });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new RequestBuilderImpl();
expect(builder.withBasicAuth('', '')).toEqual(builder);
expect(builder.withBasicAuth("", "")).toEqual(builder);
});
});
describe('withBody', () => {
it('should json stringify to { bodyPatterns: [{{ JSON GENERATED BY MATCH BUILDER }}] }', () => {
describe("withBody", () => {
it("should json stringify to { bodyPatterns: [{{ JSON GENERATED BY MATCH BUILDER }}] }", () => {
const builder = new RequestBuilderImpl();

@@ -147,6 +147,6 @@ builder.withBody().absent();

describe('withCookie', () => {
it('should json stringify to { cookies: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }', () => {
describe("withCookie", () => {
it("should json stringify to { cookies: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }", () => {
const builder = new RequestBuilderImpl();
builder.withCookie('ike').absent();
builder.withCookie("ike").absent();
const expectedJSON = JSON.stringify({ cookies: { ike: { absent: true } } });

@@ -157,6 +157,6 @@ expect(JSON.stringify(builder)).toEqual(expectedJSON);

describe('withHeader', () => {
it('should json stringify to { headers: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }', () => {
describe("withHeader", () => {
it("should json stringify to { headers: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }", () => {
const builder = new RequestBuilderImpl();
builder.withHeader('ike').absent();
builder.withHeader("ike").absent();
const expectedJSON = JSON.stringify({ headers: { ike: { absent: true } } });

@@ -167,6 +167,6 @@ expect(JSON.stringify(builder)).toEqual(expectedJSON);

describe('withQueryParam', () => {
it('should json stringify to { queryParameters: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }', () => {
describe("withQueryParam", () => {
it("should json stringify to { queryParameters: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }", () => {
const builder = new RequestBuilderImpl();
builder.withQueryParam('ike').absent();
builder.withQueryParam("ike").absent();
const expectedJSON = JSON.stringify({ queryParameters: { ike: { absent: true } } });

@@ -177,7 +177,7 @@ expect(JSON.stringify(builder)).toEqual(expectedJSON);

describe('withUrl', () => {
it('should json stringify to {{ JSON GENERATED BY URL MATCH BUILDER }}', () => {
describe("withUrl", () => {
it("should json stringify to {{ JSON GENERATED BY URL MATCH BUILDER }}", () => {
const builder = new RequestBuilderImpl();
builder.withUrl().equalTo('ike');
const expectedJSON = JSON.stringify({ url: 'ike' });
builder.withUrl().equalTo("ike");
const expectedJSON = JSON.stringify({ url: "ike" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);

@@ -187,7 +187,7 @@ });

describe('withUrlPath', () => {
it('should json stringify to {{ JSON GENERATED BY URL MATCH BUILDER }}', () => {
describe("withUrlPath", () => {
it("should json stringify to {{ JSON GENERATED BY URL MATCH BUILDER }}", () => {
const builder = new RequestBuilderImpl();
builder.withUrlPath().equalTo('ike');
const expectedJSON = JSON.stringify({ urlPath: 'ike' });
builder.withUrlPath().equalTo("ike");
const expectedJSON = JSON.stringify({ urlPath: "ike" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);

@@ -194,0 +194,0 @@ });

@@ -1,41 +0,41 @@

import { ResponseBuilderImpl } from '../../lib/builders/response_builder'
import { ResponseBuilderImpl } from "../../lib/builders/response_builder";
describe('ResponseBuilderImpl', () => {
describe('withBody', () => {
it('json stringifies to { body: value }', () => {
describe("ResponseBuilderImpl", () => {
describe("withBody", () => {
it("json stringifies to { body: value }", () => {
const builder = new ResponseBuilderImpl();
builder.withBody('whatevs');
const expectedJSON = JSON.stringify({ body: 'whatevs' });
builder.withBody("whatevs");
const expectedJSON = JSON.stringify({ body: "whatevs" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new ResponseBuilderImpl();
expect(builder.withBody('whatevs')).toEqual(builder);
expect(builder.withBody("whatevs")).toEqual(builder);
});
});
describe('withHeader', () => {
it('jsons an added header to { headers: { key: value } }', () => {
describe("withHeader", () => {
it("jsons an added header to { headers: { key: value } }", () => {
const builder = new ResponseBuilderImpl();
builder.withHeader('key', 'value');
const expectedJSON = JSON.stringify({ 'headers': { 'key': 'value' } });
builder.withHeader("key", "value");
const expectedJSON = JSON.stringify({ headers: { key: "value" } });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new ResponseBuilderImpl();
expect(builder.withHeader('whatevs', 'whatevs')).toEqual(builder);
expect(builder.withHeader("whatevs", "whatevs")).toEqual(builder);
});
});
describe('withStatus', () => {
it('json stringifies to { status: value }', () => {
describe("withStatus", () => {
it("json stringifies to { status: value }", () => {
const builder = new ResponseBuilderImpl();
builder.withStatus(400);
const expectedJSON = JSON.stringify({ 'status': 400 });
const expectedJSON = JSON.stringify({ status: 400 });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new ResponseBuilderImpl();

@@ -46,25 +46,25 @@ expect(builder.withStatus(400)).toEqual(builder);

describe('withStatusMessage', () => {
it('json stringifies to { statusMessage: value }', () => {
describe("withStatusMessage", () => {
it("json stringifies to { statusMessage: value }", () => {
const builder = new ResponseBuilderImpl();
builder.withStatusMessage('hi');
const expectedJSON = JSON.stringify({ 'statusMessage': 'hi' });
builder.withStatusMessage("hi");
const expectedJSON = JSON.stringify({ statusMessage: "hi" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new ResponseBuilderImpl();
expect(builder.withStatusMessage('hi')).toEqual(builder);
expect(builder.withStatusMessage("hi")).toEqual(builder);
});
});
describe('withDelay', () => {
it('json stringifies to { fixedDelayMilliseconds: value }', () => {
describe("withDelay", () => {
it("json stringifies to { fixedDelayMilliseconds: value }", () => {
const builder = new ResponseBuilderImpl();
builder.withDelay(123);
const expectedJSON = JSON.stringify({ 'fixedDelayMilliseconds': 123 });
const expectedJSON = JSON.stringify({ fixedDelayMilliseconds: 123 });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new ResponseBuilderImpl();

@@ -75,15 +75,15 @@ expect(builder.withDelay(123)).toEqual(builder);

describe('withTransformer', () => {
it('json stringifies to { transformer: value }', () => {
describe("withTransformer", () => {
it("json stringifies to { transformer: value }", () => {
const builder = new ResponseBuilderImpl();
builder.withTransformer('optimus prime');
const expectedJSON = JSON.stringify({ 'transformer': 'optimus prime' });
builder.withTransformer("optimus prime");
const expectedJSON = JSON.stringify({ transformer: "optimus prime" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns self for chaining', () => {
it("returns self for chaining", () => {
const builder = new ResponseBuilderImpl();
expect(builder.withTransformer('optimus prime')).toEqual(builder);
expect(builder.withTransformer("optimus prime")).toEqual(builder);
});
});
});

@@ -1,35 +0,35 @@

import { RequestBuilderImpl } from '../../lib/builders/request_builder';
import { UrlMatchBuilder } from '../../lib/builders/url_match_builder';
import { RequestBuilderImpl } from "../../lib/builders/request_builder";
import { UrlMatchBuilder } from "../../lib/builders/url_match_builder";
describe('UrlMatchBuilder', () => {
describe('constructed with path = true', () => {
describe('equalTo', () => {
it('json stringifies to { urlPath: value }', () => {
describe("UrlMatchBuilder", () => {
describe("constructed with path = true", () => {
describe("equalTo", () => {
it("json stringifies to { urlPath: value }", () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), true);
builder.equalTo('/some/path');
builder.equalTo("/some/path");
const expectedJSON = JSON.stringify({ 'urlPath': '/some/path' });
const expectedJSON = JSON.stringify({ urlPath: "/some/path" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new UrlMatchBuilder(requestBuilder, true);
expect(builder.equalTo('/some/path')).toEqual(requestBuilder);
expect(builder.equalTo("/some/path")).toEqual(requestBuilder);
});
});
describe('matching', () => {
it('json stringifies to { urlPattern: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl, true);
builder.matching('/some/path');
describe("matching", () => {
it("json stringifies to { urlPattern: value }", () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), true);
builder.matching("/some/path");
const expectedJSON = JSON.stringify({ 'urlPathPattern': '/some/path' });
const expectedJSON = JSON.stringify({ urlPathPattern: "/some/path" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
it('returns the constructor arg request builder for chaining', () => {
it("returns the constructor arg request builder for chaining", () => {
const requestBuilder = new RequestBuilderImpl();
const builder = new UrlMatchBuilder(requestBuilder, true);
expect(builder.matching('/some/path')).toEqual(requestBuilder);
expect(builder.matching("/some/path")).toEqual(requestBuilder);
});

@@ -39,9 +39,9 @@ });

describe('constructed with path = false', () => {
describe('equalTo', () => {
it('json stringifies to { url: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl, false);
builder.equalTo('/some/path');
describe("constructed with path = false", () => {
describe("equalTo", () => {
it("json stringifies to { url: value }", () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), false);
builder.equalTo("/some/path");
const expectedJSON = JSON.stringify({ 'url': '/some/path' });
const expectedJSON = JSON.stringify({ url: "/some/path" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);

@@ -51,8 +51,8 @@ });

describe('matching', () => {
it('json stringifies to { urlPattern: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl, false);
builder.matching('/some/path');
describe("matching", () => {
it("json stringifies to { urlPattern: value }", () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), false);
builder.matching("/some/path");
const expectedJSON = JSON.stringify({ 'urlPattern': '/some/path' });
const expectedJSON = JSON.stringify({ urlPattern: "/some/path" });
expect(JSON.stringify(builder)).toEqual(expectedJSON);

@@ -59,0 +59,0 @@ });

@@ -1,14 +0,14 @@

import { Configuration } from '../lib/configuration';
import { Configuration } from "../lib/configuration";
describe('Configuration', () => {
describe('createGlobalMapping', () => {
xit('should set the request builder on configuration', () => {
describe("Configuration", () => {
describe("createGlobalMapping", () => {
it("should set the request builder on configuration", () => {
Configuration.createGlobalMapping((requestBuilder, responseBuilder) => {
requestBuilder.withHeader('foo').equalTo('bar');
requestBuilder.withHeader("foo").equalTo("bar");
});
const expectedJSON = JSON.stringify({ headers: { foo: { equalTo: 'bar' } } });
const expectedJSON = JSON.stringify({ headers: { foo: { equalTo: "bar" } } });
expect(JSON.stringify(Configuration.requestBuilder)).toEqual(expectedJSON);
});
xit('should set the response builder on configuration', () => {
it("should set the response builder on configuration", () => {
Configuration.createGlobalMapping((requestBuilder, responseBuilder) => {

@@ -15,0 +15,0 @@ responseBuilder.withDelay(500);

@@ -1,152 +0,179 @@

import * as nock from 'nock';
import { WireMockMapper } from '../lib/wiremock_mapper';
import { Configuration } from '../lib/configuration';
import { RequestBuilder } from '../lib/builders/request_builder';
import { ResponseBuilder } from '../lib/builders/response_builder';
import * as nock from "nock";
import { RequestBuilder } from "../lib/builders/request_builder";
import { ResponseBuilder } from "../lib/builders/response_builder";
import { Configuration } from "../lib/configuration";
import { WireMockMapper } from "../lib/wiremock_mapper";
describe('WireMockMapper', () => {
describe('createMapping', () => {
it('posts the correct json to wiremock', (done) => {
const expected_request_body = { request: { method: 'POST',
urlPath: '/some/path',
headers: { some_header: { equalTo: 'some header value' } },
bodyPatterns: [
{ matches: 'some request body' }
] },
response: { body: 'some response body' } };
describe("WireMockMapper", () => {
describe("createMapping", () => {
it("posts the correct json to wiremock", (done) => {
const expectedRequestBody = {
request: {
bodyPatterns: [{ matches: "some request body" }],
headers: { some_header: { equalTo: "some header value" } },
method: "POST",
urlPath: "/some/path"
},
response: { body: "some response body" } };
nock('http://localhost:8080', { reqheaders: { 'Content-Type': 'application/json' } })
.post('/__admin/mappings', expected_request_body)
.reply(201, { id: 123 })
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", expectedRequestBody)
.reply(201, { id: 123 });
const promise = WireMockMapper.createMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.isAPost()
.withUrlPath().equalTo('/some/path')
.withHeader('some_header').equalTo('some header value')
.withBody().matching('some request body')
.withUrlPath().equalTo("/some/path")
.withHeader("some_header").equalTo("some header value")
.withBody().matching("some request body");
respond.withBody('some response body')
respond.withBody("some response body");
});
promise.then(() => done())
.catch(() => done.fail());;
promise.then(done)
.catch(() => done.fail());
});
it('resolves the promise with the mapping id', (done) => {
const expected_request_body = { request: { method: 'POST',
urlPath: '/some/path',
headers: { some_header: { equalTo: 'some header value' } },
bodyPatterns: [
{ matches: 'some request body' }
] },
response: { body: 'some response body' } };
it("resolves the promise with the mapping id", (done) => {
const expectedRequestBody = {
request: {
bodyPatterns: [{ matches: "some request body" }],
headers: { some_header: { equalTo: "some header value" } },
method: "POST",
urlPath: "/some/path"
},
response: { body: "some response body" } };
nock('http://localhost:8080', { reqheaders: { 'Content-Type': 'application/json' } })
.post('/__admin/mappings', expected_request_body)
.reply(201, { id: '123' })
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", expectedRequestBody)
.reply(201, { id: "123" });
const promise = WireMockMapper.createMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.isAPost()
.withUrlPath().equalTo('/some/path')
.withHeader('some_header').equalTo('some header value')
.withBody().matching('some request body')
.withUrlPath().equalTo("/some/path")
.withHeader("some_header").equalTo("some header value")
.withBody().matching("some request body");
respond.withBody('some response body')
respond.withBody("some response body");
});
promise.then((id) => { expect(id).toEqual('123'); done(); })
.catch(() => done.fail());;
promise.then((id) => { expect(id).toEqual("123"); done(); })
.catch(() => done.fail());
});
it('rejects the promise with an error if the status code is not 201', (done) => {
const expected_request_body = { request: { method: 'POST',
urlPath: '/some/path',
headers: { some_header: { equalTo: 'some header value' } },
bodyPatterns: [
{ matches: 'some request body' }
] },
response: { body: 'some response body' } };
it("rejects the promise with an error if the status code is not 201", (done) => {
const expectedRequestBody = {
request: {
bodyPatterns: [{ matches: "some request body" }],
headers: { some_header: { equalTo: "some header value" } },
method: "POST",
urlPath: "/some/path"
},
response: { body: "some response body" }
};
nock('http://localhost:8080', { reqheaders: { 'Content-Type': 'application/json' } })
.post('/__admin/mappings', expected_request_body)
.reply(400)
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", expectedRequestBody)
.reply(400);
const promise = WireMockMapper.createMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.isAPost()
.withUrlPath().equalTo('/some/path')
.withHeader('some_header').equalTo('some header value')
.withBody().matching('some request body')
.withUrlPath().equalTo("/some/path")
.withHeader("some_header").equalTo("some header value")
.withBody().matching("some request body");
respond.withBody('some response body')
respond.withBody("some response body");
});
promise.then(() => done.fail())
.catch(() => done());;
.catch(done);
});
xit('sends the global mappings', (done) => {
it("rejects the promise if there was an error with the request", (done) => {
const expectedRequestBody = { request: { method: "POST", urlPath: "/some/path" },
response: { body: "some response body" } };
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", expectedRequestBody)
.replyWithError("something went wrong...sorry dude...");
const promise = WireMockMapper.createMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.isAPost()
.withUrlPath().equalTo("/some/path");
respond.withBody("some response body");
});
promise.then(() => done.fail())
.catch(done);
});
it("sends the global mappings", (done) => {
Configuration.createGlobalMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.withHeader('some_header').equalTo('some header value')
request.withHeader("some_header").equalTo("some header value");
});
const expected_request_body = { request: { method: 'POST',
urlPath: '/some/path',
headers: { some_header: { equalTo: 'some header value' } },
bodyPatterns: [
{ matches: 'some request body' }
] },
response: { body: 'some response body' } };
const expectedRequestBody = {
request: {
bodyPatterns: [{ matches: "some request body" }],
headers: { some_header: { equalTo: "some header value" } },
method: "POST",
urlPath: "/some/path"
},
response: { body: "some response body" }
};
nock('http://localhost:8080', { reqheaders: { 'Content-Type': 'application/json' } })
.post('/__admin/mappings', expected_request_body)
.reply(201, { id: 123 })
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", expectedRequestBody)
.reply(201, { id: 123 });
const promise = WireMockMapper.createMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.isAPost()
.withUrlPath().equalTo('/some/path')
.withBody().matching('some request body')
.withUrlPath().equalTo("/some/path")
.withBody().matching("some request body");
respond.withBody('some response body')
respond.withBody("some response body");
});
promise.then(() => done())
.catch(() => done.fail());;
promise.then(done)
.catch(() => done.fail());
});
xit('subsequent requests do not have state from first', (done) => {
const expected_request_body = {
it("subsequent requests do not have state from first", (done) => {
const expectedRequestBody = {
request: {
method: 'POST',
urlPath: '/some/path',
headers: { some_header: { equalTo: 'some header value' } },
bodyPatterns: [
{ matches: 'some request body' }
] },
response: { body: 'some response body' }
bodyPatterns: [{ matches: "some request body" }],
headers: { some_header: { equalTo: "some header value" } },
method: "POST",
urlPath: "/some/path",
},
response: { body: "some response body" },
};
const second_expected_request_body = {
const secondExpectedRequestBody = {
request: {
method: 'POST',
urlPath: '/some/path',
headers: { some_header: { equalTo: 'some other header value' } },
bodyPatterns: [
{ matches: 'some other request body' }
] },
response: { body: 'some other response body' }
bodyPatterns: [{ matches: "some other request body" }],
headers: { some_header: { equalTo: "some header value" } },
method: "POST",
urlPath: "/some/path"
},
response: { body: "some other response body" },
};
nock('http://localhost:8080', { reqheaders: { 'Content-Type': 'application/json' } })
.post('/__admin/mappings', expected_request_body)
.reply(201, { id: 123 })
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", expectedRequestBody)
.reply(201, { id: 123 });
nock('http://localhost:8080', { reqheaders: { 'Content-Type': 'application/json' } })
.post('/__admin/mappings', second_expected_request_body)
.reply(201, { id: 123 })
nock("http://localhost:8080", { reqheaders: { "Content-Type": "application/json" } })
.post("/__admin/mappings", secondExpectedRequestBody)
.reply(201, { id: 123 });
Configuration.createGlobalMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.withHeader("some_header").equalTo("some header value");
});
const promise1 = WireMockMapper.createMapping((request: RequestBuilder, respond: ResponseBuilder) => {
request.isAPost()
.withUrlPath().equalTo('/some/path')
.withBody().matching('some request body')
.withUrlPath().equalTo("/some/path")
.withBody().matching("some request body");
respond.withBody('some response body')
respond.withBody("some response body");
});

@@ -156,9 +183,9 @@

request.isAPost()
.withUrlPath().equalTo('/some/path')
.withBody().matching('some other request body')
.withUrlPath().equalTo("/some/path")
.withBody().matching("some other request body");
respond.withBody('some other response body')
respond.withBody("some other response body");
});
Promise.all([promise1, promise2]).then(() => done())
Promise.all([promise1, promise2]).then(done)
.catch(() => done.fail());

@@ -168,39 +195,57 @@ });

describe('deleteMapping', () => {
it('sends a DELETE request with the provided mapping id to wiremock', () => {
nock('http://localhost:8080')
.delete('/__admin/mappings/123')
describe("deleteMapping", () => {
it("sends a DELETE request with the provided mapping id to wiremock", () => {
nock("http://localhost:8080")
.delete("/__admin/mappings/123")
.reply(200);
WireMockMapper.deleteMapping('123');
WireMockMapper.deleteMapping("123");
});
it('rejects the promise if the response is not a 200', (done) => {
nock('http://localhost:8080')
.delete('/__admin/mappings/123')
it("rejects the promise if the response is not a 200", (done) => {
nock("http://localhost:8080")
.delete("/__admin/mappings/123")
.reply(404);
const promise = WireMockMapper.deleteMapping('123');
const promise = WireMockMapper.deleteMapping("123");
promise.then(() => done.fail())
.catch(() => done());
.catch(done);
});
it("rejects the promise if there was an error with the request", (done) => {
nock("http://localhost:8080")
.delete("/__admin/mappings/123")
.replyWithError("something went wrong...sorry dude...");
const promise = WireMockMapper.deleteMapping("123");
promise.then(() => done.fail())
.catch(done);
});
});
describe('clearAllMappings', () => {
it('sends the correct request to WireMock', (done) => {
nock('http://localhost:8080')
.post('/__admin/mappings/reset')
describe("clearAllMappings", () => {
it("sends the correct request to WireMock", (done) => {
nock("http://localhost:8080")
.post("/__admin/mappings/reset")
.reply(200);
const promise = WireMockMapper.clearAllMappings();
promise.then(() => done())
promise.then(done)
.catch(() => done.fail());
});
it('rejects the promise if the request returns the a status code that is not 200', (done) => {
nock('http://localhost:8080')
.post('/__admin/mappings/reset')
it("rejects the promise if the request returns the a status code that is not 200", (done) => {
nock("http://localhost:8080")
.post("/__admin/mappings/reset")
.reply(400);
const promise = WireMockMapper.clearAllMappings();
promise.then(() => done.fail())
.catch(() => done());
.catch(done);
});
it("rejects the promise if there was an error with the request", (done) => {
nock("http://localhost:8080")
.post("/__admin/mappings/reset")
.replyWithError("something went wrong...sorry dude...");
const promise = WireMockMapper.clearAllMappings();
promise.then(() => done.fail())
.catch(done);
});
});
});
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