mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
* fix: #7038, autoLocale logic not playing nicely with no-refresh auths - on login, req.query.lang is deleted (since it seems to be left over) - on logout, the middleware.autoLocale is executed, which resets req.query.lang - middleware.autoLocale is new, just refactored existing logic in webserver.js into new middleware method. * style: tests, use lodash * fix: timeago strings not switching languages on login or out
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
var assert = require('assert');
|
|
var nconf = require('nconf');
|
|
var request = require('request');
|
|
|
|
var db = require('./mocks/databasemock');
|
|
var meta = require('../src/meta');
|
|
|
|
describe('Language detection', function () {
|
|
it('should detect the language for a guest', function (done) {
|
|
meta.configs.set('autoDetectLang', 1, function (err) {
|
|
assert.ifError(err);
|
|
request(nconf.get('url') + '/api/config', {
|
|
headers: {
|
|
'Accept-Language': 'de-DE,de;q=0.5',
|
|
},
|
|
json: true,
|
|
}, function (err, res, body) {
|
|
assert.ifError(err);
|
|
assert.ok(body);
|
|
|
|
assert.strictEqual(body.userLang, 'de');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should do nothing when disabled', function (done) {
|
|
meta.configs.set('autoDetectLang', 0, function (err) {
|
|
assert.ifError(err);
|
|
request(nconf.get('url') + '/api/config', {
|
|
headers: {
|
|
'Accept-Language': 'de-DE,de;q=0.5',
|
|
},
|
|
json: true,
|
|
}, function (err, res, body) {
|
|
assert.ifError(err);
|
|
assert.ok(body);
|
|
|
|
assert.strictEqual(body.userLang, 'en-GB');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|