IN

integration-testing

A guide for writing integration tests in clinica-angel, utilizing supertest and Prisma for reliable API and database validation.

Install

mkdir -p .claude/skills/integration-testing && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/15370" && unzip -o skill.zip -d .claude/skills/integration-testing && rm skill.zip

Installs to .claude/skills/integration-testing

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Patterns and best practices for writing integration tests in clinica-angel. Trigger: When creating or modifying *.int.test.js files, testing Express routes, or setting up test data with Prisma.
193 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Write integration tests for new features
  • Test API endpoints using `supertest`
  • Validate business rules involving a database
  • Simulate authentication with cookies
  • Handle file uploads in tests
  • Verify database state after mutations

How it works

The skill outlines patterns for setting up integration tests, including using `supertest` for API calls, `prisma` for database interactions, and specific methods for authentication and file uploads.

Inputs & outputs

You give it
API endpoint requests, test data, file buffers
You get back
HTTP responses, updated database states, test results

When to use integration-testing

  • Write integration tests for new features
  • Test API endpoints with supertest
  • Validate business logic involving database state
  • Mock authentication for protected routes

About this skill

When to Use

Use this skill when:

  • Adding integration tests for new features.
  • Testing API endpoints or SSR controllers.
  • Validating business rules that involve a database.
  • Testing file uploads or authentication-protected routes.

Critical Patterns

1. Test Setup & Tools

  • Framework: Use supertest to hit endpoints.
  • Database: Use the shared prisma client (src/_shared/infrastructure/prisma.js).
  • File Naming: Always use the .int.test.js suffix for integration tests.
  • Imports:
    import request from "supertest";
    import app from "../../app.js";
    import { prisma } from "../../_shared/infrastructure/prisma.js";
    import { generateToken } from "../../auth/infrastructure/jwt.js";
    import { Roles } from "../../auth/domain/roles.js";
    

2. Authentication

Most routes are protected by roles. Simulate authentication by setting a cookie:

const adminToken = generateToken({ sub: 999, role: Roles.ADMIN });

const response = await request(app)
  .post("/some-endpoint")
  .set("Cookie", `access_token=${adminToken}`)
  .send(payload);

3. Handling File Uploads

For endpoints using multer (like patient registration), use .field() and .attach() instead of .send():

const imageBuffer = Buffer.from("..."); // Min valid PNG or mock data
const response = await request(app)
  .post("/patients")
  .field("email", "[email protected]")
  .attach("nationalIdImage", imageBuffer, "test-id.png");

4. Filesystem Cleanup

If a test creates files (uploads), ALWAYS clean them up in afterEach:

import { unlink } from "node:fs/promises";
import { join } from "node:path";

afterEach(async () => {
  const users = await prisma.user.findMany({
    where: { email: { in: testEmails } },
  });
  for (const user of users) {
    if (user.nationalIdImageUrl) {
      const filename = user.nationalIdImageUrl.replace(/^\/uploads\//, "");
      const filePath = join("src", "_assets", "uploads", filename);
      try {
        await unlink(filePath);
      } catch {}
    }
  }
});

5. Verification

Don't just check status codes. Verify the database state after mutations:

expect(response.status).toBe(201);
const stored = await prisma.specialty.findFirst({
  where: { name: "Neurología" },
});
expect(stored).not.toBeNull();

Code Examples

Standard CRUD Post

test("creates a resource successfully", async () => {
  const res = await request(app)
    .post("/items")
    .set("Cookie", `access_token=${token}`)
    .send({ name: "Testing" });

  expect(res.status).toBe(201);
  expect(res.text).toContain("creado correctamente");
});

Testing Validation Errors (Zod/422)

test("returns 422 when data is invalid", async () => {
  const res = await request(app)
    .post("/items")
    .set("Cookie", `access_token=${token}`)
    .send({ name: "" }); // Empty name

  expect(res.status).toBe(422);
});

Commands

# Run all integration tests
pnpm test

# Run a specific test file
pnpm test src/users/infrastructure/user-register.int.test.js

# Run tests matching a pattern
pnpm test -t "registers a user"

When not to use it

  • When writing unit tests
  • When testing frontend UI components without backend interaction
  • When not using Express or Prisma

Prerequisites

supertestprisma

Limitations

  • Requires `.int.test.js` suffix for test files
  • Authentication simulation relies on setting a cookie
  • File cleanup is required for tests that create files

How it compares

This skill provides a structured approach for integration testing specific to Express and Prisma, offering concrete patterns for common scenarios like authentication and file uploads, unlike general testing guidelines.

Compared to similar skills

integration-testing side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
integration-testing (this skill)06moReviewIntermediate
bullmq-specialist256moNo flagsIntermediate
senior-backend148moReviewAdvanced
database-migration32moNo flagsAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

bullmq-specialist

davila7

BullMQ expert for Redis-backed job queues, background processing, and reliable async execution in Node.js/TypeScript applications. Use when: bullmq, bull queue, redis queue, background job, job queue.

2595

senior-backend

davila7

Comprehensive backend development skill for building scalable backend systems using NodeJS, Express, Go, Python, Postgres, GraphQL, REST APIs. Includes API scaffolding, database optimization, security implementation, and performance tuning. Use when designing APIs, optimizing database queries, implementing business logic, handling authentication/authorization, or reviewing backend code.

1446

database-migration

wshobson

Execute database migrations across ORMs and platforms with zero-downtime strategies, data transformation, and rollback procedures. Use when migrating databases, changing schemas, performing data transformations, or implementing zero-downtime deployment strategies.

324

agent-dev-backend-api

ruvnet

Agent skill for dev-backend-api - invoke with $agent-dev-backend-api

318

rate-limiting-apis

jeremylongshore

Implement sophisticated rate limiting with sliding windows, token buckets, and quotas. Use when protecting APIs from excessive requests. Trigger with phrases like "add rate limiting", "limit API requests", or "implement rate limits".

15

orchardcore-tester

OrchardCMS

Tests OrchardCore CMS features through browser automation. Use when the user needs to build, run, setup, or test OrchardCore functionality including admin features, content management, media library, and module testing.

14

Search skills

Search the agent skills registry