mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
240 lines
10 KiB
CoffeeScript
240 lines
10 KiB
CoffeeScript
CreateAccountModal = require 'views/core/CreateAccountModal'
|
|
COPPADenyModal = require 'views/core/COPPADenyModal'
|
|
forms = require 'core/forms'
|
|
|
|
describe 'CreateAccountModal', ->
|
|
|
|
modal = null
|
|
|
|
initModal = (options) -> (done) ->
|
|
application.facebookHandler.fakeAPI()
|
|
application.gplusHandler.fakeAPI()
|
|
modal = new CreateAccountModal(options)
|
|
modal.render()
|
|
modal.render = _.noop
|
|
jasmine.demoModal(modal)
|
|
_.defer done
|
|
|
|
afterEach ->
|
|
modal.stopListening()
|
|
|
|
describe 'constructed with showRequiredError is true', ->
|
|
beforeEach initModal({showRequiredError: true})
|
|
it 'shows a modal explaining to login first', ->
|
|
expect(modal.$('#required-error-alert').length).toBe(1)
|
|
|
|
describe 'constructed with showSignupRationale is true', ->
|
|
beforeEach initModal({showSignupRationale: true})
|
|
it 'shows a modal explaining signup rationale', ->
|
|
expect(modal.$('#signup-rationale-alert').length).toBe(1)
|
|
|
|
describe 'clicking the save button', ->
|
|
|
|
beforeEach initModal()
|
|
|
|
it 'fails if nothing is in the form, showing errors for email, birthday, and password', ->
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
modal.$('form').submit()
|
|
expect(jasmine.Ajax.requests.all().length).toBe(0)
|
|
expect(modal.$('.has-error').length).toBe(3)
|
|
|
|
it 'fails if email is missing', ->
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
forms.objectToForm(modal.$el, { name: 'Name', password: 'xyzzy', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
|
modal.$('form').submit()
|
|
expect(jasmine.Ajax.requests.all().length).toBe(0)
|
|
expect(modal.$('.has-error').length).toBeTruthy()
|
|
|
|
it 'fails if birthday is missing', ->
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', password: 'xyzzy' })
|
|
modal.$('form').submit()
|
|
expect(jasmine.Ajax.requests.all().length).toBe(0)
|
|
expect(modal.$('.has-error').length).toBe(1)
|
|
|
|
it 'fails if user is too young', ->
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', password: 'xyzzy', birthdayDay: 24, birthdayMonth: 7, birthdayYear: (new Date().getFullYear() - 10) })
|
|
modalOpened = false
|
|
spyOn(modal, 'openModalView').and.callFake (modal) ->
|
|
modalOpened = true
|
|
expect(modal instanceof COPPADenyModal).toBe(true)
|
|
|
|
modal.$('form').submit()
|
|
expect(jasmine.Ajax.requests.all().length).toBe(0)
|
|
expect(modalOpened).toBeTruthy()
|
|
|
|
it 'signs up if only email, birthday, and password is provided', ->
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', password: 'xyzzy', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
|
modal.$('form').submit()
|
|
requests = jasmine.Ajax.requests.all()
|
|
expect(requests.length).toBe(1)
|
|
expect(modal.$el.has('.has-warning').length).toBeFalsy()
|
|
expect(modal.$('#signup-button').is(':disabled')).toBe(true)
|
|
|
|
describe 'and a class code is entered', ->
|
|
|
|
beforeEach ->
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', password: 'xyzzy', classCode: 'qwerty' })
|
|
modal.$('form').submit()
|
|
expect(jasmine.Ajax.requests.all().length).toBe(1)
|
|
|
|
it 'checks for Classroom existence if a class code was entered', ->
|
|
jasmine.demoModal(modal)
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.url).toBe('/db/classroom?code=qwerty')
|
|
|
|
it 'has not hidden the close-modal button', ->
|
|
expect(modal.$('#close-modal').css('display')).not.toBe('none')
|
|
|
|
describe 'the Classroom exists', ->
|
|
it 'continues with signup', ->
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
request.respondWith({status: 200, responseText: JSON.stringify({})})
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.url).toBe('/db/user')
|
|
expect(request.method).toBe('POST')
|
|
|
|
describe 'the Classroom does not exist', ->
|
|
it 'shows an error and clears the field', ->
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
request.respondWith({status: 404, responseText: JSON.stringify({})})
|
|
expect(jasmine.Ajax.requests.all().length).toBe(1)
|
|
expect(modal.$el.has('.has-error').length).toBeTruthy()
|
|
expect(modal.$('#class-code-input').val()).toBe('')
|
|
|
|
|
|
describe 'clicking the gplus button', ->
|
|
|
|
signupButton = null
|
|
|
|
beforeEach initModal()
|
|
|
|
beforeEach ->
|
|
forms.objectToForm(modal.$el, { birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
|
signupButton = modal.$('#gplus-signup-btn')
|
|
expect(signupButton.attr('disabled')).toBeFalsy()
|
|
signupButton.click()
|
|
|
|
it 'checks to see if the user already exists in our system', ->
|
|
requests = jasmine.Ajax.requests.all()
|
|
expect(requests.length).toBe(1)
|
|
expect(signupButton.attr('disabled')).toBeTruthy()
|
|
|
|
|
|
describe 'and finding the given person is already a user', ->
|
|
beforeEach ->
|
|
expect(modal.$('#gplus-account-exists-row').hasClass('hide')).toBe(true)
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
request.respondWith({status: 200, responseText: JSON.stringify({_id: 'existinguser'})})
|
|
|
|
it 'shows a message saying you are connected with Google+, with a button for logging in', ->
|
|
expect(modal.$('#gplus-account-exists-row').hasClass('hide')).toBe(false)
|
|
loginBtn = modal.$('#gplus-login-btn')
|
|
expect(loginBtn.attr('disabled')).toBeFalsy()
|
|
loginBtn.click()
|
|
expect(loginBtn.attr('disabled')).toBeTruthy()
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.method).toBe('POST')
|
|
expect(request.params).toBe('gplusID=abcd&gplusAccessToken=1234')
|
|
expect(request.url).toBe('/auth/login-gplus')
|
|
|
|
describe 'and the user finishes signup anyway with new info', ->
|
|
beforeEach ->
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
|
modal.$('form').submit()
|
|
|
|
it 'upserts the values to the new user', ->
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.method).toBe('PUT')
|
|
expect(request.url).toBe('/db/user?gplusID=abcd&gplusAccessToken=1234')
|
|
|
|
|
|
describe 'and finding the given person is not yet a user', ->
|
|
beforeEach ->
|
|
expect(modal.$('#gplus-logged-in-row').hasClass('hide')).toBe(true)
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
request.respondWith({status: 404})
|
|
|
|
it 'shows a message saying you are connected with Google+', ->
|
|
expect(modal.$('#gplus-logged-in-row').hasClass('hide')).toBe(false)
|
|
|
|
describe 'and the user finishes signup', ->
|
|
beforeEach ->
|
|
modal.$('form').submit()
|
|
|
|
it 'creates the user with the gplus attributes', ->
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.method).toBe('PUT')
|
|
expect(request.url).toBe('/db/user?gplusID=abcd&gplusAccessToken=1234')
|
|
expect(_.string.startsWith(request.url, '/db/user')).toBe(true)
|
|
expect(modal.$('#signup-button').is(':disabled')).toBe(true)
|
|
|
|
|
|
describe 'clicking the facebook button', ->
|
|
|
|
signupButton = null
|
|
|
|
beforeEach initModal()
|
|
|
|
beforeEach ->
|
|
forms.objectToForm(modal.$el, { birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
|
signupButton = modal.$('#facebook-signup-btn')
|
|
expect(signupButton.attr('disabled')).toBeFalsy()
|
|
signupButton.click()
|
|
|
|
it 'checks to see if the user already exists in our system', ->
|
|
requests = jasmine.Ajax.requests.all()
|
|
expect(requests.length).toBe(1)
|
|
expect(signupButton.attr('disabled')).toBeTruthy()
|
|
|
|
|
|
describe 'and finding the given person is already a user', ->
|
|
beforeEach ->
|
|
expect(modal.$('#facebook-account-exists-row').hasClass('hide')).toBe(true)
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
request.respondWith({status: 200, responseText: JSON.stringify({_id: 'existinguser'})})
|
|
|
|
it 'shows a message saying you are connected with Facebook, with a button for logging in', ->
|
|
expect(modal.$('#facebook-account-exists-row').hasClass('hide')).toBe(false)
|
|
loginBtn = modal.$('#facebook-login-btn')
|
|
expect(loginBtn.attr('disabled')).toBeFalsy()
|
|
loginBtn.click()
|
|
expect(loginBtn.attr('disabled')).toBeTruthy()
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.method).toBe('POST')
|
|
expect(request.params).toBe('facebookID=abcd&facebookAccessToken=1234')
|
|
expect(request.url).toBe('/auth/login-facebook')
|
|
|
|
describe 'and the user finishes signup anyway with new info', ->
|
|
beforeEach ->
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
|
modal.$('form').submit()
|
|
|
|
it 'upserts the values to the new user', ->
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.method).toBe('PUT')
|
|
expect(request.url).toBe('/db/user?facebookID=abcd&facebookAccessToken=1234')
|
|
|
|
|
|
describe 'and finding the given person is not yet a user', ->
|
|
beforeEach ->
|
|
expect(modal.$('#facebook-logged-in-row').hasClass('hide')).toBe(true)
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
request.respondWith({status: 404})
|
|
|
|
it 'shows a message saying you are connected with Facebook', ->
|
|
expect(modal.$('#facebook-logged-in-row').hasClass('hide')).toBe(false)
|
|
|
|
describe 'and the user finishes signup', ->
|
|
beforeEach ->
|
|
modal.$('form').submit()
|
|
|
|
it 'creates the user with the facebook attributes', ->
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
expect(request.method).toBe('PUT')
|
|
expect(_.string.startsWith(request.url, '/db/user')).toBe(true)
|
|
expect(modal.$('#signup-button').is(':disabled')).toBe(true)
|
|
expect(request.url).toBe('/db/user?facebookID=abcd&facebookAccessToken=1234')
|