mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
COPPA tests.
This commit is contained in:
parent
4183764b61
commit
5bd8f7a1cb
4 changed files with 40 additions and 16 deletions
|
@ -1821,6 +1821,9 @@
|
|||
oreilly: "ebook of your choice"
|
||||
|
||||
calendar:
|
||||
year: "Year"
|
||||
day: "Day"
|
||||
month: "Month"
|
||||
january: "January"
|
||||
february: "February"
|
||||
march: "March"
|
||||
|
|
|
@ -76,15 +76,15 @@
|
|||
| :
|
||||
.input-border
|
||||
select#birthday-month-input.input-large.form-control(name="birthdayMonth", value=view.previousFormInputs.birthdayMonth || '', tabindex=4, style="width: 120px; float: left")
|
||||
option Month
|
||||
option(value='',data-i18n="calendar.month")
|
||||
for name, val in ['january','february','march','april','may','june','july','august','september','october','november','december']
|
||||
option(data-i18n="calendar.#{name}" value=val+1)
|
||||
select#birthday-day-input.input-large.form-control(name="birthdayDay", value=view.previousFormInputs.birthdayDay || '', tabindex=5, style="width: 55px; float: left")
|
||||
option Day
|
||||
option(value='',data-i18n="calendar.day")
|
||||
for dummy, val in new Array(31)
|
||||
option #{val+1}
|
||||
select#birthday-year-input.input-large.form-control(name="birthdayYear", value=view.previousFormInputs.birthdayMonth || '', tabindex=6, style="width: 100px;")
|
||||
option Year
|
||||
option(value='',data-i18n="calendar.year")
|
||||
for dummy, val in new Array(30)
|
||||
option #{2016-29+val}
|
||||
|
||||
|
|
|
@ -58,15 +58,16 @@ module.exports = class CreateAccountModal extends ModalView
|
|||
@classCode = attrs.classCode
|
||||
delete attrs.classCode
|
||||
|
||||
|
||||
error = false
|
||||
birthday = new Date Date.UTC attrs.birthdayYear, attrs.birthdayMonth - 1, attrs.birthdayDay
|
||||
if isNaN(birthday.getTime())
|
||||
if @classCode
|
||||
#PASS
|
||||
else if isNaN(birthday.getTime())
|
||||
forms.setErrorToProperty @$el, 'birthdayDay', 'Required'
|
||||
error = true
|
||||
else
|
||||
age = (new Date().getTime() - birthday.getTime()) / 365.4 / 24 / 60 / 60 / 1000
|
||||
if age >= 13
|
||||
attrs.birthday = birthday.toISOString()
|
||||
attrs.birthday = birthday.toISOString()
|
||||
|
||||
delete attrs.birthdayYear
|
||||
delete attrs.birthdayMonth
|
||||
|
@ -75,7 +76,7 @@ module.exports = class CreateAccountModal extends ModalView
|
|||
_.assign attrs, @gplusAttrs if @gplusAttrs
|
||||
_.assign attrs, @facebookAttrs if @facebookAttrs
|
||||
res = tv4.validateMultiple attrs, User.schema
|
||||
error = false
|
||||
|
||||
if not res.valid
|
||||
forms.applyErrorsToForm(@$el, res.errors)
|
||||
error = true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
CreateAccountModal = require 'views/core/CreateAccountModal'
|
||||
COPPADenyModal = require 'views/core/COPPADenyModal'
|
||||
forms = require 'core/forms'
|
||||
|
||||
describe 'CreateAccountModal', ->
|
||||
|
@ -31,23 +32,42 @@ describe 'CreateAccountModal', ->
|
|||
beforeEach ->
|
||||
initModal()
|
||||
|
||||
it 'fails if nothing is in the form, showing errors for email and password', ->
|
||||
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(2)
|
||||
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' })
|
||||
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 'signs up if only email and password is provided', ->
|
||||
it 'fails if birthay 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: 2015 })
|
||||
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()
|
||||
|
@ -92,6 +112,7 @@ describe 'CreateAccountModal', ->
|
|||
|
||||
beforeEach ->
|
||||
initModal()
|
||||
forms.objectToForm(modal.$el, { birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
||||
signupButton = modal.$('#gplus-signup-btn')
|
||||
expect(signupButton.attr('disabled')).toBeFalsy()
|
||||
signupButton.click()
|
||||
|
@ -121,14 +142,13 @@ describe 'CreateAccountModal', ->
|
|||
|
||||
describe 'and the user finishes signup anyway with new info', ->
|
||||
beforeEach ->
|
||||
forms.objectToForm(modal.$el, { email: 'some@email.com', schoolName: 'Hogwarts' })
|
||||
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')
|
||||
expect(JSON.parse(request.params).schoolName).toBe('Hogwarts')
|
||||
|
||||
|
||||
describe 'and finding the given person is not yet a user', ->
|
||||
|
@ -158,6 +178,7 @@ describe 'CreateAccountModal', ->
|
|||
|
||||
beforeEach ->
|
||||
initModal()
|
||||
forms.objectToForm(modal.$el, { birthdayDay: 24, birthdayMonth: 7, birthdayYear: 1988 })
|
||||
signupButton = modal.$('#facebook-signup-btn')
|
||||
expect(signupButton.attr('disabled')).toBeFalsy()
|
||||
signupButton.click()
|
||||
|
@ -187,14 +208,13 @@ describe 'CreateAccountModal', ->
|
|||
|
||||
describe 'and the user finishes signup anyway with new info', ->
|
||||
beforeEach ->
|
||||
forms.objectToForm(modal.$el, { email: 'some@email.com', schoolName: 'Hogwarts' })
|
||||
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')
|
||||
expect(JSON.parse(request.params).schoolName).toBe('Hogwarts')
|
||||
|
||||
|
||||
describe 'and finding the given person is not yet a user', ->
|
||||
|
|
Loading…
Reference in a new issue