const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const ts = require("typescript"); const { test } = require("node:test"); const { loadTypeScript } = require("./load-typescript.cjs"); const root = path.resolve(__dirname, ".."); const legacy = "app/(with-base-layout)/oper/dredging/lib/"; test("기존 준설 lib 7파일은 feature 구현을 재수출하며 중복 구현을 보유하지 않는다", () => { for (const name of [ "client", "types", "uuid", "date", "exif", "registration-request", "useDredgingCommonCodes", ]) { const source = ts.createSourceFile( name, fs.readFileSync(path.join(root, legacy, `${name}.ts`), "utf8"), ts.ScriptTarget.Latest, true, ); assert.ok(source.statements.length > 0); for (const statement of source.statements) { assert.ok( ts.isExportDeclaration(statement), `${name} contains an implementation`, ); assert.match(statement.moduleSpecifier.text, /^@\/features\/dredging\//); } } }); test("feature 내부는 옛 준설 라우트·UI 모듈을 역참조하지 않는다", () => { const featureRoot = path.join(root, "src/features/dredging"); for (const entry of fs.readdirSync(featureRoot, { recursive: true, withFileTypes: true, })) { if (!entry.isFile() || !entry.name.endsWith(".ts")) continue; const filename = path.join(entry.parentPath, entry.name); const source = fs.readFileSync(filename, "utf8"); assert.doesNotMatch( source, /(?:@\/app\/|oper\/dredging|DredgingRegisterModal|DredgingDetailPopupPage)/, filename, ); } const popup = fs.readFileSync( path.join(root, "src/features/windowPopup/ui/dredgingPopupRecord.ts"), "utf8", ); assert.match(popup, /from "@\/features\/dredging"/); }); test("기존 date/uuid/EXIF 경로에서 이동된 구현을 호출할 수 있다", async () => { const date = loadTypeScript(`${legacy}date.ts`); assert.equal( date.formatDredgingCapturedDate("2024-02-29T10:11:12"), "2024-02-29", ); assert.equal(date.formatDredgingCapturedDate("2025-02-29"), null); const uuid = loadTypeScript(`${legacy}uuid.ts`); assert.match( uuid.createDredgingClientUuid(), /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, ); const exif = loadTypeScript(`${legacy}exif.ts`); assert.equal( (await exif.readPhotoMetadata({ name: "test.png", type: "image/png" })) .status, "UNSUPPORTED", ); assert.equal( ( await exif.readPhotoMetadata({ name: "test.jpg", type: "image/jpeg", arrayBuffer: async () => Uint8Array.from([0xff, 0xd8, 0xff, 0xd9]).buffer, }) ).status, "MISSING_BOTH", ); });