testing-patterns-unit

testing-patterns-unit is a cursor rule for Cursor from lambda-curry/medusa2-starter. It costs 1,532 tokens per session, scanned A, original, MIT.

A set of unit testing rules for Medusa applications. Unit tests check one function, service, component, or hook in isolation, often using test doubles for outside dependencies.

In plain words
What is it for?
Use it to test Medusa services, React components, and hooks with readable Arrange-Act-Assert tests, mocks, and stubs.
Why use it?
It gives a consistent way to test small pieces without requiring the whole application or its real services to run.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is import { UserService } from "../UserService".

Good fit Use it to test Medusa services, React components, and hooks with readable Arrange-Act-Assert tests, mocks, and stubs.

Compare 6 cursor rules from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/lambda-curry/medusa2-starter
agentmods
npx agentmods add rules/lambda-curry/medusa2-starter/testing-patterns-unit

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for testing-patterns-unit

README.md
[![agentmods](https://agentmods.dev/badge/rules/lambda-curry/medusa2-starter/testing-patterns-unit/github.svg)](https://agentmods.dev/rules/lambda-curry/medusa2-starter/testing-patterns-unit)
Your own site
<a href="https://agentmods.dev/rules/lambda-curry/medusa2-starter/testing-patterns-unit"><img src="https://agentmods.dev/badge/rules/lambda-curry/medusa2-starter/testing-patterns-unit/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for testing-patterns-unit

Your own site · 80×15
<a href="https://agentmods.dev/rules/lambda-curry/medusa2-starter/testing-patterns-unit"><img src="https://agentmods.dev/badge/rules/lambda-curry/medusa2-starter/testing-patterns-unit.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 1,532 This file is loaded in full into every session.
When invoked 1,532 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.01532 $0.01532
Opus 5.5 $0.00613 $0.00613
Sonnet 5.5 $0.00306 $0.00306
Haiku 4.5 $0.00153 $0.00153

Measured 15d ago against content hash 449005f1f929, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

testing-patterns-unit scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 15d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/testing-patterns-unit.mdc · 241 lines

How it starts

The opening of the file, as written. The whole thing — 241 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Unit Testing Patterns for Medusa Applications

You are an expert in unit testing TypeScript applications, focusing on testing individual components, services, and functions in isolation for Medusa and React applications.

Core Testing Principles

  • Write tests that are readable, maintainable, and reliable
  • Focus on testing individual units in isolation
  • Use descriptive test names that explain the behavior being tested
  • Arrange, Act, Assert (AAA) pattern for test structure
  • Test behavior, not implementation details
  • Use proper mocking and stubbing strategies
  • Ensure tests are isolated and can run independently

Unit Testing Patterns

Medusa Service Testing

// services/__tests__/UserService.test.ts
import { createMedusaContainer } from "@medusajs/framework/utils"
import { UserService } from "../UserService"
import { User } from "../models/User"

describe("UserService", () => {
  let container: MedusaContainer
  let userService: UserService
  let mockRepository: jest.Mocked<any>

  beforeEach(() => {
    container = createMedusaContainer()
    
    mockRepository = {
      create: jest.fn(),
      findOne: jest.fn(),
      update: jest.fn(),
      delete: jest.fn(),
    }
    
    container.register("userRepository", mockRepository)
    userService = container.resolve("userService")
  })

  describe("create", () => {
    it("should create a new user with valid data", async () => {
      // Arrange
      const userData = {
        name: "John Doe",
        email: "[email protected]",
      }
      const expectedUser = { id: "user_123", ...userData }
      mockRepository.create.mockResolvedValue(expectedUser)

      // Act
      const result = await userService.create(userData)

      // Assert
      expect(mockRepository.create).toHaveBeenCalledWith(userData)
      expect(result).toEqual(expectedUser)
    })

    it("should throw validation error for invalid email", async () => {
      // Arrange
      const invalidUserData = {
        name: "John Doe",
        email: "invalid-email",
      }

      // Act & Assert
      await expect(userService.create(invalidUserData))
        .rejects
        .toThrow("Invalid email format")
    })
  })

  describe("findById", () => {
    it("should return user when found", async () => {
      // Arrange
      const userId = "user_123"
      const expectedUser = { id: userId, name: "John Doe" }
      mockRepository.findOne.mockResolvedValue(expectedUser)

      // Act
      const result = await userService.findById(userId)

      // Assert
      expect(mockRepository.findOne).toHaveBeenCalledWith({ id: userId })
      expect(result).toEqual(expectedUser)
    })

    it("should return null when user not found", async () => {
      // Arrange
      const userId = "nonexistent"
      mockRepository.findOne.mockResolvedValue(null)

      // Act
      const result = await userService.findById(userId)

      // Assert
      expect(result).toBeNull()
    })
  })
})

Read the full file on GitHub · 241 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 15d ago First seen · 241 lines · 1,532 tokens per session scan A 449005f1f929

Subscribe to this mod's changes

testing-patterns-unit is a cursor rule published in the GitHub repository lambda-curry/medusa2-starter (164 stars, last pushed 17d ago), licensed MIT. It adds 1,532 tokens to every session, about $0.0061 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-15.

Related

testing-patterns-unit compared with cursor rules from other repositories

testing-patterns-unit next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
testing-patterns-unitlambda-curry/medusa2-starterCursor rule16417d agoMITA1,532Cursor
use-contract-ir-factoriesprisma/ormCursor rule48ktodayApache-2.0A0Cursor
mockitosanjeed5/awesome-cursor-rules-mdcCursor rule3.6k7d agoCC0-1.0A1,653Cursor
gonavi-goSyngnat/GoNaviCursor rule2.1ktodayApache-2.0A0Cursor
python-general-coding-standardsholtwood/awesome-cursorrules-zhCursor rule2441mo agoMITA140Cursor
project-conventionskequach/uniqlo-sales-alerterCursor rule32yesterdayMITA1,033Cursor
spec-for-utdtyq/magicCursor rule5.1k1mo agononeA528Cursor