Files
OpenNest/OpenNest.Server.Tests/ServerOptionsTests.cs
T
ajandClaude Opus 5.5 5dff83cfb8 fix(server): reject duplicate nest ids, invalid metadata and bare --database
- POST /api/nests with an existing id (active or deleted) now returns 409 with
  the current record instead of a 500 from the UNIQUE constraint.
- Uploaded nest metadata must have string text fields and a defined status;
  null fields and undefined statuses (e.g. 99) are 400 instead of a 500 or a
  stored invalid value.
- --database <path> is accepted alongside --database=<path>; a missing or
  repeated path fails startup instead of silently using OPENNEST_DB/default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 01:30:37 -04:00

35 lines
1.4 KiB
C#

namespace OpenNest.Server.Tests;
public sealed class ServerOptionsTests
{
private static readonly string Default = Path.Combine("data", "nests.db");
[Theory]
[InlineData(new[] { "--database=/srv/a.db" }, "/srv/a.db")]
[InlineData(new[] { "--database", "/srv/a.db" }, "/srv/a.db")]
[InlineData(new[] { "--urls=http://127.0.0.1:8090", "--database", "/srv/a.db" }, "/srv/a.db")]
[InlineData(new[] { "--database=/srv/a=b.db" }, "/srv/a=b.db")]
public void DatabasePath_AcceptsBothForms_AndOverridesEnvironment(string[] args, string expected)
{
Assert.Equal(expected, ServerOptions.DatabasePath(args, "/env/nests.db"));
}
[Fact]
public void DatabasePath_WithoutArgument_UsesEnvironmentThenDefault()
{
Assert.Equal("/env/nests.db", ServerOptions.DatabasePath(["--urls=http://127.0.0.1:8090"], "/env/nests.db"));
Assert.Equal(Default, ServerOptions.DatabasePath([], null));
}
[Theory]
[InlineData("--database")]
[InlineData("--database", "--urls=http://127.0.0.1:8090")]
[InlineData("--database=")]
[InlineData("--database= ")]
[InlineData("--database=/a.db", "--database", "/b.db")]
public void DatabasePath_MissingOrRepeated_FailsInsteadOfFallingBack(params string[] args)
{
Assert.Throws<ArgumentException>(() => ServerOptions.DatabasePath(args, "/env/nests.db"));
}
}