Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/event/dispatcher_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2019-2020, Optimizely, Inc. and contributors *
* Copyright 2019-2020,2022 Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -120,6 +120,7 @@ func TestQueueEventDispatcher_DispatchEvent(t *testing.T) {
conversionUserEvent := CreateConversionUserEvent(config, entities.Event{ExperimentIds: []string{"15402980349"}, ID: "15368860886", Key: "sample_conversion"}, userContext, eventTags)

batch := createBatchEvent(conversionUserEvent, createVisitorFromUserEvent(conversionUserEvent))
assert.Equal(t, conversionUserEvent.Timestamp, batch.Visitors[0].Snapshots[0].Events[0].Timestamp)

logEvent := createLogEvent(batch, DefaultEventEndPoint)

Expand Down Expand Up @@ -178,6 +179,7 @@ func TestQueueEventDispatcher_FailDispath(t *testing.T) {
conversionUserEvent := CreateConversionUserEvent(config, entities.Event{ExperimentIds: []string{"15402980349"}, ID: "15368860886", Key: "sample_conversion"}, userContext, eventTags)

batch := createBatchEvent(conversionUserEvent, createVisitorFromUserEvent(conversionUserEvent))
assert.Equal(t, conversionUserEvent.Timestamp, batch.Visitors[0].Snapshots[0].Events[0].Timestamp)

logEvent := createLogEvent(batch, DefaultEventEndPoint)

Expand Down
4 changes: 2 additions & 2 deletions pkg/event/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func createImpressionVisitor(userEvent UserEvent) Visitor {
decision.Metadata = userEvent.Impression.Metadata

dispatchEvent := SnapshotEvent{}
dispatchEvent.Timestamp = makeTimestamp()
dispatchEvent.Timestamp = userEvent.Timestamp
dispatchEvent.Key = userEvent.Impression.Key
dispatchEvent.EntityID = userEvent.Impression.EntityID
dispatchEvent.UUID = guuid.New().String()
Expand Down Expand Up @@ -189,7 +189,7 @@ func createVisitorFromUserEvent(event UserEvent) Visitor {
func createConversionVisitor(userEvent UserEvent) Visitor {

dispatchEvent := SnapshotEvent{}
dispatchEvent.Timestamp = makeTimestamp()
dispatchEvent.Timestamp = userEvent.Timestamp
dispatchEvent.Key = userEvent.Conversion.Key
dispatchEvent.EntityID = userEvent.Conversion.EntityID
dispatchEvent.UUID = userEvent.UUID
Expand Down
7 changes: 7 additions & 0 deletions pkg/event/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func BuildTestConversionEvent() UserEvent {
return conversionUserEvent
}

func TestVisitorTimestampMatchesUserEventTimestamp(t *testing.T) {
impressionUserEvent := BuildTestImpressionEvent()
visitor := createVisitorFromUserEvent(impressionUserEvent)
assert.Equal(t, impressionUserEvent.Timestamp, visitor.Snapshots[0].Events[0].Timestamp)
}

func TestCreateEmptyEvent(t *testing.T) {
impressionUserEvent := BuildTestImpressionEvent()

Expand Down Expand Up @@ -177,6 +183,7 @@ func TestCreateConversionEventRevenue(t *testing.T) {
assert.Equal(t, 25.1, *conversionUserEvent.Conversion.Value)

batch := createBatchEvent(conversionUserEvent, createVisitorFromUserEvent(conversionUserEvent))
assert.Equal(t, conversionUserEvent.Timestamp, batch.Visitors[0].Snapshots[0].Events[0].Timestamp)
assert.Equal(t, int64(55), *batch.Visitors[0].Snapshots[0].Events[0].Revenue)
assert.Equal(t, 25.1, *batch.Visitors[0].Snapshots[0].Events[0].Value)

Expand Down