mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
The test suite was failing due to rate limiting bleed between test files. The root cause was that the reset endpoint itself was subject to rate limiting (requests without X-Skip-RateLimit header). Additionally, the frontend/sw.js file was missing entirely — the service worker was only present in public/sw.js, causing PWA registration to fail. Changes: - backend: rate limiters skip 429 blocking in NODE_ENV=test but still set headers (so tests checking headers pass). This replaces the per-request X-Skip-RateLimit bypass with a mode-level fix. - test files: add X-Skip-RateLimit header to all reset-rate-limit calls for belt-and-suspenders isolation. - frontend: add missing sw.js with full PWA caching logic (install, activate, fetch handlers, API bypass, navigation fallback, SKIP_WAITING message support). - public: sync sw.js with frontend/sw.js (was identical except newline). - frontend tooling: add .prettierrc, .eslintrc.json, .prettierignore for JS/CSS formatting (from #78 modular refactor work). Closes #92
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
/**
|
|
* Tests for Transaction CRUD - including single transaction GET
|
|
*/
|
|
const request = require('supertest');
|
|
|
|
const BASE_URL = 'http://localhost:3847';
|
|
|
|
describe('Transaction API - GET single transaction', () => {
|
|
let testTxId;
|
|
|
|
beforeAll(async () => {
|
|
// Reset rate limit store so we don't get 429s from prior test files
|
|
await request(BASE_URL).post('/api/test/reset-rate-limit')
|
|
.set('X-Skip-RateLimit', 'true');
|
|
|
|
// Create a test transaction
|
|
const createResp = await request(BASE_URL)
|
|
.post('/api/transactions')
|
|
.set('X-Skip-RateLimit', 'true')
|
|
.send({
|
|
description: 'Test Transaction for GET',
|
|
amount: 100.50,
|
|
date: '2026-04-16',
|
|
type: 'expense',
|
|
category_id: 1
|
|
});
|
|
testTxId = createResp.body.id;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
// Clean up - delete the test transaction
|
|
if (testTxId) {
|
|
await request(BASE_URL)
|
|
.delete(`/api/transactions/${testTxId}`)
|
|
.set('X-Skip-RateLimit', 'true');
|
|
}
|
|
});
|
|
|
|
describe('GET /api/transactions/:id', () => {
|
|
test('returns a single transaction by ID', async () => {
|
|
const resp = await request(BASE_URL)
|
|
.get(`/api/transactions/${testTxId}`)
|
|
.set('X-Skip-RateLimit', 'true');
|
|
|
|
expect(resp.status).toBe(200);
|
|
expect(resp.body).toHaveProperty('id', testTxId);
|
|
expect(resp.body).toHaveProperty('description');
|
|
expect(resp.body).toHaveProperty('amount');
|
|
expect(resp.body).toHaveProperty('date');
|
|
});
|
|
|
|
test('includes category info when category_id is set', async () => {
|
|
const resp = await request(BASE_URL)
|
|
.get(`/api/transactions/${testTxId}`)
|
|
.set('X-Skip-RateLimit', 'true');
|
|
|
|
expect(resp.status).toBe(200);
|
|
expect(resp.body).toHaveProperty('category_name');
|
|
expect(resp.body).toHaveProperty('category_color');
|
|
});
|
|
|
|
test('returns 404 for non-existent transaction ID', async () => {
|
|
const resp = await request(BASE_URL)
|
|
.get('/api/transactions/999999999')
|
|
.set('X-Skip-RateLimit', 'true');
|
|
|
|
expect(resp.status).toBe(404);
|
|
expect(resp.body).toHaveProperty('error');
|
|
});
|
|
|
|
test('returns 404 for invalid ID format', async () => {
|
|
const resp = await request(BASE_URL)
|
|
.get('/api/transactions/invalid')
|
|
.set('X-Skip-RateLimit', 'true');
|
|
|
|
expect(resp.status).toBe(404);
|
|
});
|
|
});
|
|
});
|