eCourt-Doc-Edit/backend/WordVersioning.Api.IntegrationTests/TestFlow.cs
Suphonchai Phoonsawat 7b20f12ede 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>
2026-08-20 22:05:49 +07:00

75 lines
3.4 KiB
C#

using System.Net;
using System.Net.Http.Json;
namespace WordVersioning.Api.IntegrationTests;
/// <summary>setup ที่ใช้ร่วมกันหลาย test class: สร้าง template + ตั้ง field definitions ครบชุด
/// (employee_name = required text, position = text, salary = number, start_date = date)</summary>
public static class TestFlow
{
public static readonly Dictionary<string, string> DefaultValues = new()
{
["employee_name"] = "สมหญิง รักงาน",
["position"] = "วิศวกรซอฟต์แวร์",
["salary"] = "75000",
["start_date"] = "2026-08-01",
};
public static async Task<(Guid TemplateId, List<TemplateFieldItem> Fields)> CreateConfiguredTemplateAsync(
HttpClient client, string baseName)
{
// create (detect defaults)
using var create = await client.PostAsync(
"api/templates", ApiExtensions.TemplateForm(TestDocx.BuildTemplateDocx(), $"{baseName} {Guid.NewGuid():N}"));
create.EnsureSuccessStatusCode();
var created = await create.Content.ReadFromJsonAsync<CreateTemplateResult>(IntegrationTestFixture.Json);
// ตั้ง label/type/required ให้ครบทุกรูปแบบ (มี required, number, date)
using var put = await client.PutAsJsonAsync($"api/templates/{created!.Id}", new
{
fields = created.Fields.Select(f => new
{
key = f.Key,
label = LabelOf(f.Key),
type = TypeOf(f.Key),
isRequired = f.Key == "employee_name",
sortOrder = f.SortOrder,
}),
}, IntegrationTestFixture.Json);
put.EnsureSuccessStatusCode();
var detail = await put.Content.ReadFromJsonAsync<TemplateDetailResult>(IntegrationTestFixture.Json);
return (created.Id, detail!.Fields);
}
/// <summary>generate เอกสาร v1 จาก template ที่ตั้งค่าแล้ว — คืน response ของ generate</summary>
public static Task<GenerateResult> GenerateDocumentAsync(HttpClient client, Guid templateId) =>
GenerateDocumentAsync(client, templateId, DefaultValues);
/// <summary>generate พร้อมค่าที่กำหนดเอง (ทดสอบ validation หรือค่าเกินนิยาม)
/// + commit message ทางเลือก (FR-13)</summary>
public static async Task<GenerateResult> GenerateDocumentAsync(
HttpClient client, Guid templateId, Dictionary<string, string> values, string? message = null)
{
using var response = await client.PostAsJsonAsync(
"api/documents/generate", new { templateId, values, message }, IntegrationTestFixture.Json);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
return (await response.Content.ReadFromJsonAsync<GenerateResult>(IntegrationTestFixture.Json))!;
}
public static string LabelOf(string key) => key switch
{
"employee_name" => "ชื่อพนักงาน",
"position" => "ตำแหน่ง",
"salary" => "เงินเดือน",
"start_date" => "วันเริ่มงาน",
_ => key,
};
public static string TypeOf(string key) => key switch
{
"salary" => "number",
"start_date" => "date",
_ => "text",
};
}