@@ -183,9 +183,13 @@ describe('/account/device', function () {
183183describe ( '/account/devices/notify' , function ( ) {
184184 var config = { }
185185 var uid = uuid . v4 ( 'binary' )
186+ var deviceId = crypto . randomBytes ( 16 )
187+ var mockLog = mocks . spyLog ( )
186188 var mockRequest = mocks . mockRequest ( {
189+ log : mockLog ,
187190 credentials : {
188- uid : uid . toString ( 'hex' )
191+ uid : uid ,
192+ deviceId : deviceId
189193 }
190194 } )
191195 var pushPayload = {
@@ -253,7 +257,7 @@ describe('/account/devices/notify', function () {
253257 assert . equal ( mockPush . pushToAllDevices . callCount , 1 , 'mockPush.pushToAllDevices was called once' )
254258 var args = mockPush . pushToAllDevices . args [ 0 ]
255259 assert . equal ( args . length , 3 , 'mockPush.pushToAllDevices was passed three arguments' )
256- assert . equal ( args [ 0 ] , uid . toString ( 'hex' ) , 'first argument was the device uid' )
260+ assert . equal ( args [ 0 ] , uid , 'first argument was the device uid' )
257261 assert . equal ( args [ 1 ] , 'devicesNotify' , 'second argument was the devicesNotify reason' )
258262 assert . deepEqual ( args [ 2 ] , {
259263 data : Buffer . from ( JSON . stringify ( pushPayload ) ) ,
@@ -266,6 +270,8 @@ describe('/account/devices/notify', function () {
266270
267271 it ( 'specific devices' , function ( ) {
268272 mockCustoms . checkAuthenticated . reset ( )
273+ mockLog . activityEvent . reset ( )
274+ mockLog . error . reset ( )
269275 mockRequest . payload = {
270276 to : [ 'bogusid1' , 'bogusid2' ] ,
271277 TTL : 60 ,
@@ -284,17 +290,48 @@ describe('/account/devices/notify', function () {
284290 assert . equal ( mockPush . pushToDevices . callCount , 1 , 'mockPush.pushToDevices was called once' )
285291 var args = mockPush . pushToDevices . args [ 0 ]
286292 assert . equal ( args . length , 4 , 'mockPush.pushToDevices was passed four arguments' )
287- assert . equal ( args [ 0 ] , uid . toString ( 'hex' ) , 'first argument was the device uid' )
293+ assert . equal ( args [ 0 ] , uid , 'first argument was the device uid' )
288294 assert . deepEqual ( args [ 1 ] , [ 'bogusid1' , 'bogusid2' ] , 'second argument was the list of device ids' )
289295 assert . equal ( args [ 2 ] , 'devicesNotify' , 'third argument was the devicesNotify reason' )
290296 assert . deepEqual ( args [ 3 ] , {
291297 data : Buffer . from ( JSON . stringify ( pushPayload ) ) ,
292298 TTL : 60
293299 } , 'fourth argument was the push options' )
300+ assert . equal ( mockLog . activityEvent . callCount , 1 , 'log.activityEvent was called once' )
301+ args = mockLog . activityEvent . args [ 0 ]
302+ assert . equal ( args . length , 1 , 'log.activityEvent was passed one argument' )
303+ assert . deepEqual ( args [ 0 ] , {
304+ event : 'sync.sentTabToDevice' ,
305+ service : 'sync' ,
306+ userAgent : 'test user-agent' ,
307+ uid : uid . toString ( 'hex' ) ,
308+ device_id : deviceId . toString ( 'hex' )
309+ } , 'event data was correct' )
310+ assert . equal ( mockLog . error . callCount , 0 , 'log.error was not called' )
294311 } )
295312 } )
296313 } )
297314
315+ it ( 'does not log activity event for non-send-tab-related messages' , function ( ) {
316+ mockPush . pushToDevices . reset ( )
317+ mockLog . activityEvent . reset ( )
318+ mockLog . error . reset ( )
319+ mockRequest . payload = {
320+ to : [ 'bogusid1' , 'bogusid2' ] ,
321+ TTL : 60 ,
322+ payload : {
323+ isValid : true ,
324+ version : 1 ,
325+ command : 'fxaccounts:password_reset'
326+ }
327+ }
328+ return runTest ( route , mockRequest , function ( response ) {
329+ assert . equal ( mockPush . pushToDevices . callCount , 1 , 'mockPush.pushToDevices was called once' )
330+ assert . equal ( mockLog . activityEvent . callCount , 0 , 'log.activityEvent was not called' )
331+ assert . equal ( mockLog . error . callCount , 0 , 'log.error was not called' )
332+ } )
333+ } )
334+
298335 it ( 'device driven notifications disabled' , function ( ) {
299336 config . deviceNotificationsEnabled = false
300337 mockRequest . payload = {
@@ -367,7 +404,7 @@ describe('/account/device/destroy', function () {
367404 var mockDB = mocks . mockDB ( )
368405 var mockRequest = mocks . mockRequest ( {
369406 credentials : {
370- uid : uid . toString ( 'hex' ) ,
407+ uid : uid
371408 } ,
372409 log : mockLog ,
373410 payload : {
@@ -406,7 +443,7 @@ describe('/account/device/destroy', function () {
406443 assert . equal ( args [ 0 ] , 'device:delete' )
407444 assert . equal ( args [ 1 ] , mockRequest )
408445 var details = args [ 2 ]
409- assert . equal ( details . uid , uid . toString ( 'hex' ) )
446+ assert . equal ( details . uid , uid )
410447 assert . equal ( details . id , deviceId )
411448 assert . ok ( Date . now ( ) - details . timestamp < 100 )
412449 } )
0 commit comments