github.com/prebid/prebid-server/v2@v2.18.0/hooks/hookanalytics/analytics_test.go (about) 1 package hookanalytics 2 3 import ( 4 "testing" 5 6 "github.com/prebid/prebid-server/v2/util/jsonutil" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestAnalytics(t *testing.T) { 11 expectedAnalytics := []byte(` 12 { 13 "activities": [ 14 { 15 "name": "device-id", 16 "status": "success", 17 "results": [ 18 { 19 "status": "success-allow", 20 "values": { 21 "foo": "bar" 22 }, 23 "appliedto": { 24 "impids": [ 25 "impId1" 26 ], 27 "request": true 28 } 29 } 30 ] 31 }, 32 { 33 "name": "define-blocks", 34 "status": "error" 35 } 36 ] 37 } 38 `) 39 40 result := Result{Status: ResultStatusAllow, Values: map[string]interface{}{"foo": "bar"}} 41 result.AppliedTo = AppliedTo{ImpIds: []string{"impId1"}, Request: true} 42 43 activity := Activity{Name: "device-id", Status: ActivityStatusSuccess} 44 activity.Results = append(activity.Results, result) 45 46 analytics := Analytics{} 47 analytics.Activities = append( 48 analytics.Activities, 49 activity, 50 Activity{Name: "define-blocks", Status: ActivityStatusError}, 51 ) 52 53 gotAnalytics, err := jsonutil.Marshal(analytics) 54 assert.NoError(t, err, "Failed to marshal analytics: %s", err) 55 assert.JSONEq(t, string(expectedAnalytics), string(gotAnalytics)) 56 }