From monotemplate
Add and manage integration tests for repositories and API endpoints. Use when adding integration tests, testing a repository, testing an API endpoint, or setting up integration test infrastructure.
How this skill is triggered — by the user, by Claude, or both
Slash command
/monotemplate:integration-testsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Two test categories: **Repository tests** (direct DB via Prisma) and **API tests** (HTTP via supertest).
Two test categories: Repository tests (direct DB via Prisma) and API tests (HTTP via supertest).
truncateAllTables() in beforeEach — wipes all data between testsresetSeq() in beforeEach — resets the factory sequence counter for predictable IDsimport { PrismaClient } from "@server/generated/prisma";
import { SomeRepository } from "@server/repositories/SomeRepository";
import { createTestPrismaClient, truncateAllTables } from "../utils/db/prisma-test-client";
import { resetSeq } from "../utils/db/test-factories";
let prisma: PrismaClient;
let repo: SomeRepository;
beforeAll(() => {
prisma = createTestPrismaClient();
repo = new SomeRepository(prisma);
});
beforeEach(async () => {
await truncateAllTables(prisma);
resetSeq();
});
afterAll(async () => {
await prisma.$disconnect();
});
Repository tests instantiate repos directly with the test PrismaClient — they bypass DI.
import request from "supertest";
import type { Express } from "express";
import { PrismaClient } from "@server/generated/prisma";
import { resetMockAuth, setMockUserId } from "../utils/api/auth-helper";
import createApp from "@server/server";
import { createTestPrismaClient, truncateAllTables } from "../utils/db/prisma-test-client";
import { resetSeq } from "../utils/db/test-factories";
let app: Express;
let prisma: PrismaClient;
beforeAll(async () => {
app = createApp();
prisma = createTestPrismaClient();
});
beforeEach(async () => {
await truncateAllTables(prisma);
resetSeq();
resetMockAuth();
});
afterAll(async () => {
await prisma.$disconnect();
});
API tests use the real Express app with mocked auth via DI container rebinding. Use setMockUserId() to set the authenticated user and resetMockAuth() to clear it.
export async function createEntity(
prisma: PrismaClient,
overrides: Partial<{ field1: string; field2: string }> = {},
) {
const n = seq();
return prisma.entities.create({
data: {
field1: overrides.field1 ?? `Default ${n}`,
field2: overrides.field2 ?? `value-${n}`,
},
});
}
seq() returns an auto-incrementing number for unique defaultsoverrides partial lets tests specify only the fields they care abouttests/integration/utils/db/test-factories.tstruncateAllTables() in FK-safe order in tests/integration/utils/db/prisma-test-client.tstests/integration/repositories/<Entity>Repository.integration.test.tstests/integration/api/<entity>.integration.test.ts*.integration.test.tssetMockUserId())If integration test infrastructure doesn't exist yet, see setup.md for the one-time setup guide.
npx claudepluginhub firstloophq/claude-code-plugins --plugin monotemplateProvides patterns for writing integration tests with real databases, test containers, and API endpoints using Prisma, PostgreSQL, and supertest.
Configures .NET integration tests using WebApplicationFactory and Testcontainers for real PostgreSQL, with Respawn for fast cleanup and authentication helpers.
Sets up integration tests across databases, APIs, and message queues using Testcontainers, with DB seeding, cleanup strategies, and Docker dependencies.