Files
NodeBB/test/locale-detect.js

36 lines
878 B
JavaScript
Raw Normal View History

2017-04-21 23:54:59 -06:00
'use strict';
const assert = require('assert');
2021-02-04 00:06:15 -07:00
const nconf = require('nconf');
2017-04-21 23:54:59 -06:00
2021-02-04 00:06:15 -07:00
const db = require('./mocks/databasemock');
const meta = require('../src/meta');
const request = require('../src/request');
2017-04-21 23:54:59 -06:00
2021-02-04 00:01:39 -07:00
describe('Language detection', () => {
it('should detect the language for a guest', async () => {
await meta.configs.set('autoDetectLang', 1);
2017-04-21 23:54:59 -06:00
const { body } = await request.get(`${nconf.get('url')}/api/config`, {
headers: {
'Accept-Language': 'de-DE,de;q=0.5',
},
2017-04-21 23:54:59 -06:00
});
assert.ok(body);
assert.strictEqual(body.userLang, 'de');
2017-04-21 23:54:59 -06:00
});
it('should do nothing when disabled', async () => {
await meta.configs.set('autoDetectLang', 0);
2017-04-21 23:54:59 -06:00
const { body } = await request.get(`${nconf.get('url')}/api/config`, {
headers: {
'Accept-Language': 'de-DE,de;q=0.5',
},
2017-04-21 23:54:59 -06:00
});
assert.ok(body);
assert.strictEqual(body.userLang, 'en-GB');
2017-04-21 23:54:59 -06:00
});
});