express-tongue
Version:
Localization library for Express. It works with every template engine and exposes a json endpoint to consume on client side.
104 lines (95 loc) • 3.44 kB
JavaScript
/**
* @author: Carlos Luis Castro Márquez
*/
const expect = require("chai").expect;
const app = require("../server").app;
const request = require("supertest");
describe("Localization", function () {
it("localization endpoint available", function (done) {
request(app)
.get("/i18n")
.expect(200)
.end(function (err, res) {
expect(res.body).to.not.null();
const json = res.body;
expect(json).to.be.an("object");
expect(json.lang).to.be.a("string");
expect(json.language).to.be.a("string");
expect(json.strings).to.be.a("object");
done(err);
});
});
it("localization languages available", function (done) {
request(app)
.get("/i18n/languages")
.expect(200)
.end(function (err, res) {
expect(res.body).to.not.null();
const json = res.body;
expect(json).to.be.an("array");
done(err);
});
});
it("localization strings available", function (done) {
request(app)
.get("/i18n/strings")
.expect(200)
.end(function (err, res) {
expect(res.body).to.not.null();
const json = res.body;
expect(json).to.be.an("object");
expect(json.test).to.not.null();
done(err);
});
});
it("localization in default lang (en)", function (done) {
request(app)
.get("/i18n")
.expect(200)
.end(function (err, res) {
expect(res.body).to.not.null();
const json = res.body;
expect(json).to.be.an("object");
expect(json.lang).to.be.a("string");
expect(json.language).to.be.a("string");
expect(json.strings).to.be.a("object");
expect(json.lang).to.equal("en");
done(err);
});
});
it("localization in spanish using User-Agent", function (done) {
request(app)
.get("/i18n")
.set("Accept-Language", "es")
.expect(200)
.end(function (err, res) {
expect(res.body).to.not.null();
const json = res.body;
expect(json).to.be.an("object");
expect(json.lang).to.be.a("string");
expect(json.language).to.be.a("string");
expect(json.strings).to.be.a("object");
expect(json.lang).to.equal("es");
done(err);
});
});
it("localization in spanish using QueryString", function (done) {
request(app)
.get("/i18n?hl=es")
.expect(200)
.end(function (err, res) {
expect(res.body).to.not.null();
const json = res.body;
expect(json).to.be.an("object");
expect(json.lang).to.be.a("string");
expect(json.language).to.be.a("string");
expect(json.strings).to.be.a("object");
expect(json.lang).to.equal("es");
expect("set-cookie", "cookie=xp_i18n_lang; Path=/");
done(err);
});
});
after(function () {
process.exit();
});
});