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

consumer-contracts

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consumer-contracts - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.travis.yml

2

index.js
module.exports.Contract = require('./lib/contract');
module.exports.Joi = require('joi');
module.exports.Joi = require('joi');

@@ -6,8 +6,2 @@ var Joi = require('joi');

var package = require('../package');
var request = require('request').defaults({
json: true,
headers: {
'user-agent': 'consumer-contracts/' + package.version
}
});

@@ -41,2 +35,8 @@ var requiredOptions = [

this.response = options.response;
this.client = (options.client || require('request')).defaults({
json: true,
headers: {
'user-agent': 'consumer-contracts/' + package.version
}
});
}

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

request(this.request, function (err, res) {
this.client(this.request, function (err, res) {
if (err) return cb(new Error(util.format('Request failed: %s', err.message)));

@@ -68,2 +68,2 @@

module.exports = Contract;
module.exports = Contract;
{
"name": "consumer-contracts",
"version": "1.0.0",
"version": "1.1.0",
"description": "Consumer driven contracts for Node.js",

@@ -36,3 +36,4 @@ "main": "index.js",

"recursive-readdir": "^1.2.1",
"request": "^2.55.0"
"request": "^2.55.0",
"sinon": "^1.14.1"
},

@@ -58,2 +59,2 @@ "devDependencies": {

}
}
}
# consumer-contracts
[![Build Status](https://travis-ci.org/robinjmurphy/consumer-contracts.svg)](https://travis-ci.org/robinjmurphy/consumer-contracts) [![Code Climate](https://codeclimate.com/github/robinjmurphy/consumer-contracts/badges/gpa.svg)](https://codeclimate.com/github/robinjmurphy/consumer-contracts)
> Consumer-driven contracts in JavaScript

@@ -75,3 +77,3 @@

```

@@ -101,3 +103,3 @@

The `consumer` property appears in the output of the `consumer-contracts` tool and should be the name of the consuming service that the contract applies to.
The `consumer` property appears in the output of the `consumer-contracts` tool and should be the name of the consuming service that the contract applies to.

@@ -137,3 +139,3 @@ ### `name`

### Validating the response code
#### Validating the response code

@@ -156,3 +158,3 @@ To require a specific HTTP status code, set the `statusCode` property to that value:

### Validating the response headers
#### Validating the response headers

@@ -170,3 +172,3 @@ The response headers can be validated using a Joi schema:

### Validating the response body
#### Validating the response body

@@ -186,2 +188,28 @@ The response body can be validated using a Joi schema:

### `client` _optional_
You can use a pre-configured [request](https://github.com/request/request) client for your contracts using the `client` property. This can be useful when you have a set of common request options across contracts.
```js
var Contract = require('consumer-contracts').Contract;
var Joi = require('consumer-contracts').Joi;
var client = require('request').defaults({
headers: {
authorization: 'Bearer xxx'
}
});
module.exports = new Contract({
name: 'Contract name',
consumer: 'Consumer name',
request: {
// ...
},
response: {
// ...
},
client: client
});
```
## CLI

@@ -188,0 +216,0 @@

@@ -5,2 +5,3 @@ var Contract = require('../lib/contract');

var nock = require('nock');
var sinon = require('sinon');

@@ -131,3 +132,59 @@ describe('Contract', function () {

});
it('sets a user-agent header', function (done) {
nock('http://api.example.com', {
reqheaders: {
'user-agent': 'consumer-contracts/' + require('../package').version
}
}).get('/').reply(200);
var contract = new Contract({
name: 'Name',
consumer: 'Consumer',
request: {
url: 'http://api.example.com/'
},
response: {
statusCode: 200
}
});
contract.validate(function (err) {
assert.ifError(err);
done();
});
});
it('supports passing a custom request client', function (done) {
nock('http://api.example.com', {
reqheaders: {
authorization: 'Bearer xxx',
'user-agent': 'consumer-contracts/' + require('../package').version
}
}).get('/').reply(200);
var client = require('request').defaults({
headers: {
authorization: 'Bearer xxx'
}
});
var contract = new Contract({
name: 'Name',
consumer: 'Consumer',
request: {
url: 'http://api.example.com/'
},
response: {
statusCode: 200
},
client: client
});
contract.validate(function (err) {
assert.ifError(err);
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