Initial commit of version 0.2.0
This commit is contained in:
parent
86fc06b877
commit
dfb04462f3
108 changed files with 16167 additions and 80 deletions
39
tests/Decky.Core.Tests/CardDtoSerializationTests.cs
Normal file
39
tests/Decky.Core.Tests/CardDtoSerializationTests.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System.Text.Json;
|
||||
using Decky.Core.Api.Models;
|
||||
|
||||
namespace Decky.Core.Tests;
|
||||
|
||||
public sealed class CardDtoSerializationTests
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
[Fact]
|
||||
public void Card_owner_accepts_documented_string_shape()
|
||||
{
|
||||
var card = JsonSerializer.Deserialize<CardDto>(
|
||||
"""{"id":1,"stackId":2,"title":"Test","owner":"admin"}""",
|
||||
JsonOptions);
|
||||
|
||||
Assert.Equal("admin", card!.Owner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Card_owner_accepts_embedded_user_object_shape()
|
||||
{
|
||||
var card = JsonSerializer.Deserialize<CardDto>(
|
||||
"""{"id":1,"stackId":2,"title":"Test","owner":{"primaryKey":"admin","uid":"admin","displayname":"Elijah"}}""",
|
||||
JsonOptions);
|
||||
|
||||
Assert.Equal("admin", card!.Owner);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Card_owner_falls_back_to_primary_key()
|
||||
{
|
||||
var card = JsonSerializer.Deserialize<CardDto>(
|
||||
"""{"id":1,"stackId":2,"title":"Test","owner":{"primaryKey":"admin"}}""",
|
||||
JsonOptions);
|
||||
|
||||
Assert.Equal("admin", card!.Owner);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,5 +36,28 @@ public sealed class CardUpdateRequestTests
|
|||
Assert.Equal("2026-07-20T12:00:00+00:00", root.GetProperty("duedate").GetString());
|
||||
Assert.Equal(JsonValueKind.Null, root.GetProperty("done").ValueKind);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromCard_can_explicitly_clear_description_and_due_date()
|
||||
{
|
||||
var card = new CardDto
|
||||
{
|
||||
Title = "Card",
|
||||
Description = "Remove me",
|
||||
Type = "plain",
|
||||
Owner = "admin",
|
||||
DueDate = DateTimeOffset.Parse("2026-07-20T12:00:00Z"),
|
||||
Color = "D99080",
|
||||
};
|
||||
|
||||
var request = CardUpdateRequest.FromCard(
|
||||
card,
|
||||
description: string.Empty,
|
||||
replaceDescription: true,
|
||||
dueDate: null,
|
||||
replaceDueDate: true);
|
||||
|
||||
Assert.Equal(string.Empty, request.Description);
|
||||
Assert.Null(request.DueDate);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue