From 19569fd40bc131001a3728e944a47a891997b05c Mon Sep 17 00:00:00 2001 From: Casey Waldren Date: Fri, 22 Nov 2024 12:56:47 -0800 Subject: [PATCH] add more default value test --- pkgs/sdk/server-ai/test/LdAiClientTest.cs | 42 ++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/pkgs/sdk/server-ai/test/LdAiClientTest.cs b/pkgs/sdk/server-ai/test/LdAiClientTest.cs index 15e2de6..3e848d6 100644 --- a/pkgs/sdk/server-ai/test/LdAiClientTest.cs +++ b/pkgs/sdk/server-ai/test/LdAiClientTest.cs @@ -101,6 +101,40 @@ public void ConfigNotEnabledReturnsDisabledInstance(string json) Assert.False(tracker.Config.Enabled); } + [Fact] + public void CanSetAllDefaultValueFields() + { + var mockClient = new Mock(); + + var mockLogger = new Mock(); + + mockClient.Setup(x => + x.JsonVariation("foo", It.IsAny(), It.IsAny())).Returns(LdValue.Null); + + mockClient.Setup(x => x.GetLogger()).Returns(mockLogger.Object); + + var client = new LdAiClient(mockClient.Object); + + var tracker = client.ModelConfig("foo", Context.New(ContextKind.Default, "key"), + LdAiConfig.New(). + AddMessage("foo"). + SetModelParam("foo", LdValue.Of("bar")). + SetCustomModelParam("foo", LdValue.Of("baz")). + SetModelProviderId("amazing-provider"). + SetEnabled(true).Build()); + + Assert.True(tracker.Config.Enabled); + Assert.Collection(tracker.Config.Messages, + message => + { + Assert.Equal("foo", message.Content); + Assert.Equal(Role.User, message.Role); + }); + Assert.Equal("amazing-provider", tracker.Config.Provider.Id); + Assert.Equal("bar", tracker.Config.Model.Parameters["foo"].AsString); + Assert.Equal("baz", tracker.Config.Model.Custom["foo"].AsString); + } + [Fact] public void ConfigEnabledReturnsInstance() { @@ -180,10 +214,10 @@ public void ModelParametersAreParsed() LdAiConfig.New().AddMessage("Goodbye!").Build()); Assert.Equal("model-foo", tracker.Config.Model.Id); - Assert.Equal(LdValue.Of("bar"), tracker.Config.Model.Parameters["foo"]); - Assert.Equal(LdValue.Of(42), tracker.Config.Model.Parameters["baz"]); - Assert.Equal(LdValue.Of("baz"), tracker.Config.Model.Custom["foo"]); - Assert.Equal(LdValue.Of(43), tracker.Config.Model.Custom["baz"]); + Assert.Equal("bar", tracker.Config.Model.Parameters["foo"].AsString); + Assert.Equal(42, tracker.Config.Model.Parameters["baz"].AsInt); + Assert.Equal("baz", tracker.Config.Model.Custom["foo"].AsString); + Assert.Equal(43, tracker.Config.Model.Custom["baz"].AsInt); } [Fact]