From c38ae0705d4f712c3fdbbdb6008fe4872442dd4d Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 15 Oct 2024 22:11:09 +0900 Subject: [PATCH] Enhance test program by `typia`. --- package.json | 5 ++-- test/features/test_bbs_article.ts | 31 ++++++++++++++++--------- test/features/test_shopping_swagger.ts | 32 ++++++++++++++------------ test/index.ts | 2 +- test/tsconfig.json | 5 ++-- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 7809ca1..243b40f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "prepare": "ts-patch install", + "prepare": "ts-patch install && typia patch", "build": "npm run build:main && npm run build:test", "build:main": "rimraf lib && tsc", "build:test": "rimraf bin && tsc -p test/tsconfig.json", @@ -32,6 +32,7 @@ }, "devDependencies": { "@nestia/e2e": "^0.7.0", + "@samchon/openapi": "^1.1.1", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "dotenv": "^16.4.5", "dotenv-expand": "^11.0.6", @@ -41,7 +42,7 @@ "ts-node": "^10.9.2", "ts-patch": "^3.2.1", "typescript": "5.5.4", - "typescript-transform-paths": "^3.5.1", + "typescript-transform-paths": "^3.4.6", "typia": "^6.11.2" }, "files": [ diff --git a/test/features/test_bbs_article.ts b/test/features/test_bbs_article.ts index da292ca..4aaf2b3 100644 --- a/test/features/test_bbs_article.ts +++ b/test/features/test_bbs_article.ts @@ -1,23 +1,32 @@ -import { JsonTranslator } from "@samchon/translate-json"; +import { JsonTranslator } from "@samchon/json-translator"; import fs from "fs"; +import typia, { tags } from "typia"; import input from "../../assets/input/bbs.article.json"; export const test_bbs_article = async ( translator: JsonTranslator, ): Promise => { - for (const lang of ["ko", "ja", "ar"]) + typia.assertGuard(input); + for (const lang of ["ko", "ja", "ar"]) { + const output: IBbsArticle = await translator.translate({ + input, + target: lang, + // filter: ({ key }) => key === "title" || key === "body", + }); + typia.assert(output); await fs.promises.writeFile( `${__dirname}/../../../assets/output/bbs.article.${lang}.json`, - JSON.stringify( - await translator.translate({ - input, - target: lang, - filter: ({ key }) => key === "title" || key === "body", - }), - null, - 2, - ), + JSON.stringify(output, null, 2), "utf8", ); + } }; + +interface IBbsArticle { + id: string & tags.Format<"uuid">; + title: string; + body: string; + created_at: string & tags.Format<"date-time">; + updated_at: string & tags.Format<"date-time">; +} diff --git a/test/features/test_shopping_swagger.ts b/test/features/test_shopping_swagger.ts index 790c0a6..de30c8e 100644 --- a/test/features/test_shopping_swagger.ts +++ b/test/features/test_shopping_swagger.ts @@ -1,27 +1,29 @@ -import { JsonTranslator } from "@samchon/translate-json"; +import { JsonTranslator } from "@samchon/json-translator"; +import { OpenApi } from "@samchon/openapi"; import fs from "fs"; +import typia from "typia"; import input from "../../assets/input/shopping.swagger.json"; export const test_connector_swagger = async ( translator: JsonTranslator, ): Promise => { - for (const lang of ["ko", "ja", "ar"]) + typia.assertGuard(input); + for (const lang of ["ko", "ja", "ar"]) { + const output: OpenApi.IDocument = await translator.translate({ + input, + target: lang, + filter: (explore) => + explore.key === "title" || + explore.key === "description" || + explore.key === "summary" || + explore.key === "x-wrtn-placeholder", + }); + typia.assert(output); await fs.promises.writeFile( `${__dirname}/../../../assets/output/shopping.swagger.${lang}.json`, - JSON.stringify( - await translator.translate({ - input, - target: lang, - filter: (explore) => - explore.key === "title" || - explore.key === "description" || - explore.key === "summary" || - explore.key === "x-wrtn-placeholder", - }), - null, - 2, - ), + JSON.stringify(output, null, 2), "utf8", ); + } }; diff --git a/test/index.ts b/test/index.ts index ec734aa..6695c24 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,5 +1,5 @@ import { DynamicExecutor } from "@nestia/e2e"; -import { JsonTranslator } from "@samchon/translate-json"; +import { JsonTranslator } from "@samchon/json-translator"; import chalk from "chalk"; import dotenv from "dotenv"; import dotenvExpand from "dotenv-expand"; diff --git a/test/tsconfig.json b/test/tsconfig.json index ab772d7..834d7a8 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -7,11 +7,12 @@ "experimentalDecorators": true, "resolveJsonModule": true, "paths": { - "@samchon/translate-json": ["../src/index.ts"], - "@samchon/translate-json/lib/*": ["../src/*"], + "@samchon/json-translator": ["../src/index.ts"], + "@samchon/json-translator/lib/*": ["../src/*"], }, "plugins": [ { "transform": "typescript-transform-paths" }, + { "transform": "typia/lib/transform" }, ] }, "include": ["../src", "../test"]