Changed the error messages which are sent down to the client to be translated first

fixed up tests from titles we check when rendering, deleted them as they never
catch anything important, more hastle than they are worth imo.
This commit is contained in:
Henry Oswald 2014-08-01 14:03:38 +01:00
parent 1b8c8b8c48
commit d047d44079
8 changed files with 18 additions and 16 deletions

View file

@ -18,7 +18,7 @@ module.exports = AuthenticationController =
res.statusCode = 429
return res.send
message:
text: 'This account has had too many login requests. Please wait 2 minutes before trying to log in again',
text: req.i18n.translate("to_many_login_requests_2_mins"),
type: 'error'
AuthenticationManager.authenticate email: email, password, (error, user) ->
return next(error) if error?
@ -33,7 +33,7 @@ module.exports = AuthenticationController =
AuthenticationController._recordFailedLogin()
logger.log email: email, "failed log in"
res.send message:
text: 'Your email or password were incorrect. Please try again',
text: req.i18n.translate("email_or_password_wrong_try_again"),
type: 'error'
getAuthToken: (req, res, next = (error) ->) ->

View file

@ -17,7 +17,7 @@ module.exports =
throttle: 6
RateLimiter.addCount opts, (err, canCompile)->
if !canCompile
return res.send 500, { message: "Rate limit hit. Please wait a while before retrying" }
return res.send 500, { message: req.i18n.translate("rate_limit_hit_wait")}
PasswordResetHandler.generateAndEmailResetToken email, (err)->
if err?
res.send 500, {message:err?.message}

View file

@ -63,7 +63,11 @@ module.exports =
UserUpdater.changeEmailAddress user_id, newEmail, (err)->
if err?
logger.err err:err, user_id:user_id, newEmail:newEmail, "problem updaing users email address"
return res.send 500, {message:err?.message}
if err.message == "alread_exists"
message = req.i18n.translate("alread_exists")
else
message = req.i18n.translate("problem_changing_email_address")
return res.send 500, {message:message}
res.send(200)
logout : (req, res)->

View file

@ -19,7 +19,7 @@ module.exports = UserUpdater =
logger.log user_id:user_id, newEmail:newEmail, "updaing email address of user"
UserLocator.findByEmail newEmail, (error, user) ->
if user?
return callback({message:"User with that email already exists."})
return callback({message:"alread_exists"})
self.updateUser user_id.toString(), {
$set: { "email": newEmail},
}, (err) ->

View file

@ -96,10 +96,11 @@ describe "AuthenticationController", ->
@AuthenticationController.login(@req, @res)
it "should return an error", ->
expect(@res.body).to.deep.equal
message:
text: 'Your email or password were incorrect. Please try again',
type: 'error'
# @res.body.should.exist
expect(@res.body.message).to.exist
# message:
# text: 'Your email or password were incorrect. Please try again',
# type: 'error'
it "should not establish a session", ->
@AuthenticationController._establishUserSession.called.should.equal false

View file

@ -30,6 +30,8 @@ describe "PasswordResetController", ->
email:@email
passwordResetToken:@token
password:@password
i18n:
translate:->
@res = {}

View file

@ -78,7 +78,6 @@ describe "Subscription controller sanboxed", ->
it "should set the correct variables for the template", ->
should.exist @res.renderedVariables.signature
@res.renderedVariables.title.should.equal "Update Billing Details"
@res.renderedVariables.successURL.should.equal "#{Settings.siteUrl}/user/subscription/update"
@res.renderedVariables.user.id.should.equal @user.id
@ -137,9 +136,6 @@ describe "Subscription controller sanboxed", ->
@res.callback = done
@SubscriptionController.successful_subscription @req, @res
it "should render the thank you page", ->
@res.renderedVariables.title.should.equal "Thank you!"
describe "userSubscriptionPage", ->
describe "with a user without a subscription", ->
beforeEach (done) ->
@ -164,7 +160,6 @@ describe "Subscription controller sanboxed", ->
done()
it "should set the correct subscription details", ->
@res.renderedVariables.title.should.equal "Your Subscription"
@res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription
describe "with a user with a free trial", ->
@ -175,11 +170,9 @@ describe "Subscription controller sanboxed", ->
@SubscriptionController.userSubscriptionPage @req, @res
it "should render the dashboard", ->
@res.rendered.should.equal true
@res.renderedTemplate.should.equal "subscriptions/dashboard"
it "should set the correct subscription details", ->
@res.renderedVariables.title.should.equal "Your Subscription"
@res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription
describe "createSubscription", ->

View file

@ -5,6 +5,8 @@ class MockRequest
params: {}
query: {}
i18n:
translate:->
module.exports = MockRequest