@pact-foundation/pact-node
Advanced tools
Comparing version 4.5.4 to 4.6.0
{ | ||
"name": "@pact-foundation/pact-node", | ||
"version": "4.5.4", | ||
"version": "4.6.0", | ||
"description": "A wrapper for the Ruby version of Pact to work within Node", | ||
@@ -75,3 +75,3 @@ "main": "./src/pact.js", | ||
"pretest": "npm run clean && npm run lint", | ||
"test": "./node_modules/.bin/cross-env LOGLEVEL=debug ./node_modules/.bin/mocha ./**/*.spec.js", | ||
"test": "./node_modules/.bin/cross-env LOGLEVEL=fatal ./node_modules/.bin/mocha -R spec --timeout 10000 ./**/*.spec.js", | ||
"watch": "nodemon -x npm run dev", | ||
@@ -78,0 +78,0 @@ "watch:debug": "nodemon --debug -q -w assets/ --ext '.' --exec 'npm run lint'", |
var bunyan = require('bunyan'), | ||
pkg = require('../package.json'), | ||
_ = require('underscore'), | ||
PrettyStream = require('bunyan-prettystream'), | ||
@@ -5,0 +4,0 @@ prettyStdOut = new PrettyStream(); |
@@ -19,2 +19,11 @@ var expect = require('chai').expect, | ||
describe("Set Log Level", function () { | ||
var originalLogLevel; | ||
// Reset lot level after the tests | ||
before(function () { | ||
originalLogLevel = pact.logLevel(); | ||
}); | ||
after(function () { | ||
pact.logLevel(originalLogLevel); | ||
}); | ||
context("when setting a log level", function () { | ||
@@ -21,0 +30,0 @@ it("should be able to set log level 'trace'", function () { |
@@ -47,7 +47,25 @@ 'use strict'; | ||
// Return a merge of all promises... | ||
return q.allSettled( | ||
_.map(uris, function (uri) { | ||
return getPactFile(options, uri) | ||
.then(function (data) { | ||
// Return a promise that does everything one after another | ||
return q(uris) | ||
.then(function (uris) { // Get the pact contract either from local file or broker | ||
return q.allSettled( | ||
_.map(uris, function (uri) { | ||
return getPactFile(options, uri) | ||
})) | ||
.then(function (data) { // Make sure all files have been retrieved | ||
var rejects = []; | ||
data = _.map(data, function (result) { | ||
if (result.state === "fulfilled") { | ||
return result.value; | ||
} | ||
rejects.push(result.reason); | ||
}); | ||
return rejects.length ? | ||
q.reject(new Error('Could not retrieve all Pact contracts:\n - ' + rejects.join('\n - '))) | ||
: data; | ||
}); | ||
}) | ||
.tap(function (files) { // Publish the contracts to broker | ||
return q.allSettled( | ||
_.map(files, function (data) { | ||
return callPact(options, { | ||
@@ -62,41 +80,53 @@ uri: constructPutUrl(options, data), | ||
body: data | ||
}).fail(function (err) { | ||
return q.reject(new Error('Unable to publish Pact to Broker. ' + err.message)); | ||
}); | ||
}) | ||
.tap(function (data) { | ||
if (!options.tags.length) { | ||
return; | ||
).then(function (results) { // Make sure publishing promises came back fulfilled, or else error out | ||
var rejects = []; | ||
_.each(results, function (result) { | ||
if (result.state !== "fulfilled") { | ||
rejects.push(result.reason); | ||
} | ||
return q.allSettled(_.map(options.tags, function (tag) { | ||
return callPact(options, { | ||
uri: constructTagUrl(options, tag, data), | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}).fail(function () { | ||
return q.reject(new Error('Could not tag Pact with tag "' + tag + '"')); | ||
}); | ||
})).tap(function (results) { | ||
_.each(results, function (result) { | ||
if (result.state !== "fulfilled") { | ||
logger.warn(result.reason); | ||
} | ||
}); | ||
}); | ||
}); | ||
if (rejects.length) { | ||
return q.reject(new Error('Could not publish pacts to broker at "' + options.pactBroker + '":\n - ' + rejects.join('\n - '))); | ||
} | ||
}); | ||
}) | ||
).then(function (results) { | ||
var reject = false; | ||
results = _.map(results, function (result) { | ||
if (result.state === "fulfilled") { | ||
return result.value; | ||
} else { | ||
reject = true; | ||
return result.reason; | ||
.tap(function (files) { // If publishing works, try to tag those contracts | ||
if (!options.tags || !options.tags.length) { | ||
return; | ||
} | ||
}); | ||
return reject ? q.reject(results) : results; | ||
}); | ||
return q.allSettled( | ||
_.chain(files) | ||
.map(function (data) { | ||
return _.map(options.tags, function (tag) { | ||
return callPact(options, { | ||
uri: constructTagUrl(options, tag, data), | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}).fail(function (err) { | ||
return q.reject('Error with tag "' + tag + '": ' + err); | ||
}); | ||
}) | ||
}) | ||
.flatten(true) | ||
.value() | ||
).then(function (results) { | ||
var rejects = []; | ||
_.each(results, function (result) { | ||
if (result.state !== "fulfilled") { | ||
rejects.push(result.reason); | ||
} | ||
}); | ||
if (rejects.length) { | ||
return q.reject(new Error('Could not tag Pact contract:\n - ' + rejects.join('\n - '))); | ||
} | ||
}); | ||
}) | ||
.catch(function (err) { | ||
logger.error(err); | ||
return q.reject(err); | ||
}) | ||
}; | ||
@@ -125,3 +155,3 @@ | ||
if (response.statusCode < 200 || response.statusCode >= 300) { | ||
return q.reject(new Error('Failed http call to pact broker. \nCode: ' + response.statusCode + '\nBody: ' + response.body)); | ||
return q.reject('Failed http call to pact broker.\nURI: ' + config.uri + '\nCode: ' + response.statusCode + '\nBody: ' + response.body); | ||
} | ||
@@ -138,3 +168,3 @@ return response.body; | ||
} catch (err) { | ||
return q.reject("Invalid Pact file: " + uri + ". Nested exception: " + err); | ||
return q.reject('Invalid Pact contract "' + uri + '":\n' + err); | ||
} | ||
@@ -146,3 +176,3 @@ } else { | ||
}).fail(function (err) { | ||
return q.reject(new Error('Cannot GET ' + uri + '. Nested exception: ' + err.message)) | ||
return q.reject('Failed to get Pact contract from broker:\n' + err); | ||
}); | ||
@@ -152,3 +182,3 @@ } | ||
// Given Pact Options and a Pact File, construct a Pact URL used to | ||
// Given Pact Options and a Pact contract, construct a Pact URL used to | ||
// PUT/POST to the Pact Broker. | ||
@@ -169,3 +199,3 @@ function constructPutUrl(options, data) { | ||
|| !_.has(data.provider, 'name')) { | ||
throw new Error("Invalid Pact file given. " + | ||
throw new Error("Invalid Pact contract given. " + | ||
"Unable to parse consumer and provider name"); | ||
@@ -189,3 +219,3 @@ } | ||
|| !_.has(data.consumer, 'name')) { | ||
throw new Error("Invalid Pact file given. " + | ||
throw new Error("Invalid Pact contract given. " + | ||
"Unable to parse consumer name"); | ||
@@ -217,3 +247,3 @@ } | ||
} catch (e) { | ||
throw new Error('Pact file or directory: "' + uri + '" doesn\'t exist'); | ||
throw new Error('Pact contract or directory: "' + uri + '" doesn\'t exist'); | ||
} | ||
@@ -220,0 +250,0 @@ } |
@@ -122,3 +122,3 @@ var publisherFactory = require('./publisher'), | ||
}); | ||
context("when given an invalid pact file (no consumer/provider keys)", function () { | ||
context("when given an invalid Pact contract (no consumer/provider keys)", function () { | ||
it("should return a PUT url", function () { | ||
@@ -129,6 +129,6 @@ var options = {'pactBroker': 'http://foo', 'consumerVersion': '1'}; | ||
constructPutUrl(options, data); | ||
}).to.throw(Error, "Invalid Pact file given. Unable to parse consumer and provider name"); | ||
}).to.throw(Error, "Invalid Pact contract given. Unable to parse consumer and provider name"); | ||
}); | ||
}); | ||
context("when given an invalid pact file (no name keys)", function () { | ||
context("when given an invalid Pact contract (no name keys)", function () { | ||
it("should return a PUT url", function () { | ||
@@ -139,3 +139,3 @@ var options = {'pactBroker': 'http://foo', 'consumerVersion': '1'}; | ||
constructPutUrl(options, data); | ||
}).to.throw(Error, "Invalid Pact file given. Unable to parse consumer and provider name"); | ||
}).to.throw(Error, "Invalid Pact contract given. Unable to parse consumer and provider name"); | ||
}); | ||
@@ -169,3 +169,3 @@ }); | ||
}); | ||
context("when given an invalid pact file (no consumer key)", function () { | ||
context("when given an invalid Pact contract (no consumer key)", function () { | ||
it("should return a PUT url", function () { | ||
@@ -176,6 +176,6 @@ var options = {'pactBroker': 'http://foo', consumerVersion: '1.0'}; | ||
constructTagUrl(options, data); | ||
}).to.throw(Error, "Invalid Pact file given. Unable to parse consumer name"); | ||
}).to.throw(Error, "Invalid Pact contract given. Unable to parse consumer name"); | ||
}); | ||
}); | ||
context("when given an invalid pact file (no name keys)", function () { | ||
context("when given an invalid Pact contract (no name keys)", function () { | ||
it("should return a PUT url", function () { | ||
@@ -186,3 +186,3 @@ var options = {'pactBroker': 'http://foo', consumerVersion: '1.0'}; | ||
constructTagUrl(options, data); | ||
}).to.throw(Error, "Invalid Pact file given. Unable to parse consumer name"); | ||
}).to.throw(Error, "Invalid Pact contract given. Unable to parse consumer name"); | ||
}); | ||
@@ -189,0 +189,0 @@ }); |
var publisherFactory = require('./../src/publisher'), | ||
logger = require('./../src/logger'), | ||
expect = require('chai').expect, | ||
@@ -17,3 +16,3 @@ fs = require('fs'), | ||
authenticatedPactBrokerBaseUrl = 'http://localhost:' + PORT + '/auth'; | ||
before(function (done) { | ||
@@ -25,10 +24,10 @@ server = broker.listen(PORT, function () { | ||
}); | ||
after(function () { | ||
server.close(); | ||
}); | ||
context("when publishing a to a broker", function () { | ||
context("without authentication", function () { | ||
context("and the Pact file is valid", function () { | ||
context("and the Pact contract is valid", function () { | ||
it("should successfully publish all Pacts", function () { | ||
@@ -40,3 +39,3 @@ var publisher = publisherFactory({ | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -46,3 +45,3 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
it("should successfully tag all Pacts with 'test' and 'latest'", function () { | ||
@@ -55,3 +54,3 @@ var publisher = publisherFactory({ | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -62,3 +61,3 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
context("and the Pact file is invalid", function () { | ||
context("and the Pact contract is invalid", function () { | ||
it("should report an unsuccessful push", function () { | ||
@@ -70,3 +69,3 @@ var publisher = publisherFactory({ | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -78,3 +77,3 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
context("with authentication", function () { | ||
@@ -90,3 +89,3 @@ context("and valid credentials", function () { | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -97,3 +96,3 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
context("and invalid credentials", function () { | ||
@@ -108,3 +107,3 @@ it("should return a rejected promise", function () { | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -116,7 +115,7 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
}); | ||
context("when publishing a directory of Pacts to a Broker", function () { | ||
context("and the directory contains only valid pact files", function () { | ||
context("and the directory contains only valid Pact contracts", function () { | ||
it("should asynchronously send all Pacts to the Broker", function () { | ||
@@ -128,3 +127,3 @@ var publisher = publisherFactory({ | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -137,3 +136,3 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
it("should successfully tag all Pacts sent with 'test' and 'latest'", function () { | ||
@@ -146,3 +145,3 @@ var publisher = publisherFactory({ | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -156,5 +155,5 @@ expect(publisher).to.respondTo('publish'); | ||
}); | ||
context("and the directory contains Pact and non-Pact files", function () { | ||
it("should asynchronously send only the Pact files to the broker", function () { | ||
context("and the directory contains Pact and non-Pact contracts", function () { | ||
it("should asynchronously send only the Pact contracts to the broker", function () { | ||
var publisher = publisherFactory({ | ||
@@ -165,3 +164,3 @@ pactBroker: pactBrokerBaseUrl, | ||
}); | ||
expect(publisher).to.be.a('object'); | ||
@@ -177,4 +176,4 @@ expect(publisher).to.respondTo('publish'); | ||
context("when publishing Pacts from an http-based URL", function () { | ||
context("and the pact files are valid", function () { | ||
it("should asynchronously send the Pact files to the broker", function () { | ||
context("and the Pact contracts are valid", function () { | ||
it("should asynchronously send the Pact contracts to the broker", function () { | ||
var publisher = publisherFactory({ | ||
@@ -185,6 +184,6 @@ pactBroker: pactBrokerBaseUrl, | ||
}); | ||
return expect(publisher.publish()).to.eventually.be.fulfilled; | ||
}); | ||
it("should successfully tag all Pacts sent with 'test' and 'latest'", function () { | ||
@@ -197,8 +196,8 @@ var publisher = publisherFactory({ | ||
}); | ||
return expect(publisher.publish()).to.eventually.be.fulfilled; | ||
}); | ||
}); | ||
context("and the pact files do not exist (404)", function () { | ||
context("and the Pact contracts do not exist (404)", function () { | ||
it("should return a rejected promise", function () { | ||
@@ -210,3 +209,3 @@ var publisher = publisherFactory({ | ||
}); | ||
return publisher.publish() | ||
@@ -216,9 +215,9 @@ .then(function () { | ||
}) | ||
.catch(function (results) { | ||
expect(results[0].message).to.contain("Cannot GET /somepacturlthatdoesntexist") | ||
.catch(function (err) { | ||
expect(err.message).to.contain("Cannot GET /somepacturlthatdoesntexist") | ||
}) | ||
}); | ||
}); | ||
context("and the pact files are invalid (no consumer/provider)", function () { | ||
context("and the Pact contracts are invalid (no consumer/provider)", function () { | ||
it("should return a rejected promise", function () { | ||
@@ -230,3 +229,3 @@ var publisher = publisherFactory({ | ||
}); | ||
return publisher.publish() | ||
@@ -236,4 +235,4 @@ .then(function () { | ||
}) | ||
.catch(function (results) { | ||
expect(results[0].message).to.contain("Invalid Pact file given. Unable to parse consumer and provider name"); | ||
.catch(function (err) { | ||
expect(err.message).to.contain("Invalid Pact contract given. Unable to parse consumer and provider name"); | ||
}) | ||
@@ -240,0 +239,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98270
2414
38