Skip to content

Commit

Permalink
fix(providerstate): make providerState serialisation spec compliant #12
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed May 11, 2017
1 parent a74b730 commit cc44554
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/dsl/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
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 {

/**
* Creates a new Interaction.
* @returns {Interaction} interaction
*/
constructor () {
constructor() {
this.state = {}
return this
}
Expand All @@ -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
}
Expand All @@ -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.')
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -112,7 +112,7 @@ module.exports = class Interaction {
* Returns the interaction object created.
* @returns {Object}
*/
json () {
json() {
return this.state
}
}
10 changes: 5 additions & 5 deletions test/dsl/interaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
})
})
})
Expand Down Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions test/pact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var proxyquire = require('proxyquire')

describe('Pact', () => {

describe('#constructor', () => {
describe('#constructor', () => {
let mockServiceSpy, Pact

beforeEach(() => {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('Pact', () => {

})

describe('#addInteraction', () => {
describe('#addInteraction', () => {
let pact, Pact
let port = 4567

Expand All @@ -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) => {
Expand All @@ -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)
})
})
})

0 comments on commit cc44554

Please sign in to comment.