File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,9 @@ export default class UserData {
1717 json ( ) {
1818 const verificationSecret = this . getVerificationSecret ( ) ;
1919 const identifier = this . getIdentifier ( ) ;
20- this . setUserHash ( verificationSecret , identifier ) ;
20+ if ( this . settings . user_hash === undefined ) {
21+ this . setUserHash ( verificationSecret , identifier ) ;
22+ }
2123 return this . escapedSettings ( this . settings ) ;
2224 }
2325 getVerificationSecret ( ) {
@@ -41,6 +43,7 @@ export default class UserData {
4143 secretKey : verificationSecret ,
4244 identifier
4345 } ) ;
46+
4447 this . settings . user_hash = userHash ;
4548 }
4649 escapedSettings ( settings ) {
Original file line number Diff line number Diff line change 1919 ],
2020 "dependencies" : {
2121 "bluebird" : " ^3.3.4" ,
22+ "htmlencode" : " ^0.0.4" ,
2223 "request" : " ^2.83.0" ,
23- "htmlencode " : " ^0.0.4 "
24+ "sinon " : " ^4.1.3 "
2425 },
2526 "devDependencies" : {
2627 "babel-core" : " ^6.7.4" ,
Original file line number Diff line number Diff line change 11import UserData from '../lib/user-data' ;
22import assert from 'assert' ;
3+ import sinon from 'sinon' ;
34
45describe ( 'userData' , ( ) => {
56 it ( 'should be able to grab the verification secret' , ( ) => {
@@ -110,6 +111,20 @@ describe('userData', () => {
110111 assert . equal ( Object . keys ( result ) . indexOf ( settings . verificationSecret ) , - 1 ) ;
111112 } ) ;
112113
114+ it ( 'should skip setUserHash if user_hash is already defined' , ( ) => {
115+ const settings = {
116+ verificationSecret : 'abc123' ,
117+ app_id : 'xyz789' ,
118+ user_id : 1
119+ } ;
120+ const userData = new UserData ( settings ) ;
121+ const setUserHash = sinon . spy ( userData , 'setUserHash' ) ;
122+ userData . json ( ) ;
123+ userData . json ( ) ;
124+ setUserHash . restore ( ) ;
125+ sinon . assert . calledOnce ( setUserHash ) ;
126+ } ) ;
127+
113128 it ( 'should return the userData' , ( ) => {
114129 const settings = {
115130 verificationSecret : 'abc123' ,
You can’t perform that action at this time.
0 commit comments