- Fix detectLanguage() to sort by HTTP q-values per RFC 7231 (was first-match-wins)
- Strict qvalue grammar: /^(0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/
- Exclude q=0 entries (not acceptable per RFC)
- Case-insensitive Q parameter name
- Fix 5 stale tests: zh/ja now supported (31 languages, not 5)
- Add 7 boundary regression tests for q-value parsing
- All 1781 tests pass
Codex grade: B (urn:ump:6yumklcezgiaemcg5t2mebuoi4w2n5dexozm4j7h5pu5g2s4p5ta)
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 31 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(31);
|
|
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');
|
|
});
|
|
});
|