const request = require('supertest'); jest.mock('../../server/routes', () => ({ mountApiRoutes(app) { app.post('/api/fixture', (req, res) => res.json(req.body)); }, })); jest.mock('../middlewares/response-telemetry.middleware', () => ({ transactionRequest(req, res, next) { next(); }, response(req, res, next) { next(); }, })); const app = require('../../server'); test('entry point menyajikan halaman utama, file publik, dan metrik', async () => { await request(app).get('/').expect(200, { message: 'Welcome to Topup Online Service.', data: {} }); await request(app).get('/images/logo_portal_kmt.png').expect(200).expect('Content-Type', /image\/png/); await request(app).get('/metrics').expect(200).expect('Content-Type', /text\/plain/); }); test('entry point mempertahankan parse JSON, form, dan header CORS', async () => { await request(app).post('/api/fixture') .set('Origin', 'http://localhost:3000') .send({ code: '00' }) .expect('Access-Control-Allow-Origin', 'http://localhost:3000') .expect('Access-Control-Expose-Headers', 'X-Request-Id,X-Response-Time') .expect(200, { code: '00' }); await request(app).post('/api/fixture') .type('form').send({ code: '00' }) .expect(200, { code: '00' }); }); test('request ID dibuat oleh server, termasuk ketika body JSON tidak valid', async () => { const malformed = await request(app).post('/api/fixture') .set('X-Request-Id', 'client-value') .type('json').send('{') .expect(400); const success = await request(app).post('/api/fixture').send({ code: '00' }).expect(200); expect(malformed.headers['x-request-id']).toMatch(/^[a-f\d-]{36}$/); expect(success.headers['x-request-id']).toMatch(/^[a-f\d-]{36}$/); expect(malformed.headers['x-request-id']).not.toBe(success.headers['x-request-id']); });