Socket
Socket
Sign inDemoInstall

@pact-foundation/pact-node

Package Overview
Dependencies
Maintainers
4
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pact-foundation/pact-node - npm Package Compare versions

Comparing version 4.4.2 to 4.4.3

2

package.json
{
"name": "@pact-foundation/pact-node",
"version": "4.4.2",
"version": "4.4.3",
"description": "A wrapper for the Ruby version of Pact to work within Node",

@@ -5,0 +5,0 @@ "main": "./src/pact.js",

@@ -22,2 +22,21 @@ 'use strict';

// Given Pact Options and a Pact File, construct a Pact URL used to
// PUT/POST to the Pact Broker.
var constructPutUrl = function(options, data) {
if (!_.has(options, 'pactBroker')) {
throw new Error("Cannot construct Pact publish URL: 'pactBroker' not specified");
}
if (!_.isObject(options)
|| !_.has(data, 'consumer')
|| !_.has(data, 'provider')
|| !_.has(data.consumer, 'name')
|| !_.has(data.provider, 'name')) {
throw new Error("Invalid Pact file given. " +
"Unable to parse consumer and provider name");
}
return urlJoin(options.pactBroker, 'pacts/provider', data.provider.name, 'consumer', data.consumer.name, 'version', options.consumerVersion)
};
Publisher.prototype.publish = function () {

@@ -99,4 +118,6 @@ var options = this.options;

.then(function(data) {
var url = constructPutUrl(options, data);
var config = {
uri: urlJoin(options.pactBroker, 'pacts/provider', data.provider, 'consumer', data.consumer, 'version', options.consumerVersion),
uri: url,
method: 'PUT',

@@ -116,3 +137,7 @@ headers: {

} else {
deferred.reject();
if (error != null) {
deferred.reject(error);
} else {
deferred.reject(new Error('Unable to publish Pact to Broker: ' + response.statusCode));
}
}

@@ -119,0 +144,0 @@ });

@@ -9,2 +9,5 @@ /* global describe:true, before:true, after:true, it:true, global:true, process:true */

chai = require("chai"),
rewire = require("rewire"),
publisher = rewire("./publisher.js"),
constructPutUrl = publisher.__get__('constructPutUrl'),
broker = require('../test/integration/brokerMock.js'),

@@ -97,2 +100,39 @@ chaiAsPromised = require("chai-as-promised");

});
context("constructPutUrl", function () {
context("when given a valid config object and pact JSON", function () {
it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo' };
var data = { 'consumer': { 'name': 'consumerName' }, 'provider': { 'name': 'providerName' } };
expect(constructPutUrl(options, data)).to.eq('http://foo/pacts/provider/providerName/consumer/consumerName/version/');
});
});
context("when given an invalid config object", function () {
it("should return a PUT url", function () {
var options = { 'someotherurl': 'http://foo' };
var data = { 'consumer': { 'name': 'consumerName' }, 'provider': { 'name': 'providerName' } };
expect(function() {
constructPutUrl(options, data);
}).to.throw(Error, "Cannot construct Pact publish URL: 'pactBroker' not specified");
});
});
context("when given an invalid pact file (no consumer/provider keys)", function () {
it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo' };
var data = { };
expect(function() {
constructPutUrl(options, data);
}).to.throw(Error, "Invalid Pact file given. Unable to parse consumer and provider name");
});
});
context("when given an invalid pact file (no name keys)", function () {
it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo' };
var data = { 'consumer': {}, 'provider': {} };
expect(function() {
constructPutUrl(options, data);
}).to.throw(Error, "Invalid Pact file given. Unable to parse consumer and provider name");
});
});
});
});

@@ -35,4 +35,7 @@ var cors = require('cors'),

server.get('/somebrokenpact', function(req, res) {
res.json({});
});
server.get('/somepact', function(req, res) {
console.log('pact get!!')
res.json({'consumer': {'name': 'anotherclient'}, 'provider': {'name': 'they'}});

@@ -39,0 +42,0 @@ });

@@ -144,3 +144,3 @@ /* global describe:true, before:true, after:true, it:true, global:true, process:true */

context("and the pact files are invalid", function () {
context("and the pact files do not exist (404)", function () {
it("should return a rejected promise", function () {

@@ -162,3 +162,20 @@ var publisher = publisherFactory({

});
context("and the pact files are invalid (no consumer/provider)", function () {
it("should return a rejected promise", function () {
var publisher = publisherFactory({
pactBroker: pactBrokerBaseUrl,
pactUrls: [pactBrokerBaseUrl + '/somebrokenpact'],
consumerVersion: "1.0.0"
});
return publisher.publish()
.then(function() {
throw new Error("Expected an error but got none");
})
.catch(function(err) {
expect(err.message).to.contain("Invalid Pact file given. Unable to parse consumer and provider name");
})
});
});
});
});

Sorry, the diff of this file is not supported yet

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