@@ -32,6 +32,7 @@ registerSuite('flow-event', {
3232 flowMetrics : {
3333 validate : sandbox . spy ( ( ) => flowMetricsValidateResult )
3434 } ,
35+ geolocate : sandbox . spy ( ( ) => ( { country : 'United States' , state : 'California' } ) ) ,
3536 request : {
3637 headers : {
3738 'user-agent' : 'bar'
@@ -43,7 +44,8 @@ registerSuite('flow-event', {
4344 flowEvent = proxyquire ( path . resolve ( 'server/lib/flow-event' ) , {
4445 './amplitude' : mocks . amplitude ,
4546 './configuration' : mocks . config ,
46- './flow-metrics' : mocks . flowMetrics
47+ './flow-metrics' : mocks . flowMetrics ,
48+ './geo-locate' : mocks . geolocate
4749 } ) . metricsRequest ;
4850 } ,
4951
@@ -88,6 +90,7 @@ registerSuite('flow-event', {
8890 assert . deepEqual ( JSON . parse ( args [ 0 ] ) , {
8991 /*eslint-disable camelcase*/
9092 context : 'fx_desktop_v3' ,
93+ country : 'United States' ,
9194 entrypoint : 'menupanel' ,
9295 event : 'flow.begin' ,
9396 flow_id : '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ,
@@ -97,6 +100,7 @@ registerSuite('flow-event', {
97100 migration : 'amo' ,
98101 op : 'flowEvent' ,
99102 pid : process . pid ,
103+ region : 'California' ,
100104 service : '1234567890abcdef' ,
101105 time : new Date ( mocks . time - 1000 ) . toISOString ( ) ,
102106 userAgent : mocks . request . headers [ 'user-agent' ] ,
@@ -111,22 +115,22 @@ registerSuite('flow-event', {
111115
112116 'second call to process.stderr.write was correct' : ( ) => {
113117 const arg = JSON . parse ( process . stderr . write . args [ 1 ] [ 0 ] ) ;
114- assert . lengthOf ( Object . keys ( arg ) , 18 ) ;
118+ assert . lengthOf ( Object . keys ( arg ) , 20 ) ;
115119 assert . equal ( arg . event , 'flow.signup.view' ) ;
116120 assert . equal ( arg . flow_time , 5 ) ;
117121 assert . equal ( arg . time , new Date ( mocks . time - 995 ) . toISOString ( ) ) ;
118122 } ,
119123
120124 'third call to process.stderr.write was correct' : ( ) => {
121125 const arg = JSON . parse ( process . stderr . write . args [ 2 ] [ 0 ] ) ;
122- assert . lengthOf ( Object . keys ( arg ) , 18 ) ;
126+ assert . lengthOf ( Object . keys ( arg ) , 20 ) ;
123127 assert . equal ( arg . event , 'flow.signup.good-offset-now' ) ;
124128 assert . equal ( arg . time , new Date ( mocks . time ) . toISOString ( ) ) ;
125129 } ,
126130
127131 'fourth call to process.stderr.write was correct' : ( ) => {
128132 const arg = JSON . parse ( process . stderr . write . args [ 3 ] [ 0 ] ) ;
129- assert . lengthOf ( Object . keys ( arg ) , 18 ) ;
133+ assert . lengthOf ( Object . keys ( arg ) , 20 ) ;
130134 assert . equal ( arg . event , 'flow.signup.good-offset-oldest' ) ;
131135 assert . equal ( arg . time , new Date ( mocks . time - config . flow_id_expiry ) . toISOString ( ) ) ;
132136 } ,
@@ -159,6 +163,10 @@ registerSuite('flow-event', {
159163 type : 'wibble'
160164 } ) ;
161165 assert . equal ( args [ 1 ] , mocks . request ) ;
166+ assert . deepEqual ( args [ 2 ] . location , {
167+ country : 'United States' ,
168+ state : 'California'
169+ } ) ;
162170 mocks . amplitude . firstCall . calledBefore ( process . stderr . write . firstCall ) ;
163171 } ,
164172
@@ -799,7 +807,7 @@ registerSuite('flow-event', {
799807 'process.stderr.write was called correctly' : ( ) => {
800808 assert . equal ( process . stderr . write . callCount , 1 ) ;
801809 const arg = JSON . parse ( process . stderr . write . args [ 0 ] [ 0 ] ) ;
802- assert . lengthOf ( Object . keys ( arg ) , 17 ) ;
810+ assert . lengthOf ( Object . keys ( arg ) , 19 ) ;
803811 assert . isUndefined ( arg . utm_campaign ) ; //eslint-disable-line camelcase
804812 }
805813 }
@@ -816,7 +824,7 @@ registerSuite('flow-event', {
816824 'process.stderr.write was called correctly' : ( ) => {
817825 assert . equal ( process . stderr . write . callCount , 1 ) ;
818826 const arg = JSON . parse ( process . stderr . write . args [ 0 ] [ 0 ] ) ;
819- assert . lengthOf ( Object . keys ( arg ) , 17 ) ;
827+ assert . lengthOf ( Object . keys ( arg ) , 19 ) ;
820828 assert . isUndefined ( arg . utm_content ) ; //eslint-disable-line camelcase
821829 }
822830 }
@@ -833,7 +841,7 @@ registerSuite('flow-event', {
833841 'process.stderr.write was called correctly' : ( ) => {
834842 assert . equal ( process . stderr . write . callCount , 1 ) ;
835843 const arg = JSON . parse ( process . stderr . write . args [ 0 ] [ 0 ] ) ;
836- assert . lengthOf ( Object . keys ( arg ) , 17 ) ;
844+ assert . lengthOf ( Object . keys ( arg ) , 19 ) ;
837845 assert . isUndefined ( arg . utm_medium ) ; //eslint-disable-line camelcase
838846 }
839847 }
@@ -850,7 +858,7 @@ registerSuite('flow-event', {
850858 'process.stderr.write was called correctly' : ( ) => {
851859 assert . equal ( process . stderr . write . callCount , 1 ) ;
852860 const arg = JSON . parse ( process . stderr . write . args [ 0 ] [ 0 ] ) ;
853- assert . lengthOf ( Object . keys ( arg ) , 17 ) ;
861+ assert . lengthOf ( Object . keys ( arg ) , 19 ) ;
854862 assert . isUndefined ( arg . utm_source ) ; //eslint-disable-line camelcase
855863 }
856864 }
0 commit comments