Skip to content

Commit

Permalink
add link from accel-record README to accel-record-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
koyopro committed May 14, 2024
1 parent ebc8847 commit 7e1d7c9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
33 changes: 31 additions & 2 deletions packages/accel-record/README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
## バリデーション
### バリデーションのサンプル
Expand Down Expand Up @@ -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)
33 changes: 31 additions & 2 deletions packages/accel-record/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 7e1d7c9

Please sign in to comment.