feat: allow custom locale store cookie domain (#33)

* test: use mocha@4
This commit is contained in:
fengmk2
2019-04-17 10:43:00 +08:00
committed by GitHub
parent b3c8ab19e5
commit 08037ee0ae
6 changed files with 50 additions and 12 deletions

View File

@@ -35,7 +35,7 @@ describe('koa-locales.test.js', function () {
'gender': 'model.user.fields.gender',
'name': 'model.user.fields.name',
})
.expect('Set-Cookie', /^locale=en\-us; path=\/; expires=\w+/)
.expect('Set-Cookie', /^locale=en\-us; path=\/; expires=[^;]+ GMT$/)
.expect(200, done);
});
@@ -50,6 +50,37 @@ describe('koa-locales.test.js', function () {
});
});
describe('options.cookieDomain', function () {
const app = createApp({
cookieDomain: '.foo.com',
});
it('should use default locale: en-US', function (done) {
request(app.callback())
.get('/')
.expect({
email: 'Email',
hello: 'Hello fengmk2, how are you today?',
message: 'Hello fengmk2, how are you today? How was your 18.',
empty: '',
notexists_key: 'key not exists',
empty_string: '',
empty_value: 'emptyValue',
novalue: 'key %s ok',
arguments3: '1 2 3',
arguments4: '1 2 3 4',
arguments5: '1 2 3 4 5',
arguments6: '1 2 3 4 5. 6',
values: 'foo bar foo bar {2} {100}',
object: 'foo bar foo bar {z}',
'gender': 'model.user.fields.gender',
'name': 'model.user.fields.name',
})
.expect('Set-Cookie', /^locale=en\-us; path=\/; expires=[^;]+; domain=.foo.com$/)
.expect(200, done);
});
});
describe('custom options', function () {
const app = createApp({
dirs: [__dirname + '/locales', __dirname + '/other-locales'],