mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Make delighted profiles for teachers only, instead of all users
This commit is contained in:
parent
0e96b4b250
commit
0ed99565d3
4 changed files with 30 additions and 16 deletions
|
@ -4,23 +4,23 @@ log = require 'winston'
|
|||
|
||||
DELIGHTED_EMAIL_DELAY = 1 * 86400 # in seconds
|
||||
|
||||
module.exports.addDelightedUser = addDelightedUser = (user) ->
|
||||
return unless key = config.mail.delightedAPIKey
|
||||
#return unless user.isEmailSubscriptionEnabled 'generalNews' # Doesn't work? Just returns undefined...
|
||||
return if user.get('emails')?.generalNews?.enabled is false # Workaround.
|
||||
name = user.get('name')
|
||||
if first = user.get('firstName') and last = user.get('lastName')
|
||||
name = first + ' ' + last
|
||||
module.exports.addDelightedUser = addDelightedUser = (user, trialRequest) ->
|
||||
props = trialRequest.get('properties')
|
||||
name = props.firstName + ' ' + props.lastName
|
||||
form =
|
||||
email: user.get('email')
|
||||
email: props.email
|
||||
name: name
|
||||
delay: DELIGHTED_EMAIL_DELAY
|
||||
properties:
|
||||
id: user.id
|
||||
id: trialRequest.get('applicant')
|
||||
locale: user.get('preferredLanguage')
|
||||
testGroupNumber: user.get('testGroupNumber')
|
||||
gender: user.get('gender')
|
||||
lastLevel: user.get('lastLevel')
|
||||
@postPeople(form)
|
||||
|
||||
module.exports.postPeople = (form) ->
|
||||
return unless key = config.mail.delightedAPIKey
|
||||
request.post {uri: "https://#{key}:@api.delightedapp.com/v1/people.json", form: form}, (err, res, body) ->
|
||||
return log.error 'Error sending Delighted request:', err or body if err or /error/i.test body
|
||||
#log.info "Got DelightedApp response: #{body}"
|
||||
|
|
|
@ -6,6 +6,7 @@ database = require '../commons/database'
|
|||
mongoose = require 'mongoose'
|
||||
TrialRequest = require '../models/TrialRequest'
|
||||
User = require '../models/User'
|
||||
delighted = require '../delighted'
|
||||
|
||||
module.exports =
|
||||
post: wrap (req, res) ->
|
||||
|
@ -27,6 +28,7 @@ module.exports =
|
|||
trialRequest.set 'type', attrs.type
|
||||
database.validateDoc(trialRequest)
|
||||
trialRequest = yield trialRequest.save()
|
||||
delighted.addDelightedUser req.user, trialRequest
|
||||
res.status(201).send(trialRequest.toObject({req: req}))
|
||||
|
||||
put: wrap (req, res) ->
|
||||
|
|
|
@ -12,7 +12,6 @@ config = require '../../server_config'
|
|||
stripe = require('stripe')(config.stripe.secretKey)
|
||||
|
||||
sendwithus = require '../sendwithus'
|
||||
delighted = require '../delighted'
|
||||
|
||||
UserSchema = new mongoose.Schema({
|
||||
dateCreated:
|
||||
|
@ -238,7 +237,6 @@ UserSchema.methods.register = (done) ->
|
|||
address: @get 'email'
|
||||
sendwithus.api.send data, (err, result) ->
|
||||
log.error "sendwithus post-save error: #{err}, result: #{result}" if err
|
||||
delighted.addDelightedUser @
|
||||
@saveActiveUser 'register'
|
||||
|
||||
UserSchema.methods.hasSubscription = ->
|
||||
|
|
|
@ -6,6 +6,7 @@ User = require '../../../server/models/User'
|
|||
TrialRequest = require '../../../server/models/TrialRequest'
|
||||
Prepaid = require '../../../server/models/Prepaid'
|
||||
request = require '../request'
|
||||
delighted = require '../../../server/delighted'
|
||||
|
||||
fixture = {
|
||||
type: 'subscription'
|
||||
|
@ -14,12 +15,18 @@ fixture = {
|
|||
age: '14-17'
|
||||
numStudents: 14
|
||||
heardAbout: 'magical interwebs'
|
||||
firstName: 'First'
|
||||
lastName: 'Last'
|
||||
}
|
||||
|
||||
describe 'POST /db/trial.request', ->
|
||||
|
||||
beforeEach utils.wrap (done) ->
|
||||
yield utils.clearModels([User, TrialRequest])
|
||||
spyOn(delighted, 'postPeople')
|
||||
done()
|
||||
|
||||
it 'sets type and properties given', utils.wrap (done) ->
|
||||
yield utils.clearModels([User, TrialRequest])
|
||||
@user = yield utils.initUser()
|
||||
yield utils.loginUser(@user)
|
||||
fixture.properties.email = @user.get('email')
|
||||
|
@ -32,7 +39,6 @@ describe 'POST /db/trial.request', ->
|
|||
done()
|
||||
|
||||
it 'sets applicant to the user\'s id', utils.wrap (done) ->
|
||||
yield utils.clearModels([User, TrialRequest])
|
||||
@user = yield utils.initUser()
|
||||
yield utils.loginUser(@user)
|
||||
fixture.properties.email = @user.get('email')
|
||||
|
@ -44,7 +50,6 @@ describe 'POST /db/trial.request', ->
|
|||
done()
|
||||
|
||||
it 'creates trial request for anonymous user', utils.wrap (done) ->
|
||||
yield utils.clearModels([User, TrialRequest])
|
||||
@user = yield utils.initUser({anonymous: true})
|
||||
yield utils.loginUser(@user)
|
||||
email = 'someone@test.com'
|
||||
|
@ -57,7 +62,6 @@ describe 'POST /db/trial.request', ->
|
|||
done()
|
||||
|
||||
it 'prevents trial request for anonymous user with conflicting email', utils.wrap (done) ->
|
||||
yield utils.clearModels([User, TrialRequest])
|
||||
@otherUser = yield utils.initUser()
|
||||
@user = yield utils.initUser({anonymous: true})
|
||||
yield utils.loginUser(@user)
|
||||
|
@ -66,7 +70,6 @@ describe 'POST /db/trial.request', ->
|
|||
done()
|
||||
|
||||
it 'updates an existing TrialRequest if there is one', utils.wrap (done) ->
|
||||
yield utils.clearModels([User, TrialRequest])
|
||||
@user = yield utils.initUser()
|
||||
yield utils.loginUser(@user)
|
||||
fixture.properties.email = @user.get('email')
|
||||
|
@ -87,6 +90,17 @@ describe 'POST /db/trial.request', ->
|
|||
count = yield TrialRequest.count()
|
||||
expect(count).toBe(1)
|
||||
done()
|
||||
|
||||
it 'creates a delighted profile', utils.wrap (done) ->
|
||||
@user = yield utils.initUser({gender: 'male', lastLevel: 'abcd', preferredLanguage: 'de', testGroupNumber: 1})
|
||||
yield utils.loginUser(@user)
|
||||
fixture.properties.email = @user.get('email')
|
||||
[res, body] = yield request.postAsync(getURL('/db/trial.request'), { json: fixture })
|
||||
expect(delighted.postPeople).toHaveBeenCalled()
|
||||
args = delighted.postPeople.calls.argsFor(0)
|
||||
expect(args[0].email).toBe(@user.get('email'))
|
||||
expect(args[0].name).toBe('First Last')
|
||||
done()
|
||||
|
||||
describe 'GET /db/trial.request', ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue