Initial commit of version 0.2.0

This commit is contained in:
Elijah 2026-07-19 18:37:14 -07:00
parent 86fc06b877
commit dfb04462f3
108 changed files with 16167 additions and 80 deletions

View file

@ -1,6 +1,7 @@
using System.Net;
using System.Text;
using Decky.Core.Api;
using Decky.Core.Api.Requests;
using Decky.Core.Configuration;
namespace Decky.Core.Tests;
@ -64,6 +65,78 @@ public sealed class DeckApiClientTests
Assert.Equal(2, requestedPaths.Count);
}
[Fact]
public async Task ReorderCardAsync_fetches_destination_card_after_boolean_acknowledgement()
{
var handler = new StubHttpMessageHandler(request =>
{
if (request.Method == HttpMethod.Put)
{
return JsonResponse("true");
}
Assert.Equal(
"/index.php/apps/deck/api/v1.0/boards/2/stacks/8/cards/11",
request.RequestUri!.AbsolutePath);
return JsonResponse("{\"id\":11,\"stackId\":8,\"title\":\"Moved\",\"owner\":\"admin\"}");
});
using var httpClient = new HttpClient(handler);
var client = CreateClient(httpClient);
var card = await client.ReorderCardAsync(
2,
7,
11,
new ReorderCardRequest { Order = 0, StackId = 8 });
Assert.Equal(8, card.StackId);
}
[Fact]
public async Task ReorderCardAsync_retries_with_destination_route_when_body_stack_was_ignored()
{
var putCount = 0;
var handler = new StubHttpMessageHandler(request =>
{
if (request.Method == HttpMethod.Put)
{
putCount++;
if (putCount == 2)
{
Assert.Contains("/stacks/8/", request.RequestUri!.AbsolutePath, StringComparison.Ordinal);
}
return JsonResponse("true");
}
if (request.RequestUri!.AbsolutePath.Contains("/stacks/8/", StringComparison.Ordinal))
{
if (putCount == 2)
{
return JsonResponse("{\"id\":11,\"stackId\":8,\"title\":\"Moved\",\"owner\":\"admin\"}");
}
return new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent("{\"status\":404}", Encoding.UTF8, "application/json"),
};
}
return JsonResponse("{\"id\":11,\"stackId\":7,\"title\":\"Not moved\",\"owner\":\"admin\"}");
});
using var httpClient = new HttpClient(handler);
var client = CreateClient(httpClient);
var card = await client.ReorderCardAsync(
2,
7,
11,
new ReorderCardRequest { Order = 0, StackId = 8 });
Assert.Equal(8, card.StackId);
Assert.Equal(2, putCount);
}
private static HttpResponseMessage JsonResponse(string json) => new(HttpStatusCode.OK)
{
Content = new StringContent(json, Encoding.UTF8, "application/json"),
@ -80,6 +153,15 @@ public sealed class DeckApiClientTests
return clone;
}
private static DeckApiClient CreateClient(HttpClient httpClient)
{
var options = DeckConnectionOptions.Create("https://cloud.example.test", "elijah", "app-password");
return new DeckApiClient(
httpClient,
options,
new Uri("https://cloud.example.test/index.php/apps/deck/api/v1.0/"));
}
private sealed class StubHttpMessageHandler(
Func<HttpRequestMessage, HttpResponseMessage> responseFactory) : HttpMessageHandler
{