From 6432c02ab80f0832539c02cbc1843a6d755a0a01 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Fri, 21 Apr 2017 23:54:59 -0600 Subject: [PATCH] Add tests --- test/locale-detect.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/locale-detect.js diff --git a/test/locale-detect.js b/test/locale-detect.js new file mode 100644 index 0000000000..84ea5af59c --- /dev/null +++ b/test/locale-detect.js @@ -0,0 +1,41 @@ +'use strict'; + +var assert = require('assert'); +var nconf = require('nconf'); +var request = require('request'); + +var meta = require('../src/meta'); + +describe('Language detection', function () { + it('should detect the language for a guest', function (done) { + request(nconf.get('url') + '/api/config', { + headers: { + 'Accept-Language': 'de-DE,de;q=0.5', + }, + }, function (err, res, body) { + assert.ifError(err); + assert.ok(body); + + assert.strictEqual(JSON.parse(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', + }, + }, function (err, res, body) { + assert.ifError(err); + assert.ok(body); + + assert.strictEqual(JSON.parse(body).userLang, 'en-GB'); + done(); + }); + }); + }); +});