63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
/**
|
|
* DC-077 i18n route + DC-071 error tracker route tests
|
|
*/
|
|
const express = require('express');
|
|
const request = require('supertest');
|
|
|
|
function createI18nApp() {
|
|
const app = express();
|
|
app.use(express.json());
|
|
const routes = require('../../routes/i18n');
|
|
const wrap = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
|
|
app.use('/api/v1', routes());
|
|
return app;
|
|
}
|
|
|
|
describe('DC-077: i18n Routes', () => {
|
|
it('GET /i18n/languages returns 5 languages', async () => {
|
|
const app = createI18nApp();
|
|
const res = await request(app).get('/api/v1/i18n/languages');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.success).toBe(true);
|
|
expect(res.body.languages).toHaveLength(5);
|
|
expect(res.body.default).toBe('en');
|
|
});
|
|
|
|
it('GET /i18n/languages includes RTL flag for Arabic', async () => {
|
|
const app = createI18nApp();
|
|
const res = await request(app).get('/api/v1/i18n/languages');
|
|
|
|
const arabic = res.body.languages.find(l => l.code === 'ar');
|
|
expect(arabic).toBeTruthy();
|
|
expect(arabic.rtl).toBe(true);
|
|
});
|
|
|
|
it('GET /i18n/translations/en returns English translations', async () => {
|
|
const app = createI18nApp();
|
|
const res = await request(app).get('/api/v1/i18n/translations/en');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.lang).toBe('en');
|
|
expect(res.body.translations['dashboard.title']).toBe('Dashboard');
|
|
});
|
|
|
|
it('GET /i18n/translations/es returns Spanish translations', async () => {
|
|
const app = createI18nApp();
|
|
const res = await request(app).get('/api/v1/i18n/translations/es');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.lang).toBe('es');
|
|
expect(res.body.translations['dashboard.title']).toBe('Panel de control');
|
|
});
|
|
|
|
it('GET /i18n/translations/xx returns 400 for unsupported', async () => {
|
|
const app = createI18nApp();
|
|
const res = await request(app).get('/api/v1/i18n/translations/xx');
|
|
|
|
expect(res.status).toBe(400);
|
|
expect(res.body.success).toBe(false);
|
|
expect(res.body.supported).toContain('en');
|
|
});
|
|
});
|