107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
using Jibo.Cloud.Application.Services;
|
|
using Jibo.Cloud.Infrastructure.Content;
|
|
using Jibo.Runtime.Abstractions;
|
|
|
|
namespace Jibo.Cloud.Tests.WebSockets;
|
|
|
|
public sealed class JiboInteractionServiceTests
|
|
{
|
|
[Fact]
|
|
public async Task BuildDecisionAsync_Joke_UsesCatalogBackedRandomContent()
|
|
{
|
|
var service = CreateService();
|
|
|
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
|
{
|
|
RawTranscript = "tell me a joke",
|
|
NormalizedTranscript = "tell me a joke"
|
|
});
|
|
|
|
Assert.Equal("joke", decision.IntentName);
|
|
Assert.Equal("@be/joke", decision.SkillName);
|
|
Assert.Equal("Why did the robot cross the road? Because it was programmed by the chicken.", decision.ReplyText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task BuildDecisionAsync_Dance_UsesCatalogBackedAnimation()
|
|
{
|
|
var service = CreateService();
|
|
|
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
|
{
|
|
RawTranscript = "do a dance",
|
|
NormalizedTranscript = "do a dance"
|
|
});
|
|
|
|
Assert.Equal("dance", decision.IntentName);
|
|
Assert.Equal("chitchat-skill", decision.SkillName);
|
|
Assert.Equal("Okay. Watch this.", decision.ReplyText);
|
|
Assert.Equal("<speak>Okay.<break size='0.2'/> Watch this.<anim cat='dance' filter='music, rom-upbeat' /></speak>", decision.SkillPayload!["esml"]);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task BuildDecisionAsync_ClientNluAskForDate_MapsToDateIntent()
|
|
{
|
|
var service = CreateService();
|
|
|
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
|
{
|
|
Attributes = new Dictionary<string, object?>
|
|
{
|
|
["clientIntent"] = "askForDate"
|
|
}
|
|
});
|
|
|
|
Assert.Equal("date", decision.IntentName);
|
|
Assert.Contains("Today is", decision.ReplyText, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task BuildDecisionAsync_YesNoFollowUp_MapsShortAffirmationToYesIntent()
|
|
{
|
|
var service = CreateService();
|
|
|
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
|
{
|
|
RawTranscript = "yeah",
|
|
NormalizedTranscript = "yeah",
|
|
Attributes = new Dictionary<string, object?>
|
|
{
|
|
["listenRules"] = new[] { "create/is_it_a_keeper" }
|
|
}
|
|
});
|
|
|
|
Assert.Equal("yes", decision.IntentName);
|
|
Assert.Equal("Yes.", decision.ReplyText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task BuildDecisionAsync_SkillPhraseVariant_MapsToKnownIntent()
|
|
{
|
|
var service = CreateService();
|
|
|
|
var decision = await service.BuildDecisionAsync(new TurnContext
|
|
{
|
|
RawTranscript = "make me laugh",
|
|
NormalizedTranscript = "make me laugh"
|
|
});
|
|
|
|
Assert.Equal("joke", decision.IntentName);
|
|
}
|
|
|
|
private static JiboInteractionService CreateService()
|
|
{
|
|
return new JiboInteractionService(
|
|
new JiboExperienceContentCache(new InMemoryJiboExperienceContentRepository()),
|
|
new FirstItemRandomizer());
|
|
}
|
|
|
|
private sealed class FirstItemRandomizer : IJiboRandomizer
|
|
{
|
|
public T Choose<T>(IReadOnlyList<T> items)
|
|
{
|
|
return items[0];
|
|
}
|
|
}
|
|
}
|