Phase 9: version message (FR-13)
- ใส่คำอธิบายแบบ commit message ได้ทุก flow ที่สร้าง version (Save & Version / Start Versioning / generate จากเว็บ) + แสดงใน version history ทุกหน้า - backend: DocumentVersion.Message (varchar 2048) + migration AddVersionMessage + BadRequest ตรวจความยาวก่อนแตะ MinIO (กัน 500 + orphan object) - add-in: ConfirmVersionDialog เพิ่ม textarea (Start Versioning ใช้ dialog ด้วย) + แสดง message ใน VersionHistoryPanel - web: ฟอร์มสร้างเอกสาร + หน้า detail แสดง message (desktop truncate + tooltip, mobile เต็มบรรทัด) - sync เอกสารทั้งหมด: spec v5 (FR-13/AC-16) + plan Phase 9 + acceptance-review 1–16 + README + CLAUDE.md + web/README - tests: backend 52 / addin 50 / web 36 — เขียวทั้งชุด Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b47667f918
commit
7b20f12ede
28 changed files with 928 additions and 141 deletions
|
|
@ -9,7 +9,7 @@ public record UploadVersionResult(Guid VersionId, int VersionNumber);
|
|||
|
||||
public record GenerateResult(Guid DocumentId, Guid VersionId, int VersionNumber, string DownloadUrl);
|
||||
|
||||
public record VersionItem(Guid VersionId, int VersionNumber, DateTimeOffset CreatedAt, string CreatedByUserId, string ContentHash, JsonElement? Fields);
|
||||
public record VersionItem(Guid VersionId, int VersionNumber, DateTimeOffset CreatedAt, string CreatedByUserId, string ContentHash, JsonElement? Fields, string? Message);
|
||||
|
||||
public record TemplateFieldItem(Guid Id, string Key, string Label, string Type, bool IsRequired, int SortOrder);
|
||||
|
||||
|
|
@ -29,9 +29,9 @@ public record DocDetail(Guid Id, string FileName, DateTimeOffset CreatedAt, Guid
|
|||
|
||||
public static class ApiExtensions
|
||||
{
|
||||
/// <summary>multipart form ของ POST versions: file + clientVersionId + fields (option)</summary>
|
||||
/// <summary>multipart form ของ POST versions: file + clientVersionId + fields (option) + message (option)</summary>
|
||||
public static MultipartFormDataContent VersionForm(
|
||||
byte[] docx, string fileName, string clientVersionId, string? fieldsJson = null)
|
||||
byte[] docx, string fileName, string clientVersionId, string? fieldsJson = null, string? message = null)
|
||||
{
|
||||
var form = new MultipartFormDataContent();
|
||||
var file = new ByteArrayContent(docx);
|
||||
|
|
@ -40,6 +40,8 @@ public static class ApiExtensions
|
|||
form.Add(new StringContent(clientVersionId), "clientVersionId");
|
||||
if (fieldsJson is not null)
|
||||
form.Add(new StringContent(fieldsJson), "fields");
|
||||
if (message is not null)
|
||||
form.Add(new StringContent(message), "message");
|
||||
return form;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,12 +46,13 @@ public static class TestFlow
|
|||
public static Task<GenerateResult> GenerateDocumentAsync(HttpClient client, Guid templateId) =>
|
||||
GenerateDocumentAsync(client, templateId, DefaultValues);
|
||||
|
||||
/// <summary>generate พร้อมค่าที่กำหนดเอง (ทดสอบ validation หรือค่าเกินนิยาม)</summary>
|
||||
/// <summary>generate พร้อมค่าที่กำหนดเอง (ทดสอบ validation หรือค่าเกินนิยาม)
|
||||
/// + commit message ทางเลือก (FR-13)</summary>
|
||||
public static async Task<GenerateResult> GenerateDocumentAsync(
|
||||
HttpClient client, Guid templateId, Dictionary<string, string> values)
|
||||
HttpClient client, Guid templateId, Dictionary<string, string> values, string? message = null)
|
||||
{
|
||||
using var response = await client.PostAsJsonAsync(
|
||||
"api/documents/generate", new { templateId, values }, IntegrationTestFixture.Json);
|
||||
"api/documents/generate", new { templateId, values, message }, IntegrationTestFixture.Json);
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
return (await response.Content.ReadFromJsonAsync<GenerateResult>(IntegrationTestFixture.Json))!;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,182 @@
|
|||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace WordVersioning.Api.IntegrationTests;
|
||||
|
||||
/// <summary>FR-13 — commit message ต่อ version: รับจากทุก flow ที่สร้าง version (upload + generate),
|
||||
/// normalize ว่าง/whitespace → null, trim, จำกัด 2048 อักขระ, echo ใน history (AC-16)</summary>
|
||||
[Collection(IntegrationTestCollection.Name)]
|
||||
public sealed class VersionMessageTests(IntegrationTestFixture fixture)
|
||||
{
|
||||
[Fact]
|
||||
public async Task Upload_WithMessage_PersistsRow_AndEchoesInHistory()
|
||||
{
|
||||
var documentId = Guid.NewGuid();
|
||||
using var client = fixture.CreateClient();
|
||||
|
||||
using var response = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx(), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: "แก้ไขข้อ 3 หลังตรวจสอบ"));
|
||||
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
|
||||
await using var db = fixture.CreateDb();
|
||||
var version = await db.DocumentVersions.AsNoTracking().SingleAsync(v => v.DocumentId == documentId);
|
||||
Assert.Equal("แก้ไขข้อ 3 หลังตรวจสอบ", version.Message);
|
||||
|
||||
using var history = await client.GetAsync($"api/documents/{documentId}/versions");
|
||||
var items = await history.Content.ReadFromJsonAsync<List<VersionItem>>(IntegrationTestFixture.Json);
|
||||
Assert.Equal("แก้ไขข้อ 3 หลังตรวจสอบ", items!.Single().Message);
|
||||
}
|
||||
|
||||
/// <summary>ไม่ส่ง / ส่งค่าว่าง / ส่ง whitespace ล้วน → เก็บ null ทั้ง DB และ history</summary>
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public async Task Upload_BlankOrMissingMessage_StoredAsNull(string? sent)
|
||||
{
|
||||
var documentId = Guid.NewGuid();
|
||||
using var client = fixture.CreateClient();
|
||||
|
||||
using var response = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx(), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: sent));
|
||||
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
|
||||
await using var db = fixture.CreateDb();
|
||||
var version = await db.DocumentVersions.AsNoTracking().SingleAsync(v => v.DocumentId == documentId);
|
||||
Assert.Null(version.Message);
|
||||
|
||||
using var history = await client.GetAsync($"api/documents/{documentId}/versions");
|
||||
var items = await history.Content.ReadFromJsonAsync<List<VersionItem>>(IntegrationTestFixture.Json);
|
||||
Assert.Null(items!.Single().Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Upload_TrimsSurroundingWhitespace()
|
||||
{
|
||||
var documentId = Guid.NewGuid();
|
||||
using var client = fixture.CreateClient();
|
||||
|
||||
using var response = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx(), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: " แก้ไขข้อ 3 "));
|
||||
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
|
||||
await using var db = fixture.CreateDb();
|
||||
var version = await db.DocumentVersions.AsNoTracking().SingleAsync(v => v.DocumentId == documentId);
|
||||
Assert.Equal("แก้ไขข้อ 3", version.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Upload_OversizeMessage_Returns400_NoSideEffect()
|
||||
{
|
||||
var documentId = Guid.NewGuid();
|
||||
using var client = fixture.CreateClient();
|
||||
|
||||
using var response = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx(), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: new string('ก', 2049)));
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
|
||||
await using var db = fixture.CreateDb();
|
||||
Assert.False(await db.Documents.AsNoTracking().AnyAsync(d => d.Id == documentId)); // ไม่มี side effect
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Upload_MessageExactly2048_Succeeds()
|
||||
{
|
||||
var documentId = Guid.NewGuid();
|
||||
using var client = fixture.CreateClient();
|
||||
var message = new string('ก', 2048);
|
||||
|
||||
using var response = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx(), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: message));
|
||||
|
||||
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||
|
||||
await using var db = fixture.CreateDb();
|
||||
var version = await db.DocumentVersions.AsNoTracking().SingleAsync(v => v.DocumentId == documentId);
|
||||
Assert.Equal(message, version.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SecondUpload_KeepsPerVersionMessages()
|
||||
{
|
||||
var documentId = Guid.NewGuid();
|
||||
using var client = fixture.CreateClient();
|
||||
|
||||
using var first = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx("v1"), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: "ฉบับแรก"));
|
||||
using var second = await client.PostAsync(
|
||||
$"api/documents/{documentId}/versions",
|
||||
ApiExtensions.VersionForm(
|
||||
TestDocx.BuildPlainDocx("v2"), "doc.docx", Guid.NewGuid().ToString(),
|
||||
message: "แก้ไขเงินเดือน"));
|
||||
|
||||
Assert.Equal(HttpStatusCode.Created, second.StatusCode);
|
||||
|
||||
// history ใหม่ → เก่า พร้อม message ของแต่ละ version เป็นของตัวเอง
|
||||
using var history = await client.GetAsync($"api/documents/{documentId}/versions");
|
||||
var items = await history.Content.ReadFromJsonAsync<List<VersionItem>>(IntegrationTestFixture.Json);
|
||||
Assert.Equal(2, items!.Count);
|
||||
Assert.Equal(2, items[0].VersionNumber);
|
||||
Assert.Equal("แก้ไขเงินเดือน", items[0].Message);
|
||||
Assert.Equal(1, items[1].VersionNumber);
|
||||
Assert.Equal("ฉบับแรก", items[1].Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Generate_WithMessage_CreatesV1WithMessage()
|
||||
{
|
||||
using var client = fixture.CreateClient();
|
||||
var (templateId, _) = await TestFlow.CreateConfiguredTemplateAsync(client, "msg-gen");
|
||||
|
||||
var generated = await TestFlow.GenerateDocumentAsync(
|
||||
client, templateId, TestFlow.DefaultValues, message: "ฉบับเสนอลงนามครั้งแรก");
|
||||
|
||||
await using var db = fixture.CreateDb();
|
||||
var version = await db.DocumentVersions.AsNoTracking()
|
||||
.SingleAsync(v => v.DocumentId == generated.DocumentId);
|
||||
Assert.Equal(1, version.VersionNumber);
|
||||
Assert.Equal("ฉบับเสนอลงนามครั้งแรก", version.Message);
|
||||
|
||||
using var history = await client.GetAsync($"api/documents/{generated.DocumentId}/versions");
|
||||
var items = await history.Content.ReadFromJsonAsync<List<VersionItem>>(IntegrationTestFixture.Json);
|
||||
Assert.Equal("ฉบับเสนอลงนามครั้งแรก", items!.Single().Message);
|
||||
}
|
||||
|
||||
/// <summary>400 ต้องเกิดก่อนแตะ MinIO/template — ไม่ทิ้ง orphan object ใน bucket</summary>
|
||||
[Fact]
|
||||
public async Task Generate_OversizeMessage_Returns400()
|
||||
{
|
||||
using var client = fixture.CreateClient();
|
||||
var (templateId, _) = await TestFlow.CreateConfiguredTemplateAsync(client, "msg-gen-oversize");
|
||||
|
||||
using var response = await client.PostAsJsonAsync(
|
||||
"api/documents/generate",
|
||||
new { templateId, values = TestFlow.DefaultValues, message = new string('ก', 2049) },
|
||||
IntegrationTestFixture.Json);
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue