-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
167 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"error.required": "is required", | ||
"error.minlength": "needs a minimum length of %s", | ||
"error.maxlength": "has a length greater than %s", | ||
"error.model.value.regexp": "must consist of only letters", | ||
"error.model.value.enum": "must be either \"true\" or \"false\"", | ||
"error.min": "needs a minimum value of %s", | ||
"error.max": "has a value greater than %s", | ||
"error.model.value.custom": "must consist of only letters", | ||
"error.unique": "already exists", | ||
"err.required": "is not allowed to left blank", | ||
"error.cast": "is not valid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
/* jshint node: true, mocha: true */ | ||
'use strict'; | ||
|
||
var express = require('express'); | ||
var mongoose = require('mongoose'); | ||
|
||
var app = express(); | ||
var server = app.listen(3000); | ||
var express = require('express'); | ||
var i18n = require('i18n'); | ||
|
||
mongoose.connect('mongodb://localhost/mongoose-i18n-error'); | ||
mongoose.connection.on('error', function() { | ||
throw new Error('Unable to connect to database.'); | ||
}); | ||
|
||
var app = express(); | ||
var server = app.listen(3000); | ||
|
||
i18n.configure({ | ||
locales: ['en'], | ||
directory: './locales' | ||
}); | ||
|
||
app.use(i18n.init); | ||
|
||
describe('Mongoose I18n Error', function() { | ||
require('./tests/message')(); | ||
require('./tests/i18n')(app); | ||
//require('./tests/i18n-2')(app); | ||
require('./tests/message')(i18n); | ||
require('./tests/express')(app); | ||
}); | ||
|
||
server.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* jshint node: true, mocha: true */ | ||
'use strict'; | ||
|
||
var mongoose = require('mongoose'); | ||
var request = require('supertest'); | ||
var should = require('should'); | ||
|
||
var helper = require('../helper'); | ||
var i18nMongooseError = new(require('../../index'))(); | ||
|
||
module.exports = function(app) { | ||
|
||
describe('Express', function() { | ||
afterEach(helper.afterEach); | ||
|
||
it('should print a localized validation error message', function(done) { | ||
var Model = mongoose.model('Model', helper.createStringSchema()); | ||
app.post('/1', function(req, res, next) { | ||
new Model().save(function(err) { | ||
if (err) return next(err); | ||
res.sendStatus(200); | ||
}); | ||
}); | ||
|
||
app.use(i18nMongooseError.handler(function(err, req, res) { | ||
res.status(422).json(err); | ||
})); | ||
|
||
request(app).post('/1').expect(422).end(function(err, res) { | ||
res.body.value.message.should.equal('is required'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should print a localized unique error message', function(done) { | ||
var Model = mongoose.model('Model', helper.createUniqueSchema()); | ||
|
||
app.post('/2', function(req, res, next) { | ||
new Model({ | ||
value: 'ab' | ||
}).save(function(err) { | ||
if (err) return next(err); | ||
res.sendStatus(200); | ||
}); | ||
}); | ||
|
||
app.use(i18nMongooseError.handler(function(err, req, res) { | ||
res.status(422).json(err); | ||
})); | ||
|
||
new Model({ | ||
value: 'ab' | ||
}).save(function(err) { | ||
should.not.exist(err); | ||
|
||
request(app).post('/2').expect(422).end(function(err, res) { | ||
res.body.value.message.should.equal('already exists'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.