/* 472 마무리 — 종단도 계획고 [저장] 조각(`design_profile_save.ts`) 진짜 본문 · 서버 창구 · 알림만 가짜. * 결과 = 표준출력 JSON. 짝 = `test_472_6_profile_save.py`. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); const calls = []; const STUBS = { B05_Profile_Api_Fetch: { saveProfileAlignment: async (projectId, routeId, edits) => { calls.push(["put", projectId, routeId, edits]); return { profile_alignment: { base_pvi: [1] }, dropped_edit_chainages: [] }; }, }, design_save: { noticeDroppedEdits: (saved) => calls.push(["notice", saved.dropped_edit_chainages]), }, }; const file = path.join(ROOT, "A00_Common", "design", "design_profile_save.ts"); const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; const req = (request) => STUBS[Object.keys(STUBS).find((name) => request.endsWith(name))] ?? {}; new Function("exports", "module", "require", js)(box.exports, box, req); (async () => { const state = { routeId: 7, dirty: true, previewing: false }; const adopted = []; const edits = { station_offsets: { 10: 0.5 }, curve_radii: {} }; const save = box.exports.createProfileSave({ projectId: "p", routeId: () => state.routeId, edits: () => edits, dirty: () => state.dirty, previewing: () => state.previewing, adopt: (next) => adopted.push(next ?? null), }); const nulls = {}; for (const [name, patch] of [ ["clean", { dirty: false }], ["preview", { previewing: true }], ["noRoute", { routeId: null }], ]) { Object.assign(state, { routeId: 7, dirty: true, previewing: false }, patch); nulls[name] = save.savePart(); } Object.assign(state, { routeId: 7, dirty: true, previewing: false }); const part = save.savePart(); await part.after({ profile_alignment: { base_pvi: [2] }, dropped_edit_chainages: [3] }); await save.save(); state.dirty = false; await save.save(); // 편집 없음 = 안 보냄 console.log(JSON.stringify({ nulls, body: part.body, adopted, calls })); })();