Fix StudentLoginModal crash on invalid login

Add test for student bad login
This commit is contained in:
phoenixeliot 2016-04-22 16:14:20 -07:00
parent 2f63c11024
commit c666a39d3b
2 changed files with 25 additions and 4 deletions

View file

@ -26,10 +26,9 @@ module.exports = class StudentLogInModal extends ModalView
data = forms.formToObject @$el
@enableModalInProgress(@$el)
auth.loginUser data, (jqxhr) =>
error = jqxhr.responseJSON[0]
message = _.filter([error.property, error.message]).join(' ')
if message is 'Missing credentials'
message = 'Enter both username and password'
message = jqxhr.responseText
if jqxhr.status is 401
message = 'Wrong username or password. Try again!'
# TODO: Make the server return better error message
message = _.string.capitalize(message)
@disableModalInProgress(@$el)

View file

@ -0,0 +1,22 @@
StudentLoginModal = require 'views/courses/StudentLogInModal'
RecoverModal = require 'views/core/RecoverModal'
auth = require 'core/auth'
describe 'StudentLoginModal', ->
modal = null
beforeEach ->
modal = new StudentLoginModal()
modal.render()
afterEach ->
modal.stopListening()
it 'displays an error when you submit an empty login form', ->
spyOn(auth, 'loginUser').and.callFake (data, callback) ->
callback { status: 401, responseText: "Unauthorized" }
modal.$el.find('#log-in-btn').click()
expect(modal.$el.html()).toContain('Wrong username or password. Try again!')
jasmine.demoModal(modal)