Skip to content

Commit cc44554

Browse files
committed
fix(providerstate): make providerState serialisation spec compliant #12
1 parent a74b730 commit cc44554

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/dsl/interaction.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
const omitBy = require('lodash.omitby')
99
const isNil = require('lodash.isnil')
1010

11-
const VALID_METHODS = [ 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS' ]
11+
const VALID_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
1212

1313
module.exports = class Interaction {
1414

1515
/**
1616
* Creates a new Interaction.
1717
* @returns {Interaction} interaction
1818
*/
19-
constructor () {
19+
constructor() {
2020
this.state = {}
2121
return this
2222
}
@@ -26,9 +26,9 @@ module.exports = class Interaction {
2626
* @param {string} providerState - The state of the provider.
2727
* @returns {Interaction} interaction
2828
*/
29-
given (providerState) {
29+
given(providerState) {
3030
if (providerState) {
31-
this.state['provider_state'] = providerState
31+
this.state['providerState'] = providerState
3232
}
3333
return this
3434
}
@@ -38,7 +38,7 @@ module.exports = class Interaction {
3838
* @param {string} description - A description of the interaction.
3939
* @returns {Interaction} interaction
4040
*/
41-
uponReceiving (description) {
41+
uponReceiving(description) {
4242
if (isNil(description)) {
4343
throw new Error('You must provide a description for the interaction.')
4444
}
@@ -56,7 +56,7 @@ module.exports = class Interaction {
5656
* @param {Object} requestOpts.body - The body, in {@link String} format or {@link Object} format
5757
* @returns {Interaction} interaction
5858
*/
59-
withRequest (requestOpts) {
59+
withRequest(requestOpts) {
6060
var method = requestOpts.method
6161
var path = requestOpts.path
6262
var query = requestOpts.query
@@ -92,7 +92,7 @@ module.exports = class Interaction {
9292
* @param {string} responseOpts.headers
9393
* @param {Object} responseOpts.body
9494
*/
95-
willRespondWith (responseOpts) {
95+
willRespondWith(responseOpts) {
9696
var status = responseOpts.status
9797
var headers = responseOpts.headers
9898
var body = responseOpts.body
@@ -112,7 +112,7 @@ module.exports = class Interaction {
112112
* Returns the interaction object created.
113113
* @returns {Object}
114114
*/
115-
json () {
115+
json() {
116116
return this.state
117117
}
118118
}

test/dsl/interaction.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ describe('Interaction', () => {
55
describe('#given', () => {
66
it('creates Interaction with provider state', () => {
77
const actual = new Interaction().given('provider state').json()
8-
expect(actual).to.eql({ provider_state: 'provider state' })
8+
expect(actual).to.eql({ providerState: 'provider state' })
99
})
1010

1111
describe('without provider state', () => {
1212
it('creates Interaction when undefined', () => {
1313
const actual = new Interaction().given(undefined).json()
14-
expect(actual).to.eql({ })
14+
expect(actual).to.eql({})
1515
})
1616

1717
it('creates Interaction when blank', () => {
1818
const actual = new Interaction().given('').json()
19-
expect(actual).to.eql({ })
19+
expect(actual).to.eql({})
2020
})
2121

2222
it('creates Interaction when nothing is passed', () => {
2323
const actual = new Interaction().given().json()
24-
expect(actual).to.eql({ })
24+
expect(actual).to.eql({})
2525
})
2626
})
2727
})
@@ -55,7 +55,7 @@ describe('Interaction', () => {
5555
})
5656

5757
describe('with only mandatory params', () => {
58-
const actual = new Interaction().withRequest({method: 'GET', path: '/search'}).json()
58+
const actual = new Interaction().withRequest({ method: 'GET', path: '/search' }).json()
5959

6060
it('has a state compacted with only present keys', () => {
6161
expect(actual).to.have.keys('request')

test/pact.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var proxyquire = require('proxyquire')
66

77
describe('Pact', () => {
88

9-
describe('#constructor', () => {
9+
describe('#constructor', () => {
1010
let mockServiceSpy, Pact
1111

1212
beforeEach(() => {
@@ -48,7 +48,7 @@ describe('Pact', () => {
4848

4949
})
5050

51-
describe('#addInteraction', () => {
51+
describe('#addInteraction', () => {
5252
let pact, Pact
5353
let port = 4567
5454

@@ -73,10 +73,10 @@ describe('Pact', () => {
7373
willRespondWith: {
7474
status: 200,
7575
headers: { 'Content-Type': 'application/json' },
76-
body: { }
76+
body: {}
7777
}
7878
})
79-
expect(addInteractionPromise).to.eventually.have.property('provider_state').notify(done)
79+
expect(addInteractionPromise).to.eventually.have.property('providerState').notify(done)
8080
})
8181

8282
it('creates interaction without state', (done) => {
@@ -90,10 +90,10 @@ describe('Pact', () => {
9090
willRespondWith: {
9191
status: 200,
9292
headers: { 'Content-Type': 'application/json' },
93-
body: { }
93+
body: {}
9494
}
9595
})
96-
expect(addInteractionPromise).to.eventually.not.have.property('provider_state').notify(done)
96+
expect(addInteractionPromise).to.eventually.not.have.property('providerState').notify(done)
9797
})
9898
})
9999
})

0 commit comments

Comments
 (0)