mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:56:27 +00:00
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
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', () => ({
|
|
correlation(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' });
|
|
});
|