qmemory
Version:
A comprehensive production-ready Node.js utility library with MongoDB document operations, user ownership enforcement, Express.js HTTP utilities, environment-aware logging, and in-memory storage. Features 96%+ test coverage with comprehensive error handli
63 lines (50 loc) • 1.8 kB
text/typescript
// Generated integration test for DELETE /users/:id - TypeScript ES module
// 🚩AI: ENTRY_POINT_FOR_GENERATED_TEST_IMPORTS
import 'qtests/setup';
import { createMockApp, supertest } from '../utils/httpTest';
// Deterministic test helpers
beforeEach(() => {
// Use fake timers for deterministic time-based behavior
jest.useFakeTimers().setSystemTime(new Date('2023-01-01T00:00:00Z'));
});
afterEach(() => {
jest.useRealTimers();
});
// Deterministic unique route for parallel test safety
const testHash = require('crypto').createHash('md5').update('/users/:id').digest('hex').slice(0, 8);
const uniqueRoute = '/users/:id' + ('/users/:id'.includes('?') ? '&' : '?') + 'testId=' + testHash;
describe('DELETE /users/:id', () => {
let app: ReturnType<typeof createMockApp>;
beforeEach(() => {
app = createMockApp();
});
it('should return success response', async () => {
// Setup route handler
app.delete(uniqueRoute, (req, res) => {
res.statusCode = 200;
res.setHeader('content-type', 'application/json');
res.end(JSON.stringify({
success: true,
message: 'Request processed successfully'
}));
});
// Execute test
const res = await supertest(app)
.delete(uniqueRoute)
.send({ testData: 'valid input' })
.expect(200);
// Verify response
expect(res.body.success).toBe(true);
expect(res.body.message).toBe('Request processed successfully');
});
it('should handle not found case', async () => {
// Don't setup any route handlers to simulate 404
// Execute test
const res = await supertest(app)
.delete('/nonexistent-route')
.send({ testData: 'any data' })
.expect(404);
// Verify error response
expect(res.body.error).toBe('Not Found');
});
});