Merge branch 'master' into production

This commit is contained in:
Matt Lott 2016-04-07 12:53:08 -07:00
commit 0e9f319315
2 changed files with 19 additions and 74 deletions

View file

@ -10,54 +10,12 @@ User = require './User'
TrialRequestSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
TrialRequestSchema.pre 'save', (next) ->
return next() unless @get('status') is 'approved'
# Add 2 course headcount
prepaid = new Prepaid
creator: @get('applicant')
type: 'course'
maxRedeemers: 2
properties:
trialRequestID: @get('_id')
prepaid.save (err) =>
if err
log.error "Trial request prepaid creation error: #{err}"
next()
TrialRequestSchema.post 'save', (doc) ->
if doc.get('status') is 'approved'
unless trialProperties = doc.get('properties')
log.error "Saving approved trial request #{doc.id} with no properties!"
return
# Subscribe to teacher news group
User.findById doc.get('applicant'), (err, user) =>
if err
log.error "Trial request user find error: #{err}"
return
# Send trial approved email
email = trialProperties.email ? user.get('emailLower')
emailParams =
recipient:
address: email
email_id: sendwithus.templates.teacher_request_demo
email_data:
account_exists: user?.get('anonymous') is false
classes_exist: false
if user?.get('anonymous') is false
Classroom.findOne {ownerID: user.get('_id')}, (err, classroom) =>
if err
log.error "Trial request classroom find error: #{err}"
return
emailParams.email_data.classes_exist = classroom?
sendwithus.api.send emailParams, (err, result) =>
log.error "sendwithus trial request approved error: #{err}, result: #{result}" if err
else
sendwithus.api.send emailParams, (err, result) =>
log.error "sendwithus trial request approved error: #{err}, result: #{result}" if err
# Subscribe to teacher news group
emails = _.cloneDeep(user.get('emails') ? {})
emails.teacherNews ?= {}
emails.teacherNews.enabled = true

View file

@ -172,15 +172,6 @@ describe 'PUT /db/trial.request/:handle', ->
expect(new Date(trialRequest.get('reviewDate'))).toBeLessThan(new Date())
done()
it 'gives the user two enrollments', utils.wrap (done) ->
prepaids = yield Prepaid.find({'properties.trialRequestID': @trialRequest._id})
expect(prepaids.length).toEqual(1)
prepaid = prepaids[0]
expect(prepaid.get('type')).toEqual('course')
expect(prepaid.get('creator')).toEqual(@user.get('_id'))
expect(prepaid.get('maxRedeemers')).toEqual(2)
done()
it 'enables teacherNews for the user', utils.wrap (done) ->
user = yield User.findById(@user._id)
expect(user.get('emails')?.teacherNews?.enabled).toEqual(true)
@ -203,7 +194,3 @@ describe 'PUT /db/trial.request/:handle', ->
expect(new Date(trialRequest.get('reviewDate'))).toBeLessThan(new Date())
done()
it 'does not give the user two enrollments', utils.wrap (done) ->
prepaids = yield Prepaid.find({'properties.trialRequestID': @trialRequest._id})
expect(prepaids.length).toEqual(0)
done()