cleanup-cache
Clean system caches (npm, Homebrew, Yarn, browsers, Python/ML) to free disk space
Test and validate Next.js API routes with comprehensive test scenarios
$ npx -y skills add davila7/claude-code-templates --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
/nextjs-api-testerContext preview
What this command does when you run it.
Test and validate Next.js API routes with comprehensive test scenarios
allowed-tools: Read, Write, Edit, Bash
argument-hint: [route-path] [--method=GET] [--data='{}'] [--headers='{}']
description: Test and validate Next.js API routes with comprehensive test scenarios**API Route**: $ARGUMENTS
Based on the provided route path, analyze:
// Basic API route test template
describe('API Route: /api/[route-path]', () => {
describe('GET requests', () => {
test('should return 200 for valid request', async () => {
const response = await fetch('/api/[route-path]');
expect(response.status).toBe(200);
});
test('should return valid JSON response', async () => {
const response = await fetch('/api/[route-path]');
const data = await response.json();
expect(data).toBeDefined();
expect(typeof data).toBe('object');
});
});
describe('POST requests', () => {
test('should create resource with valid data', async () => {
const testData = { name: 'Test', email: 'test@example.com' };
const response = await fetch('/api/[route-path]', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(testData)
});
expect(response.status).toBe(201);
const result = await response.json();
expect(result.name).toBe(testData.name);
});
test('should reject invalid data', async () => {
const invalidData = { invalid: 'field' };
const response = await fetch('/api/[route-path]', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(invalidData)
});
expect(response.status).toBe(400);
});
});
});describe('Authentication', () => {
test('should require authentication for protected routes', async () => {
const response = await fetch('/api/protected-route');
expect(response.status).toBe(401);
});
test('should allow authenticated requests', async () => {
const token = 'valid-jwt-token';
const response = await fetch('/api/protected-route', {
headers: { 'Authorization': `Bearer ${token}` }
});
expect(response.status).not.toBe(401);
});
test('should validate JWT token format', async () => {
const invalidToken = 'invalid-token';
const response = await fetch('/api/protected-route', {
headers: { 'Authorization': `Bearer ${invalidToken}` }
});
expect(response.status).toBe(403);
});
});describe('Input Validation', () => {
const validationTests = [
{ field: 'email', invalid: 'not-an-email', valid: 'test@example.com' },
{ field: 'phone', invalid: '123', valid: '+1234567890' },
{ field: 'age', invalid: -1, valid: 25 },
{ field: 'name', invalid: '', valid: 'John Doe' }
];
validationTests.forEach(({ field, invalid, valid }) => {
test(`should validate ${field} field`, async () => {
const invalidData = { [field]: invalid };
const validData = { [field]: valid };
// Test invalid data
const invalidResponse = await fetch('/api/[route-path]', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(invalidData)
});
expect(invalidResponse.status).toBe(400);
// Test valid data
const validResponse = await fetch('/api/[route-path]', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(validData)
});
expect(validResponse.status).not.toBe(400);
});
});
});describe('Error Handling', () => {
test('should handle malformed JSON', async () => {
const response = await fetch('/api/[route-path]', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: 'invalid-json'
});
expect(response.status).toBe(400);
});
test('should handle missing Content-Type header', async () => {
const response = await fetch('/api/[route-path]', {
method: 'POST',
body: JSON.stringify({ test: 'data' })
});
expect(response.status).toBe(400);
});
test('should handle request timeout', async () => {
// Mock slow endpoint
jest.setTimeout(5000);
const response = await fetch('/api/slow-endpoint');
// Test appropriate timeout handling
}, 5000);
test('should handle database connection errors', async () => {
// Mock database failure
const mockDbError = jest.spyOn(db, 'connect').mockRejectedValue(new Error('DB Error'));
const response = await fetch('/api/[route-path]');
expect(response.status).toBe(500);
mockDbError.mockRestore();
});
});describe('Performance', () => {
test('should respond within acceptable time', async () => {
const startTiReady-to-use configurations for Anthropic's Claude Code. A comprehensive collection of AI agents, custom commands, settings, hooks, external integrations (MCPs), and project templates to enhance your development workflow.
Repo: davila7/claude-code-templates
Clean system caches (npm, Homebrew, Yarn, browsers, Python/ML) to free disk space
Create an SEO-optimized blog article for a Claude Code component with AI-generated cover image