boostrap docs, tests, basic code and dev plans
This commit is contained in:
1
OpenJibo/tests/Jibo.Cloud.Tests/GlobalUsings.cs
Normal file
1
OpenJibo/tests/Jibo.Cloud.Tests/GlobalUsings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
22
OpenJibo/tests/Jibo.Cloud.Tests/Jibo.Cloud.Tests.csproj
Normal file
22
OpenJibo/tests/Jibo.Cloud.Tests/Jibo.Cloud.Tests.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Jibo.Cloud\dotnet\src\Jibo.Cloud.Application\Jibo.Cloud.Application.csproj" />
|
||||
<ProjectReference Include="..\..\src\Jibo.Cloud\dotnet\src\Jibo.Cloud.Infrastructure\Jibo.Cloud.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\..\src\Jibo.Runtime.Abstractions\Jibo.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Text.Json;
|
||||
using Jibo.Cloud.Application.Services;
|
||||
using Jibo.Cloud.Domain.Models;
|
||||
using Jibo.Cloud.Infrastructure.Persistence;
|
||||
|
||||
namespace Jibo.Cloud.Tests.Protocol;
|
||||
|
||||
public sealed class JiboCloudProtocolServiceTests
|
||||
{
|
||||
private readonly JiboCloudProtocolService _service = new(new InMemoryCloudStateStore());
|
||||
|
||||
[Fact]
|
||||
public async Task CreateHubToken_ReturnsTokenAndExpiry()
|
||||
{
|
||||
var result = await _service.DispatchAsync(new ProtocolEnvelope
|
||||
{
|
||||
HostName = "api.jibo.com",
|
||||
Method = "POST",
|
||||
ServicePrefix = "Account_20160715",
|
||||
Operation = "CreateHubToken",
|
||||
BodyText = "{}"
|
||||
});
|
||||
|
||||
using var payload = JsonDocument.Parse(result.BodyText);
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
Assert.StartsWith("hub-", payload.RootElement.GetProperty("token").GetString());
|
||||
Assert.True(payload.RootElement.GetProperty("expires").GetInt64() > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NewRobotToken_UsesBodyDeviceId()
|
||||
{
|
||||
var result = await _service.DispatchAsync(new ProtocolEnvelope
|
||||
{
|
||||
HostName = "api.jibo.com",
|
||||
Method = "POST",
|
||||
ServicePrefix = "Notification_20160715",
|
||||
Operation = "NewRobotToken",
|
||||
BodyText = """{"deviceId":"robot-123"}"""
|
||||
});
|
||||
|
||||
using var payload = JsonDocument.Parse(result.BodyText);
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
Assert.Contains("robot-123", payload.RootElement.GetProperty("token").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetUpdateFrom_ReturnsNoOpUpdate()
|
||||
{
|
||||
var result = await _service.DispatchAsync(new ProtocolEnvelope
|
||||
{
|
||||
HostName = "api.jibo.com",
|
||||
Method = "POST",
|
||||
ServicePrefix = "Update_20160715",
|
||||
Operation = "GetUpdateFrom",
|
||||
BodyText = """{"subsystem":"robot","fromVersion":"1.0.0"}"""
|
||||
});
|
||||
|
||||
using var payload = JsonDocument.Parse(result.BodyText);
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
Assert.Equal("robot", payload.RootElement.GetProperty("subsystem").GetString());
|
||||
Assert.True(payload.RootElement.TryGetProperty("url", out _));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Text.Json;
|
||||
using Jibo.Cloud.Application.Services;
|
||||
using Jibo.Cloud.Domain.Models;
|
||||
using Jibo.Cloud.Infrastructure.Persistence;
|
||||
|
||||
namespace Jibo.Cloud.Tests.WebSockets;
|
||||
|
||||
public sealed class JiboWebSocketServiceTests
|
||||
{
|
||||
private readonly JiboWebSocketService _service;
|
||||
|
||||
public JiboWebSocketServiceTests()
|
||||
{
|
||||
var store = new InMemoryCloudStateStore();
|
||||
_service = new JiboWebSocketService(
|
||||
store,
|
||||
new ProtocolToTurnContextMapper(),
|
||||
new DemoConversationBroker(),
|
||||
new ResponsePlanToSocketMessagesMapper());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListenMessage_ReturnsResponseAndEos()
|
||||
{
|
||||
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-test-token",
|
||||
Text = """{"type":"LISTEN","data":{"text":"hello jibo"}}"""
|
||||
});
|
||||
|
||||
Assert.Equal(2, replies.Count);
|
||||
Assert.Contains("OPENJIBO_RESPONSE", replies[0].Text);
|
||||
Assert.Contains("EOS", replies[1].Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BinaryMessage_ReturnsAcknowledgementPayload()
|
||||
{
|
||||
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-test-token",
|
||||
Binary = [1, 2, 3, 4]
|
||||
});
|
||||
|
||||
using var payload = JsonDocument.Parse(replies[0].Text!);
|
||||
Assert.Equal("OPENJIBO_AUDIO_RECEIVED", payload.RootElement.GetProperty("type").GetString());
|
||||
Assert.Equal(4, payload.RootElement.GetProperty("data").GetProperty("bytes").GetInt32());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user