eCourt-Doc-Edit/backend/WordVersioning.Api.IntegrationTests/TestDtos.cs
Suphonchai Phoonsawat 9bb4a48c00 Phase 10: field editor (FR-14)
เพิ่ม editor ต่อ template field — ผู้ดูแลเลือกรูปแบบช่องกรอกในฟอร์มสร้างเอกสารได้:
text → textbox/textarea, number/date → control ตาม type (presentation metadata
ล้วน — validation ยังยึด Type, ค่า field เป็น string ทั้ง flow, ไม่แตะ generate/sync/add-in)

- Backend: TemplateField.Editor (nullable, null = default ของ type) +
  migration AddTemplateFieldEditor + validate ตาม type ใน PUT templates
  (ค่าไม่รู้จัก/ไม่เข้ากับ type → 400, normalize-on-write, API คืน resolved เสมอ)
- Web: util fieldEditor.ts + editor select หน้าแก้ template (desktop+mobile,
  ซ่อนเมื่อ type มีทางเดียว) + ฟอร์มสร้างเอกสาร render ตาม editor +
  แก้ prefill re-generate ของ field date จาก ISO timestamp เต็ม (input[type=date]
  รับเฉพาะ yyyy-MM-dd เดิมแสดงว่าง)
- Docs: spec v6 (FR-14/AC-17) + plan Phase 10 + sub-plan field-editor.md +
  acceptance-review AC-17 + README/CLAUDE.md
- Tests: backend 60/60 (FieldEditorTests ใหม่ 8 กรณี) · web 46/46 + build ผ่าน

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-22 09:17:15 +07:00

66 lines
3.5 KiB
C#

using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
namespace WordVersioning.Api.IntegrationTests;
/// <summary>DTO ของ response ฝั่ง test — mirror ของ API (deserialize ด้วย camelCase เหมือนที่ API คืน)</summary>
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, string? Message);
public record TemplateFieldItem(Guid Id, string Key, string Label, string Type, string Editor, bool IsRequired, int SortOrder);
public record CreateTemplateResult(Guid Id, List<TemplateFieldItem> Fields);
public record TemplateDetailResult(Guid Id, string Name, string? Description, bool IsActive, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt, List<TemplateFieldItem> Fields);
public record ReplaceFileResult(Guid Id, List<TemplateFieldItem> Fields, List<string> AddedTags, List<string> RemovedTags);
public record TemplateListItemResult(Guid Id, string Name, string? Description, bool IsActive, int FieldCount, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt);
public record TemplateDocItem(Guid DocumentId, string FileName, DateTimeOffset CreatedAt, int VersionCount, int LatestVersionNumber, DateTimeOffset? LatestVersionAt);
public record DocFieldItem(string Key, string? Label, string? Type, bool? IsRequired, string Value, Guid? SourceVersionId, string? UpdatedByUserId, DateTimeOffset? UpdatedAt);
public record DocDetail(Guid Id, string FileName, DateTimeOffset CreatedAt, Guid? TemplateId, string? TemplateName, bool TemplateIsActive, List<DocFieldItem> Fields);
public static class ApiExtensions
{
/// <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, string? message = null)
{
var form = new MultipartFormDataContent();
var file = new ByteArrayContent(docx);
file.Headers.ContentType = new MediaTypeHeaderValue(TestDocx.DocxContentType);
form.Add(file, "file", fileName);
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;
}
/// <summary>multipart form ของ POST templates / PUT file: name + description (option) + file</summary>
public static MultipartFormDataContent TemplateForm(
byte[] docx, string name, string? description = null, string fileName = "template.docx")
{
var form = new MultipartFormDataContent();
form.Add(new StringContent(name), "name");
if (description is not null)
form.Add(new StringContent(description), "description");
var file = new ByteArrayContent(docx);
file.Headers.ContentType = new MediaTypeHeaderValue(TestDocx.DocxContentType);
form.Add(file, "file", fileName);
return form;
}
public static async Task<T?> ReadJsonAsync<T>(this HttpResponseMessage response) =>
response.Content.Headers.ContentType is null
? default
: await response.Content.ReadFromJsonAsync<T>(IntegrationTestFixture.Json);
}