hmpo-form-wizard
Advanced tools
Comparing version 11.3.0 to 11.4.0
@@ -24,3 +24,4 @@ 'use strict'; | ||
wizardValues: null, | ||
rawSessionValues: null | ||
rawSessionValues: null, | ||
enumeratedDistribution: null | ||
}; | ||
@@ -45,2 +46,10 @@ | ||
'sessionKey': 'value' | ||
}, | ||
'enumeratedDistribution': { | ||
'ABJourney': { | ||
'probability': { | ||
'A': 10, | ||
'B': 90 | ||
} | ||
} | ||
} | ||
@@ -72,2 +81,4 @@ }; | ||
this.setRawSessionValues(req, options.rawSessionValues); | ||
this.setEnumeratedDistributions(req, options.enumeratedDistribution); | ||
} | ||
@@ -161,2 +172,9 @@ | ||
setEnumeratedDistributions(req, enumeratedDistributions) { | ||
debug('setEnumeratedDistributions', enumeratedDistributions); | ||
if (enumeratedDistributions) { | ||
req.session.enumeratedDistribution = _.extend({}, enumeratedDistributions); | ||
} | ||
} | ||
middlewareDecodePayload(req, res, next) { | ||
@@ -208,2 +226,3 @@ debug('middlewareDecodePayload'); | ||
res.locals.featureFlags = req.session.featureFlags; | ||
res.locals.enumeratedDistribution = req.session.enumeratedDistribution; | ||
res.locals.journeyKeys = _.omit(req.journeyModel.toJSON(), 'history', 'registered-models'); | ||
@@ -225,2 +244,3 @@ | ||
res.locals.featureFlags = toJSON(res.locals.featureFlags); | ||
res.locals.enumeratedDistribution = toJSON(res.locals.enumeratedDistribution); | ||
res.type('html'); | ||
@@ -230,3 +250,3 @@ return res.send(template(res.locals)); | ||
let currentStatus = _.pick(res.locals, 'featureFlags', 'journeyKeys', 'payload'); | ||
let currentStatus = _.pick(res.locals, 'featureFlags', 'journeyKeys', 'payload', 'enumeratedDistribution'); | ||
if (req.accepts('json')) { | ||
@@ -233,0 +253,0 @@ res.type('json'); |
{ | ||
"name": "hmpo-form-wizard", | ||
"version": "11.3.0", | ||
"version": "11.4.0", | ||
"description": "Routing and request handling for a multi-step form processes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,2 +25,3 @@ 'use strict'; | ||
sinon.stub(injection, 'setRawSessionValues'); | ||
sinon.stub(injection, 'setEnumeratedDistributions'); | ||
}); | ||
@@ -43,2 +44,3 @@ | ||
injection.setRawSessionValues.should.have.been.calledWithExactly(req, null); | ||
injection.setEnumeratedDistributions.should.have.been.calledWithExactly(req, null); | ||
}); | ||
@@ -57,2 +59,7 @@ | ||
it('calls setEnumeratedDistributions with enumerated distribution options', () => { | ||
injection.inject(req, { enumeratedDistribution: { AB: { probability: { A: 10, B: 90 }}}}); | ||
injection.setEnumeratedDistributions.should.have.been.calledWithExactly(req, { AB: { probability: { A: 10, B: 90 }}}); | ||
}); | ||
it('calls createJourneyModel with journey name from options', () => { | ||
@@ -103,2 +110,23 @@ injection.inject(req, { journeyName: 'my-journey' }); | ||
describe('#setEnumeratedDistributions', () => { | ||
it('sets enumerated distribution on the session', () => { | ||
injection.setEnumeratedDistributions(req, { AB: { probability: { A: 10, B: 90 }}}); | ||
req.session.enumeratedDistribution.AB.probability.A.should.equal(10); | ||
req.session.enumeratedDistribution.AB.probability.B.should.equal(90); | ||
}); | ||
it('overwrites any existing session enumerated distributions', () => { | ||
req.session.enumeratedDistribution = { AB: { probability: { A: 10, B: 90 }}}; | ||
injection.setEnumeratedDistributions(req, { implementation: { probability: { implA: 50, implB: 50 }}}); | ||
expect(req.session.enumeratedDistribution.AB).to.be.undefined; | ||
}); | ||
it('does not reset the enumerated distributions if no enumerated distributionss are given', () => { | ||
req.session.enumeratedDistribution = { AB: { probability: { A: 10, B: 90 }}}; | ||
injection.setEnumeratedDistributions(req, null); | ||
req.session.enumeratedDistribution.AB.probability.A.should.equal(10); | ||
req.session.enumeratedDistribution.AB.probability.B.should.equal(90); | ||
}); | ||
}); | ||
describe('#createJourneyModel', () => { | ||
@@ -448,2 +476,3 @@ it('creates a new journey model on req', () => { | ||
res.locals.journeyKeys = { key: 'value' }; | ||
res.locals.enumeratedDistribution = { AB: { probability: { A: 10, B: 90 }}}; | ||
}); | ||
@@ -457,2 +486,3 @@ | ||
res.locals.journeyKeys.should.equal('{\n key: \'value\',\n}'); | ||
res.locals.enumeratedDistribution.should.equal('{\n AB: {\n probability: {\n A: 10,\n B: 90,\n },\n },\n}'); | ||
res.type.should.have.been.calledWithExactly('html'); | ||
@@ -487,3 +517,4 @@ res.send.should.have.been.calledOnce; | ||
featureFlags: { flag: true }, | ||
journeyKeys: { key: 'value' } | ||
journeyKeys: { key: 'value' }, | ||
enumeratedDistribution: { AB: { probability: { A: 10, B: 90 }}} | ||
}); | ||
@@ -490,0 +521,0 @@ }); |
Sorry, the diff of this file is not supported yet
377524
8735