Skip to content

fix(track): Send decisions for all experiments using an event when using track #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
155 changes: 145 additions & 10 deletions OptimizelySDK.Tests/EventTests/EventBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class EventBuilderTest
{
private string TestUserId = string.Empty;
private ProjectConfig Config;

private EventBuilder EventBuilder;

[TestFixtureSetUp]
Expand Down Expand Up @@ -83,7 +84,7 @@ public void TestCreateImpressionEventNoAttributes()
}
}
},
{"attributes", new object[]
{"attributes", new object[]
{
new Dictionary<string, object>
{
Expand All @@ -107,7 +108,7 @@ public void TestCreateImpressionEventNoAttributes()
};

var expectedLogEvent = new LogEvent("https://logx.optimizely.com/v1/events",
payloadParams,
payloadParams,
"POST",
new Dictionary<string, string>
{
Expand Down Expand Up @@ -191,10 +192,10 @@ public void TestCreateImpressionEventWithAttributes()
{"revision", "15" },
{"anonymize_ip", false}
};

var expectedLogEvent = new LogEvent("https://logx.optimizely.com/v1/events",
payloadParams,
"POST",
"POST",
new Dictionary<string, string>
{
{ "Content-Type", "application/json" }
Expand Down Expand Up @@ -255,7 +256,7 @@ public void TestCreateConversionEventNoAttributesNoValue()
}
},
{"visitor_id", TestUserId },
{"attributes", new object[]
{"attributes", new object[]
{
new Dictionary<string, object>
{
Expand All @@ -276,7 +277,7 @@ public void TestCreateConversionEventNoAttributesNoValue()
{"revision", "15" },
{"anonymize_ip", false}
};

var expectedEvent = new LogEvent(
"https://logx.optimizely.com/v1/events",
payloadParams,
Expand All @@ -302,7 +303,7 @@ public void TestCreateConversionEventWithAttributesNoValue()
{
var guid = Guid.NewGuid();
var timeStamp = TestData.SecondsSince1970();

var payloadParams = new Dictionary<string, object>
{
{"visitors", new object[]
Expand Down Expand Up @@ -597,7 +598,7 @@ public void TestCreateConversionEventWithAttributesWithValue()

Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent));
}

[Test]
public void TestCreateConversionEventNoAttributesWithInvalidValue()
{
Expand Down Expand Up @@ -668,7 +669,7 @@ public void TestCreateConversionEventNoAttributesWithInvalidValue()
{"revision", "15" },
{"anonymize_ip", false}
};

var expectedEvent = new LogEvent(
"https://logx.optimizely.com/v1/events",
payloadParams,
Expand Down Expand Up @@ -989,7 +990,7 @@ public void TestCreateImpressionEventWithBucketingIDAttribute()
{ "company", "Optimizely" },
{ControlAttributes.BUCKETING_ID_ATTRIBUTE, "variation" }
};

var logEvent = EventBuilder.CreateImpressionEvent(Config, Config.GetExperimentFromKey("test_experiment"), "7722370027", TestUserId, userAttributes);

TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid);
Expand Down Expand Up @@ -1362,5 +1363,139 @@ public void TestCreateConversionEventWhenBotFilteringIsNotProvidedInDatafile()

Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent));
}

[Test]
public void TestCreateConversionEventWhenEventUsedInMultipleExp()
{
var guid = Guid.NewGuid();
var timeStamp = TestData.SecondsSince1970();

var eventInMultiExperimentConfig = ProjectConfig.Create(TestData.SimpleABExperimentsDatafile, new NoOpLogger(), new ErrorHandler.NoOpErrorHandler());

var experimentIdVariationMap = new Dictionary<string, Variation>
{
{
"111127", new Variation{Id="111129", Key="variation"}
},
{
"111130", new Variation{Id="111131", Key="variation"}
}
};

var logEvent = EventBuilder.CreateConversionEvent(eventInMultiExperimentConfig, "event_with_multiple_running_experiments", experimentIdVariationMap, "test_user",
new UserAttributes {
{"test_attribute", "test_value"}
},
new EventTags {
{"revenue", 4200},
{"value", 1.234},
{"non-revenue", "abc"}
});

var payloadParams = new Dictionary<string, object>
{
{"client_version", Optimizely.SDK_VERSION},
{"project_id", "111001"},
//{"visitor_id", "test_user"},
{"account_id", "12001"},
{"client_name", "csharp-sdk"},
{"anonymize_ip", false},
{"revision", eventInMultiExperimentConfig.Revision},
{"visitors", new object[]
{
//visitors[0]
new Dictionary<string, object>
{
//visitors[0].attributes
{
"attributes", new object[]
{
new Dictionary<string, string>
{
{"entity_id", "111094"},
{"type", "custom"},
{"value", "test_value"},
{"key", "test_attribute"}
}
}
},
//visitors[0].visitor_id
{"visitor_id", "test_user"},
//visitors[0].snapshots
{"snapshots", new object[]
{
//snapshots[0]
new Dictionary<string, object>
{
//snapshots[0].decisions
{"decisions", new object[]
{
//decisions[0]
new Dictionary<string, object>
{
{"variation_id", "111129"},
{"experiment_id", "111127"},
{"campaign_id", "111182"}

},
//decisions[1]
new Dictionary<string,object>
{
{"experiment_id", "111130"},
{"variation_id", "111131"},
{"campaign_id", "111182"}
}
}
},
//snapshots[0].events
{
"events", new object[]
{
new Dictionary<string, object>
{
{"uuid", guid},
{"timestamp", timeStamp},
{"revenue", 4200},
{"value", 1.234},
{"key", "event_with_multiple_running_experiments"},
{"entity_id", "111095"},
{
"tags", new Dictionary<string, object>
{
{"non-revenue", "abc"},
{"revenue", 4200},
{"value", 1.234},
}
}

}
}
}

}

}
}

}
}

}
};


var expectedLogEvent = new LogEvent(
"https://logx.optimizely.com/v1/events",
payloadParams,
"POST",
new Dictionary<string, string>
{
{ "Content-Type", "application/json"}
});

TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid);

Assert.IsTrue(TestData.CompareObjects(expectedLogEvent, logEvent));
}
}
}
Loading