2016-02-25 18:24:16 -05:00
|
|
|
CreateAccountModal = require 'views/core/CreateAccountModal'
|
2016-04-26 15:28:48 -04:00
|
|
|
COPPADenyModal = require 'views/core/COPPADenyModal'
|
2016-02-25 18:24:16 -05:00
|
|
|
forms = require 'core/forms'
|
|
|
|
|
|
|
|
describe 'CreateAccountModal', ->
|
|
|
|
|
|
|
|
modal = null
|
|
|
|
|
2016-05-31 15:39:30 -04:00
|
|
|
initModal = (options) -> (done) ->
|
2016-03-15 16:50:33 -04:00
|
|
|
application.facebookHandler.fakeAPI()
|
|
|
|
application.gplusHandler.fakeAPI()
|
2016-03-10 14:37:31 -05:00
|
|
|
modal = new CreateAccountModal(options)
|
2016-02-25 18:24:16 -05:00
|
|
|
modal.render()
|
|
|
|
modal.render = _.noop
|
|
|
|
jasmine.demoModal(modal)
|
2016-05-31 15:39:30 -04:00
|
|
|
_.defer done
|
2016-03-10 14:37:31 -05:00
|
|
|
|
2016-02-25 18:24:16 -05:00
|
|
|
afterEach ->
|
|
|
|
modal.stopListening()
|
2016-03-10 14:37:31 -05:00
|
|
|
|
|
|
|
describe 'constructed with showRequiredError is true', ->
|
2016-05-31 15:39:30 -04:00
|
|
|
beforeEach initModal({showRequiredError: true})
|
2016-03-10 14:37:31 -05:00
|
|
|
it 'shows a modal explaining to login first', ->
|
|
|
|
expect(modal.$('#required-error-alert').length).toBe(1)
|
|
|
|
|
|
|
|
describe 'constructed with showSignupRationale is true', ->
|
2016-05-31 15:39:30 -04:00
|
|
|
beforeEach initModal({showSignupRationale: true})
|
2016-03-10 14:37:31 -05:00
|
|
|
it 'shows a modal explaining signup rationale', ->
|
|
|
|
expect(modal.$('#signup-rationale-alert').length).toBe(1)
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
describe 'clicking the save button', ->
|
2016-03-10 14:37:31 -05:00
|
|
|
|
2016-05-31 15:39:30 -04:00
|
|
|
beforeEach initModal()
|
2016-03-10 14:37:31 -05:00
|
|
|
|
2016-04-26 15:28:48 -04:00
|
|
|
it 'fails if nothing is in the form, showing errors for email, birthday, and password', ->
|
2016-02-25 18:24:16 -05:00
|
|
|
modal.$('form').each (i, el) -> el.reset()
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
expect(jasmine.Ajax.requests.all().length).toBe(0)
|
2016-04-26 15:28:48 -04:00
|
|
|
expect(modal.$('.has-error').length).toBe(3)
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
it 'fails if email is missing', ->
|
|
|
|
modal.$('form').each (i, el) -> el.reset()
|
2016-04-26 15:28:48 -04:00
|
|
|
forms.objectToForm(modal.$el, { name: 'Name', password: 'xyzzy', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
expect(jasmine.Ajax.requests.all().length).toBe(0)
|
|
|
|
expect(modal.$('.has-error').length).toBeTruthy()
|
|
|
|
|
2016-06-02 13:55:48 -04:00
|
|
|
it 'fails if birthday is missing', ->
|
2016-02-25 18:24:16 -05:00
|
|
|
modal.$('form').each (i, el) -> el.reset()
|
|
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', password: 'xyzzy' })
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-04-26 15:28:48 -04:00
|
|
|
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()
|
2016-04-26 17:35:07 -04:00
|
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', password: 'xyzzy', birthdayDay: 24, birthdayMonth: 7, birthdayYear: (new Date().getFullYear() - 10) })
|
2016-04-26 15:28:48 -04:00
|
|
|
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()
|
2016-02-25 18:24:16 -05:00
|
|
|
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' })
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
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', ->
|
2016-03-10 14:23:09 -05:00
|
|
|
expect(modal.$('#close-modal').css('display')).not.toBe('none')
|
2016-02-25 18:24:16 -05:00
|
|
|
|
2016-03-10 14:23:09 -05:00
|
|
|
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')
|
2016-02-25 18:24:16 -05:00
|
|
|
|
2016-03-10 14:23:09 -05:00
|
|
|
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('')
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
describe 'clicking the gplus button', ->
|
|
|
|
|
|
|
|
signupButton = null
|
2016-03-10 14:37:31 -05:00
|
|
|
|
2016-05-31 15:39:30 -04:00
|
|
|
beforeEach initModal()
|
|
|
|
|
2016-02-25 18:24:16 -05:00
|
|
|
beforeEach ->
|
2016-04-26 15:28:48 -04:00
|
|
|
forms.objectToForm(modal.$el, { birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
2016-02-25 18:24:16 -05:00
|
|
|
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 ->
|
2016-04-26 15:28:48 -04:00
|
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
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 ->
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-05-31 15:39:30 -04:00
|
|
|
beforeEach initModal()
|
|
|
|
|
2016-02-25 18:24:16 -05:00
|
|
|
beforeEach ->
|
2016-04-26 15:28:48 -04:00
|
|
|
forms.objectToForm(modal.$el, { birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
2016-02-25 18:24:16 -05:00
|
|
|
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 ->
|
2016-04-26 15:28:48 -04:00
|
|
|
forms.objectToForm(modal.$el, { email: 'some@email.com', birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
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 ->
|
2016-03-15 16:50:33 -04:00
|
|
|
modal.$('form').submit()
|
2016-02-25 18:24:16 -05:00
|
|
|
|
|
|
|
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)
|
2016-05-31 15:39:30 -04:00
|
|
|
expect(request.url).toBe('/db/user?facebookID=abcd&facebookAccessToken=1234')
|