From 7e1d7c9afcda526bf3480f2389e39e643ac28685 Mon Sep 17 00:00:00 2001 From: koyopro Date: Wed, 15 May 2024 00:37:12 +0900 Subject: [PATCH] add link from accel-record README to accel-record-factory --- packages/accel-record/README-ja.md | 33 ++++++++++++++++++++++++++++-- packages/accel-record/README.md | 33 ++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/packages/accel-record/README-ja.md b/packages/accel-record/README-ja.md index ad109380..0bca38c8 100644 --- a/packages/accel-record/README-ja.md +++ b/packages/accel-record/README-ja.md @@ -783,6 +783,37 @@ export default { }; ``` +### モデルのFactory + +テスト用のレコードを生成するために、Factoryを利用することができます。 +詳細は[accel-record-factory](https://github.com/koyopro/accella/blob/main/packages/accel-record-factory/README-ja.md)を参照してください。 + +```ts +// tests/factories/user.ts + +import { defineFactory } from "accel-record-factory"; +import { User } from "../../src/models/index.js"; + +export const UserFactory = defineFactory(User, { + firstName: "John", + lastName: "Doe", + age: 20, +}); + +export { UserFactory as $User }; +``` + +```ts +// tests/user.test.ts + +import { $User } from "./factories/user"; + +const newUser = $User.build(); +newUser.firstName; // => "John" +newUser.lastName; // => "Doe" +newUser.age; // => 20 +``` + ## バリデーション ### バリデーションのサンプル @@ -917,7 +948,5 @@ user.update({ age: undefined }); - [accel-record-core] 複合IDの対応 - [accel-record-core] クエリインターフェースの拡充 - [accel-record-core] 国際化(I18n) -- [accel-record-factory] trait -- [prisma-generator-accel-record] 各モデル用Factoryの生成 関連: [Accel Record Roadmap](https://github.com/koyopro/accella/issues/1) diff --git a/packages/accel-record/README.md b/packages/accel-record/README.md index 289fbd08..b33b7424 100644 --- a/packages/accel-record/README.md +++ b/packages/accel-record/README.md @@ -782,6 +782,37 @@ export default { }; ``` +### Model Factory + +To generate test records, you can use a Factory. +Please refer to [accel-record-factory](https://github.com/koyopro/accella/blob/main/packages/accel-record-factory/README.md) for more details. + +```ts +// tests/factories/user.ts + +import { defineFactory } from "accel-record-factory"; +import { User } from "../../src/models/index.js"; + +export const UserFactory = defineFactory(User, { + firstName: "John", + lastName: "Doe", + age: 20, +}); + +export { UserFactory as $User }; +``` + +```ts +// tests/user.test.ts + +import { $User } from "./factories/user"; + +const newUser = $User.build(); +newUser.firstName; // => "John" +newUser.lastName; // => "Doe" +newUser.age; // => 20 +``` + ## Validation ### Sample Validation @@ -916,7 +947,5 @@ user.update({ age: undefined }); - [accel-record-core] Support for Composite IDs - [accel-record-core] Expansion of Query Interface - [accel-record-core] Internationalization (I18n) -- [accel-record-factory] Trait -- [prisma-generator-accel-record] Generation of Factories for each Model Related: [Accel Record Roadmap](https://github.com/koyopro/accella/issues/1)