Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAustin Schaffer <austin.schaffer@ryansg.com>2020-02-18 14:39:46 -0500
committerAustin Schaffer <austin.schaffer@ryansg.com>2020-02-18 14:39:46 -0500
commit200ae99ce504909e19c1a7173c01cbfe02150742 (patch)
tree496e86bf79c51c88929d53dc7ca5d23d47d410e9
parent845c9771726559122e9c427098583c2a3c1bf722 (diff)
parent69acaa2d7c150187e1a8dc2f0289e7ffe53297cd (diff)
downloadliza-200ae99ce504909e19c1a7173c01cbfe02150742.tar.gz
liza-200ae99ce504909e19c1a7173c01cbfe02150742.tar.bz2
liza-200ae99ce504909e19c1a7173c01cbfe02150742.zip
Access bucket data during rate event
-rw-r--r--src/client/event/RateEventHandler.js2
-rw-r--r--test/client/event/RateEventHandlerTest.js175
2 files changed, 176 insertions, 1 deletions
diff --git a/src/client/event/RateEventHandler.js b/src/client/event/RateEventHandler.js
index b311a51..f8a9646 100644
--- a/src/client/event/RateEventHandler.js
+++ b/src/client/event/RateEventHandler.js
@@ -98,7 +98,7 @@ module.exports = Class( 'RateEventHandler' )
var qstep = quote.getCurrentStepId();
// arbitrary delay before rating (use as a last resort)
- var delay = ( typeof +data.value === 'number' )
+ var delay = ( !isNaN( data.value ) )
? data.value * 1e3
: 0;
diff --git a/test/client/event/RateEventHandlerTest.js b/test/client/event/RateEventHandlerTest.js
index f85a360..97502fb 100644
--- a/test/client/event/RateEventHandlerTest.js
+++ b/test/client/event/RateEventHandlerTest.js
@@ -114,6 +114,181 @@ describe( 'RateEventHandler', () =>
} )
} );
+ describe( "Handles rating delay", () =>
+ {
+ it( "uses a number to determine rating delay", done =>
+ {
+ let set_timeout_called = false;
+ let actual_delay = 0;
+
+ const delay = '25';
+ const expected_delay = 25000;
+
+ const quote = {
+ getExplicitLockStep: () => 0,
+ setLastPremiumDate: () => {},
+ setInitialRatedDate: () => {},
+ getCurrentStepId: () => 1,
+ refreshData: () => {},
+ isLocked: () => {},
+ getId: () => "111111"
+ };
+
+ const client = {
+ uiDialog: {
+ showRatingInProgressDialog: () =>
+ {
+ return { close: () => {} }
+ },
+ },
+ showRatingInProgressDialog: () => "Some Dialog",
+ getQuote: () => quote,
+ isSaving: () => false,
+ once: ( _, __ ) => {},
+ getUi: () =>
+ {
+ return {
+ getStep: ( _ ) =>
+ {
+ return { invalidate: () => {} }
+ }
+ }
+ },
+ getDataByName: ( name ) => { return [ 'foo' ]; },
+ };
+
+ const proxy = {
+ get: ( url, callback ) => callback(
+ {
+ content: {
+ data: "Some Data",
+ initialRatedDate: 111,
+ lastRatedDate: 222
+ }
+ },
+ null
+ )
+ };
+
+ const sut = Sut( client, proxy );
+
+ const old_setTimeout = setTimeout;
+
+ setTimeout = ( callback, delay ) => {
+ set_timeout_called = true;
+ actual_delay = delay;
+
+ callback.apply( this, arguments );
+ }
+
+ sut.handle(
+ "",
+ ( _, __ ) => {},
+ {
+ indv: 'somerater',
+ stepId: 1,
+ value: delay
+ }
+ );
+
+ setTimeout = old_setTimeout;
+
+ expect( set_timeout_called ).to.equal( true );
+ expect( actual_delay ).to.equal( expected_delay );
+ done();
+ } )
+
+
+ it( "rating delay defaults to zero", done =>
+ {
+ let set_timeout_called = false;
+ let actual_delay = 0;
+
+ const delay = 'foo';
+ const expected_delay = 0;
+
+ const quote = {
+ getExplicitLockStep: () => 0,
+ setLastPremiumDate: () => {},
+ setInitialRatedDate: () => {},
+ getCurrentStepId: () => 1,
+ refreshData: () => {},
+ isLocked: () => {},
+ getId: () => "111111"
+ };
+
+ const client = {
+ uiDialog: {
+ showRatingInProgressDialog: () =>
+ {
+ return { close: () => {} }
+ },
+ },
+ showRatingInProgressDialog: () => "Some Dialog",
+ getQuote: () => quote,
+ isSaving: () => false,
+ once: ( _, __ ) => {},
+ getUi: () =>
+ {
+ return {
+ getStep: ( _ ) =>
+ {
+ return { invalidate: () => {} }
+ }
+ }
+ },
+ };
+
+ const proxy = {
+ get: ( url, callback ) => callback(
+ {
+ content: {
+ data: "Some Data",
+ initialRatedDate: 111,
+ lastRatedDate: 222
+ }
+ },
+ null
+ )
+ };
+
+ const sut = Sut( client, proxy );
+
+ const old_setTimeout = setTimeout;
+
+ setTimeout = ( callback, delay ) => {
+ set_timeout_called = true;
+ actual_delay = delay;
+
+ callback.apply( this, arguments );
+ }
+
+ // this is necessary because if something breaks here, setTimeout
+ // will not be restored and will yield a false negative on other
+ // tests
+ try {
+ sut.handle(
+ "",
+ ( _, __ ) => {},
+ {
+ indv: 'somerater',
+ stepId: 1,
+ value: delay
+ }
+ );
+ }
+ catch( e ) {}
+ finally
+ {
+ setTimeout = old_setTimeout;
+ }
+
+ expect( set_timeout_called ).to.equal( true );
+ expect( actual_delay ).to.equal( expected_delay );
+ done();
+ } )
+ } );
+
describe( "Handle Rating Event with locked quote", () =>
{
it( "calls #handle to do the rating with a locked quote", done =>