mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 11:50:42 -05:00
Job numbers were going into Customer ("GM / 4980-88R"), which breaks
sorting, searching and grouping by customer. A nest now has its own
Job # field: one or several jobs separated by commas, normalized to
"a, b". It is saved in nest.json and the server (schema v21), edited
beside Customer in Edit Nest (WinForms and Avalonia), shown as a
sortable, searchable column in the Open list, and printed on the nest
report and in MCP output.
Deploy the server before the desktop: the open overlay takes the
server's job number, and an older server has none.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
4.1 KiB
C#
93 lines
4.1 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Microsoft.Data.Sqlite;
|
|
using OpenNest.Data;
|
|
using static OpenNest.Server.Tests.TestDatabase;
|
|
|
|
namespace OpenNest.Server.Tests;
|
|
|
|
/// <summary>
|
|
/// Nest records carry the archive's units, which their thickness is in, so a list of nests can
|
|
/// tell a millimeter nest from an inch one without reading each archive.
|
|
/// </summary>
|
|
public sealed class NestUnitsTests
|
|
{
|
|
[Fact]
|
|
public async Task Upload_TakesUnitsFromTheArchive_NotTheClientsClaim()
|
|
{
|
|
using var factory = new ServerFactory();
|
|
using var client = factory.CreateClient();
|
|
var nest = NestApiTests.SyntheticNest();
|
|
nest.Units = Units.Millimeters;
|
|
nest.Thickness = 6.35;
|
|
|
|
using var created = await client.PostAsync("/api/nests",
|
|
NestRevisionTests.Body(new NestRecord { Name = "Metric", Units = Units.Inches }, NestApiTests.Archive(nest)));
|
|
var json = await created.Content.ReadAsStringAsync();
|
|
var id = JsonDocument.Parse(json).RootElement.GetProperty("id").GetGuid();
|
|
|
|
Assert.Equal("millimeters", JsonDocument.Parse(json).RootElement.GetProperty("units").GetString());
|
|
using var listed = JsonDocument.Parse(await client.GetStringAsync("/api/nests/query"));
|
|
var item = Assert.Single(listed.RootElement.GetProperty("items").EnumerateArray());
|
|
Assert.Equal("millimeters", item.GetProperty("units").GetString());
|
|
Assert.Equal(6.35, item.GetProperty("thickness").GetDouble());
|
|
using var record = JsonDocument.Parse(await client.GetStringAsync($"/api/nests/{id}"));
|
|
Assert.Equal("millimeters", record.RootElement.GetProperty("units").GetString());
|
|
}
|
|
|
|
[Fact]
|
|
public void MetadataOnlySave_KeepsTheArchivesUnits()
|
|
{
|
|
using var factory = new ServerFactory();
|
|
using var database = new NestDatabase(factory.DatabasePath, pooling: false);
|
|
var id = Guid.NewGuid();
|
|
var created = database.Insert(id, Record("Metric", Units.Millimeters), [1]);
|
|
|
|
var updated = database.UpdateMetadata(id, Record("Metric renamed", Units.Inches), created.Revision)!;
|
|
|
|
Assert.Equal(Units.Millimeters, updated.Units);
|
|
Assert.Equal([Units.Millimeters, Units.Millimeters], database.History(id, 0, 10)!.Items.Select(r => r.Units));
|
|
}
|
|
|
|
[Fact]
|
|
public void Version11Database_ReadsEachStoredArchivesUnits()
|
|
{
|
|
using var factory = new ServerFactory();
|
|
var metric = Guid.NewGuid();
|
|
var inch = Guid.NewGuid();
|
|
var unreadable = Guid.NewGuid();
|
|
var metricNest = NestApiTests.SyntheticNest();
|
|
metricNest.Units = Units.Millimeters;
|
|
using (var database = new NestDatabase(factory.DatabasePath, pooling: false))
|
|
{
|
|
var created = database.Insert(metric, Record("Metric", Units.Inches), NestApiTests.Archive(metricNest));
|
|
database.UpdateMetadata(metric, Record("Metric renamed", Units.Inches), created.Revision);
|
|
database.Insert(inch, Record("Inch", Units.Inches), NestApiTests.Archive(NestApiTests.SyntheticNest()));
|
|
database.Insert(unreadable, Record("Broken", Units.Inches), [1]);
|
|
}
|
|
Execute(factory.DatabasePath, """
|
|
ALTER TABLE nests DROP COLUMN units;
|
|
ALTER TABLE nest_revisions DROP COLUMN units;
|
|
PRAGMA user_version=11;
|
|
""");
|
|
|
|
using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false);
|
|
|
|
Assert.Equal(Units.Millimeters, upgraded.Get(metric)!.Units);
|
|
Assert.Equal([Units.Millimeters, Units.Millimeters], upgraded.History(metric, 0, 10)!.Items.Select(r => r.Units));
|
|
Assert.Equal(Units.Inches, upgraded.Get(inch)!.Units);
|
|
Assert.Equal(Units.Inches, upgraded.Get(unreadable)!.Units);
|
|
Assert.Equal(21L, Scalar(factory.DatabasePath, "PRAGMA user_version"));
|
|
}
|
|
|
|
private static NestRecord Record(string name, Units units) => new()
|
|
{
|
|
Name = name,
|
|
Material = "Steel",
|
|
Thickness = 0.25,
|
|
Units = units,
|
|
DateCreated = new DateTime(2026, 1, 1),
|
|
DateModified = new DateTime(2026, 1, 2),
|
|
};
|
|
}
|