mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 00:40:56 -05:00
Fix StudentLoginModal crash on invalid login
Add test for student bad login
This commit is contained in:
parent
2f63c11024
commit
c666a39d3b
2 changed files with 25 additions and 4 deletions
|
@ -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)
|
||||
|
|
22
test/app/views/courses/StudentLogInModal.spec.coffee
Normal file
22
test/app/views/courses/StudentLogInModal.spec.coffee
Normal 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)
|
Loading…
Reference in a new issue