agentsclimarketplace

Workflow test factory

Skill marzun9620/agent_skills/workflow/skills/workflow-test-factory

My personal Claude Code skills — 59 of them. Use any, fork the repo, or contribute yours. Install with /plugin marketplace add marzun9620/agent_skills

Install
npx -y skills add marzun9620/agent_skills --skill workflow-test-factory

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Test Factory authoring guide — Factory pattern for inserting rows into the database. Used in Drizzle ORM + Vitest environments. Triggers: Factory creation, test data, test helper, EntityFactory, create, build, test fixture.

SKILL.md

2.8 KB, 764 tokens by cl100k_base, as published. Nobody here has run it

テスト Factory 実装手順

ADR-0005 準拠。Integration test で使用するテストデータ生成用の Factory。

ファイル配置

ファイル: apps/datahub/tests/factories/{entity}Factory.ts

既存の Factory を必ず読む

実装前に既存の Factory ファイルを読んでパターンを踏襲すること:

ls apps/datahub/tests/factories/

Factory パターン

import { randomUUID } from "node:crypto";
import type { DrizzleDb } from "~/infrastructure/db/index.js";
import { entitiesInHw } from "~/infrastructure/db/index.js";

type EntityInsert = typeof entitiesInHw.$inferInsert;

const defaults: EntityInsert = {
  publicId: randomUUID(),
  name: "Test Entity",
  status: "ACTIVE",
};

export const EntityFactory = {
  /**
   * DB に insert して返す(integration test 用)
   */
  create: async (db: DrizzleDb, overrides?: Partial<EntityInsert>) => {
    const data = { ...defaults, publicId: randomUUID(), ...overrides };
    const [row] = await db.insert(entitiesInHw).values(data).returning();
    return row;
  },

  /**
   * DB に insert せず、テストデータのみ生成(unit test 用)
   */
  build: (overrides?: Partial<EntityInsert>): EntityInsert => ({
    ...defaults,
    publicId: randomUUID(),
    ...overrides,
  }),
};

重要ルール

  • create は毎回 randomUUID() で一意な publicId を生成(テスト間の干渉を防ぐ)
  • defaults にデフォルト値を定義(テストケースは必要なフィールドだけ override)
  • createreturning() で insert した行を返す
  • build は DB に触らず、テストデータのみ返す(unit test 向け)
  • import は barrel 経由: ~/infrastructure/db/index.js

テストでの使い方

import { EntityFactory } from "../../factories/entityFactory.js";
import { getDb } from "../../helpers/db.js";

// Arrange
const db = getDb();
const entity = await EntityFactory.create(db);
const entityId = EntityId.make(entity.publicId);

// override 付き
const entity = await EntityFactory.create(db, { name: "Custom Name", status: "ARCHIVED" });

// unit test 用(DB なし)
const data = EntityFactory.build({ name: "Test" });

チェックリスト

  • create が毎回一意な publicId を生成
  • defaults にデフォルト値を定義
  • createreturning() で行を返す
  • build が DB に触らない
  • 既存の Factory パターンを踏襲
  • import が barrel 経由

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 327,069. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.