Skip to content

Commit

Permalink
add more default value test
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Nov 22, 2024
1 parent 5e211eb commit 19569fd
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions pkgs/sdk/server-ai/test/LdAiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,40 @@ public void ConfigNotEnabledReturnsDisabledInstance(string json)
Assert.False(tracker.Config.Enabled);
}

[Fact]
public void CanSetAllDefaultValueFields()
{
var mockClient = new Mock<ILaunchDarklyClient>();

var mockLogger = new Mock<ILogger>();

mockClient.Setup(x =>
x.JsonVariation("foo", It.IsAny<Context>(), It.IsAny<LdValue>())).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()
{
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 19569fd

Please sign in to comment.