From cc44554d61629591094fa3b001b2ddc58f9cb8b8 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Thu, 11 May 2017 20:51:51 +1000 Subject: [PATCH] fix(providerstate): make providerState serialisation spec compliant #12 --- src/dsl/interaction.js | 16 ++++++++-------- test/dsl/interaction.spec.js | 10 +++++----- test/pact.spec.js | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/dsl/interaction.js b/src/dsl/interaction.js index 4ce26ce59..a2569c614 100644 --- a/src/dsl/interaction.js +++ b/src/dsl/interaction.js @@ -8,7 +8,7 @@ const omitBy = require('lodash.omitby') const isNil = require('lodash.isnil') -const VALID_METHODS = [ 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS' ] +const VALID_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] module.exports = class Interaction { @@ -16,7 +16,7 @@ module.exports = class Interaction { * Creates a new Interaction. * @returns {Interaction} interaction */ - constructor () { + constructor() { this.state = {} return this } @@ -26,9 +26,9 @@ module.exports = class Interaction { * @param {string} providerState - The state of the provider. * @returns {Interaction} interaction */ - given (providerState) { + given(providerState) { if (providerState) { - this.state['provider_state'] = providerState + this.state['providerState'] = providerState } return this } @@ -38,7 +38,7 @@ module.exports = class Interaction { * @param {string} description - A description of the interaction. * @returns {Interaction} interaction */ - uponReceiving (description) { + uponReceiving(description) { if (isNil(description)) { throw new Error('You must provide a description for the interaction.') } @@ -56,7 +56,7 @@ module.exports = class Interaction { * @param {Object} requestOpts.body - The body, in {@link String} format or {@link Object} format * @returns {Interaction} interaction */ - withRequest (requestOpts) { + withRequest(requestOpts) { var method = requestOpts.method var path = requestOpts.path var query = requestOpts.query @@ -92,7 +92,7 @@ module.exports = class Interaction { * @param {string} responseOpts.headers * @param {Object} responseOpts.body */ - willRespondWith (responseOpts) { + willRespondWith(responseOpts) { var status = responseOpts.status var headers = responseOpts.headers var body = responseOpts.body @@ -112,7 +112,7 @@ module.exports = class Interaction { * Returns the interaction object created. * @returns {Object} */ - json () { + json() { return this.state } } diff --git a/test/dsl/interaction.spec.js b/test/dsl/interaction.spec.js index 3d5582866..1da9da939 100644 --- a/test/dsl/interaction.spec.js +++ b/test/dsl/interaction.spec.js @@ -5,23 +5,23 @@ describe('Interaction', () => { describe('#given', () => { it('creates Interaction with provider state', () => { const actual = new Interaction().given('provider state').json() - expect(actual).to.eql({ provider_state: 'provider state' }) + expect(actual).to.eql({ providerState: 'provider state' }) }) describe('without provider state', () => { it('creates Interaction when undefined', () => { const actual = new Interaction().given(undefined).json() - expect(actual).to.eql({ }) + expect(actual).to.eql({}) }) it('creates Interaction when blank', () => { const actual = new Interaction().given('').json() - expect(actual).to.eql({ }) + expect(actual).to.eql({}) }) it('creates Interaction when nothing is passed', () => { const actual = new Interaction().given().json() - expect(actual).to.eql({ }) + expect(actual).to.eql({}) }) }) }) @@ -55,7 +55,7 @@ describe('Interaction', () => { }) describe('with only mandatory params', () => { - const actual = new Interaction().withRequest({method: 'GET', path: '/search'}).json() + const actual = new Interaction().withRequest({ method: 'GET', path: '/search' }).json() it('has a state compacted with only present keys', () => { expect(actual).to.have.keys('request') diff --git a/test/pact.spec.js b/test/pact.spec.js index 3f4c6d839..36b116454 100644 --- a/test/pact.spec.js +++ b/test/pact.spec.js @@ -6,7 +6,7 @@ var proxyquire = require('proxyquire') describe('Pact', () => { - describe('#constructor', () => { + describe('#constructor', () => { let mockServiceSpy, Pact beforeEach(() => { @@ -48,7 +48,7 @@ describe('Pact', () => { }) - describe('#addInteraction', () => { + describe('#addInteraction', () => { let pact, Pact let port = 4567 @@ -73,10 +73,10 @@ describe('Pact', () => { willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, - body: { } + body: {} } }) - expect(addInteractionPromise).to.eventually.have.property('provider_state').notify(done) + expect(addInteractionPromise).to.eventually.have.property('providerState').notify(done) }) it('creates interaction without state', (done) => { @@ -90,10 +90,10 @@ describe('Pact', () => { willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, - body: { } + body: {} } }) - expect(addInteractionPromise).to.eventually.not.have.property('provider_state').notify(done) + expect(addInteractionPromise).to.eventually.not.have.property('providerState').notify(done) }) }) })