Automated support for writing, maintaining, and fixing unit tests for Shared Reference Data with 90% coverage mandates.
Install
mkdir -p .claude/skills/unit-tests && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/14913" && unzip -o skill.zip -d .claude/skills/unit-tests && rm skill.zipInstalls to .claude/skills/unit-tests
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.
Expert unit test engineer for MMO Shared Reference Data. Use when: writing unit tests, updating tests for code changes, fixing failing tests, improving code coverage, fixing SonarQube issues.Key capabilities
- →Write unit tests for new or modified code
- →Fix failing unit tests after code changes
- →Maintain 90% code coverage for statements, branches, functions, and lines
- →Fix SonarQube issues and code smells
- →Mock external API dependencies (e.g., Boomi/CEFAS API)
- →Mock Azure Service Bus client interactions
How it works
The skill guides the creation and maintenance of unit tests using Jest and Sinon, providing specific mocking patterns for external dependencies and enforcing a 90% code coverage target.
Inputs & outputs
When to use unit-tests
- →Writing unit tests for new code
- →Fixing failing tests
- →Improving test coverage to 90%
- →Resolving SonarQube code smells
About this skill
Shared Reference Data — Unit Tests Skill
Expert in writing and maintaining unit tests for the MMO Shared Reference Data library. This shared library enforces tiered coverage targets.
When to Use
- Writing unit tests for new or modified code
- Fixing failing tests after code changes
- Maintaining the tiered coverage targets below
- Fixing SonarQube issues or code smells
Coverage Requirements
Tiered targets (aligned with copilot-instructions quality gates) — never drop below the SonarCloud baseline:
- ≥90% global — Statements, Functions, Lines, Branches
- ≥95% — core business logic (query functions, transformations, risk scoring, weight/overuse validation)
- 100% — error-handling and security-critical paths (OAuth2/API failures, Service Bus publish failures, input/date validation)
- Run tests:
npm test(single run with coverage report) - Watch mode:
npm run test:watch
Test Framework & Tools
- Jest as test runner with ts-jest
- sinon for stubs and spies
- Test files in
test/directory mirroringsrc/structure
Mocking Patterns
Boomi/CEFAS API (OAuth2)
// Mock both success and dual error handling
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
// Success
mockedAxios.post.mockResolvedValueOnce({ data: { access_token: 'token' } });
mockedAxios.get.mockResolvedValueOnce({ data: mockApiData });
// Error with response (HTTP error)
mockedAxios.get.mockRejectedValueOnce({
response: { status: 500, data: 'Server Error' },
});
// Error without response (network error)
mockedAxios.get.mockRejectedValueOnce(new Error('ECONNREFUSED'));
Azure Service Bus (Class-Based Mock)
// Class-based mocks for Service Bus client
const mockSender = {
sendMessages: jest.fn().mockResolvedValue(undefined),
close: jest.fn().mockResolvedValue(undefined),
};
const mockSbClient = {
createSender: jest.fn().mockReturnValue(mockSender),
close: jest.fn().mockResolvedValue(undefined),
};
jest.mock('@azure/service-bus', () => ({
ServiceBusClient: jest.fn().mockImplementation(() => mockSbClient),
}));
Filesystem Fallback (Queue Dev Mode)
jest.mock('fs/promises', () => ({
writeFile: jest.fn().mockResolvedValue(undefined),
mkdir: jest.fn().mockResolvedValue(undefined),
}));
Date Mocking for CEFAS
// CEFAS requires UTC dates in YYYY-MM-DD format
jest.spyOn(Date, 'now').mockImplementation(() => 1693751375000);
// Verify: moment.utc().format('YYYY-MM-DD') === '2023-09-03'
What to Test
- Barrel exports — verify all public API is exported from
src/index.ts - Boomi OAuth2 — token fetch, API call with bearer, dual error handling (
e.response+ direct) - Service Bus — send with sessionId, sender/client cleanup in
finally, filesystem fallback - Weight validation — overuse with 10% tolerance (estimated) and fixed buffer (actual), boundary values
- AJV validation — valid/invalid payloads, schema error reporting
- Type interfaces — ensure type guards match interface definitions
- Legacy SSL —
SSL_OP_LEGACY_SERVER_CONNECToption set on HTTPS agent - Date formatting —
moment.utc()produces correctYYYY-MM-DDfor CEFAS - Logging — bracketed format with Bunyan
SonarQube Issue Resolution
When fixing SonarQube issues, NEVER modify functionality. If existing tests fail after a fix, revert it. Only structural refactoring is allowed.
Workflow
- Identify the source file(s) that need tests
- Find existing test file or create new one mirroring
src/→test/path - Read the source code to understand ALL branches — cover every path to meet the tiered targets
- Write tests for every code path including error branches (error-handling/security paths need 100%)
- Run
npm testand verify coverage meets the tiered targets across all metrics - If any metric is below target, identify uncovered lines and add tests
- Check problems tab for SonarQube issues
When not to use it
- →When the code is not part of the MMO Shared Reference Data library
- →When the task is not related to unit testing or code quality
- →When modifying functionality to fix SonarQube issues
Limitations
- →Specific to the MMO Shared Reference Data library
- →Requires Jest as test runner and Sinon for stubs/spies
- →Does not allow modifying functionality to fix SonarQube issues
How it compares
This approach enforces a high standard of code quality and reliability by mandating 90% test coverage and providing specific mocking strategies for common external services, unlike less rigorous testing methodologies.
Compared to similar skills
unit-tests side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| unit-tests (this skill) | 0 | 5mo | Review | Intermediate |
| dependency-upgrade | 26 | 5mo | Review | Intermediate |
| lint-and-validate | 6 | 6mo | Review | Beginner |
| customaize-agent:create-hook | 0 | 5mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
dependency-upgrade
wshobson
Manage major dependency version upgrades with compatibility analysis, staged rollout, and comprehensive testing. Use when upgrading framework versions, updating major dependencies, or managing breaking changes in libraries.
lint-and-validate
davila7
Automatic quality control, linting, and static analysis procedures. Use after every code modification to ensure syntax correctness and project standards. Triggers onKeywords: lint, format, check, validate, types, static analysis.
customaize-agent:create-hook
LAI-YEN-CHUN
Create and configure git hooks with intelligent project analysis, suggestions, and automated testing
verify
hoangsonww
Run Forge's canonical verification chain (format:check + lint + typecheck + build + test). Use before claiming any task done or opening a PR.
myot-validate
simpsonys
Run MYOT project validation commands (lint and build) and report results.
lint-js
y1feng200156
Check JavaScript/TypeScript code quality with ESLint