mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Clean server test logging
This commit is contained in:
parent
ca83ed05e4
commit
0581ffde82
19 changed files with 445 additions and 485 deletions
|
@ -2,6 +2,7 @@ winston = require 'winston'
|
||||||
|
|
||||||
module.exports.setup = ->
|
module.exports.setup = ->
|
||||||
winston.remove(winston.transports.Console)
|
winston.remove(winston.transports.Console)
|
||||||
|
if not global.testing
|
||||||
winston.add(winston.transports.Console,
|
winston.add(winston.transports.Console,
|
||||||
colorize: true,
|
colorize: true,
|
||||||
timestamp: true
|
timestamp: true
|
||||||
|
|
|
@ -158,7 +158,7 @@ class EarnedAchievementHandler extends Handler
|
||||||
onFinished = ->
|
onFinished = ->
|
||||||
t1 = new Date().getTime()
|
t1 = new Date().getTime()
|
||||||
runningTime = ((t1-t0)/1000/60/60).toFixed(2)
|
runningTime = ((t1-t0)/1000/60/60).toFixed(2)
|
||||||
console.log "we finished in #{runningTime} hours"
|
log.info "we finished in #{runningTime} hours"
|
||||||
callback arguments...
|
callback arguments...
|
||||||
|
|
||||||
filter = {}
|
filter = {}
|
||||||
|
@ -278,7 +278,7 @@ class EarnedAchievementHandler extends Handler
|
||||||
#log.debug "Incrementing score for these achievements with #{newTotalPoints - previousPoints}"
|
#log.debug "Incrementing score for these achievements with #{newTotalPoints - previousPoints}"
|
||||||
pointDelta = newTotalPoints - previousPoints
|
pointDelta = newTotalPoints - previousPoints
|
||||||
pctDone = (100 * usersFinished / total).toFixed(2)
|
pctDone = (100 * usersFinished / total).toFixed(2)
|
||||||
console.log "Updated points to #{newTotalPoints} (#{if pointDelta < 0 then '' else '+'}#{pointDelta}) for #{user.get('name') or '???'} (#{user.get('_id')}) (#{pctDone}%)"
|
log.info "Updated points to #{newTotalPoints} (#{if pointDelta < 0 then '' else '+'}#{pointDelta}) for #{user.get('name') or '???'} (#{user.get('_id')}) (#{pctDone}%)"
|
||||||
if recalculatingAll
|
if recalculatingAll
|
||||||
update = {$set: {points: newTotalPoints, 'earned.gems': 0, 'earned.heroes': [], 'earned.items': [], 'earned.levels': []}}
|
update = {$set: {points: newTotalPoints, 'earned.gems': 0, 'earned.heroes': [], 'earned.items': [], 'earned.levels': []}}
|
||||||
else
|
else
|
||||||
|
|
|
@ -34,7 +34,7 @@ PaymentHandler = class PaymentHandler extends Handler
|
||||||
super arguments...
|
super arguments...
|
||||||
|
|
||||||
logPaymentError: (req, msg) ->
|
logPaymentError: (req, msg) ->
|
||||||
console.warn "Payment Error: #{req.user.get('slug')} (#{req.user._id}): '#{msg}'"
|
log.warn "Payment Error: #{req.user.get('slug')} (#{req.user._id}): '#{msg}'"
|
||||||
|
|
||||||
makeNewInstance: (req) ->
|
makeNewInstance: (req) ->
|
||||||
payment = super(req)
|
payment = super(req)
|
||||||
|
|
|
@ -21,7 +21,7 @@ recipientCouponID = 'free'
|
||||||
|
|
||||||
class SubscriptionHandler extends Handler
|
class SubscriptionHandler extends Handler
|
||||||
logSubscriptionError: (user, msg) ->
|
logSubscriptionError: (user, msg) ->
|
||||||
console.warn "Subscription Error: #{user.get('slug')} (#{user._id}): '#{msg}'"
|
log.warn "Subscription Error: #{user.get('slug')} (#{user._id}): '#{msg}'"
|
||||||
|
|
||||||
getByRelationship: (req, res, args...) ->
|
getByRelationship: (req, res, args...) ->
|
||||||
return @getStripeEvents(req, res) if args[1] is 'stripe_events'
|
return @getStripeEvents(req, res) if args[1] is 'stripe_events'
|
||||||
|
|
|
@ -119,7 +119,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
log.error "Database error setting user name: #{err}" if err
|
log.error "Database error setting user name: #{err}" if err
|
||||||
return callback(res: 'Database error.', code: 500) if err
|
return callback(res: 'Database error.', code: 500) if err
|
||||||
r = {message: 'is already used by another account', property: 'name'}
|
r = {message: 'is already used by another account', property: 'name'}
|
||||||
console.log 'Another user exists' if otherUser
|
log.info 'Another user exists' if otherUser
|
||||||
return callback({res: r, code: 409}) if otherUser
|
return callback({res: r, code: 409}) if otherUser
|
||||||
user.set('name', req.body.name)
|
user.set('name', req.body.name)
|
||||||
callback(null, req, user)
|
callback(null, req, user)
|
||||||
|
@ -775,7 +775,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
else
|
else
|
||||||
update = $unset: {}
|
update = $unset: {}
|
||||||
update.$unset[statKey] = ''
|
update.$unset[statKey] = ''
|
||||||
console.log "... updating #{userStringID} patches #{statKey} to #{count}, #{usersTotal} players found so far." if count
|
log.info "... updating #{userStringID} patches #{statKey} to #{count}, #{usersTotal} players found so far." if count
|
||||||
User.findByIdAndUpdate user.get('_id'), update, (err) ->
|
User.findByIdAndUpdate user.get('_id'), update, (err) ->
|
||||||
log.error err if err?
|
log.error err if err?
|
||||||
doneWithUser()
|
doneWithUser()
|
||||||
|
@ -801,7 +801,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
update = {}
|
update = {}
|
||||||
update[method] = {}
|
update[method] = {}
|
||||||
update[method][statName] = count or ''
|
update[method][statName] = count or ''
|
||||||
console.log "... updating #{user.get('_id')} patches #{JSON.stringify(query)} #{statName} to #{count}, #{usersTotal} players found so far." if count
|
log.info "... updating #{user.get('_id')} patches #{JSON.stringify(query)} #{statName} to #{count}, #{usersTotal} players found so far." if count
|
||||||
User.findByIdAndUpdate user.get('_id'), update, doneUpdatingUser
|
User.findByIdAndUpdate user.get('_id'), update, doneUpdatingUser
|
||||||
|
|
||||||
userStream = User.find({anonymous: false}).sort('_id').stream()
|
userStream = User.find({anonymous: false}).sort('_id').stream()
|
||||||
|
@ -865,7 +865,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
update = {}
|
update = {}
|
||||||
update[method] = {}
|
update[method] = {}
|
||||||
update[method][statName] = count or ''
|
update[method][statName] = count or ''
|
||||||
console.log "... updating #{userStringID} patches #{query} to #{count}, #{usersTotal} players found so far." if count
|
log.info "... updating #{userStringID} patches #{query} to #{count}, #{usersTotal} players found so far." if count
|
||||||
User.findByIdAndUpdate user.get('_id'), update, doneWithUser
|
User.findByIdAndUpdate user.get('_id'), update, doneWithUser
|
||||||
|
|
||||||
statRecalculators:
|
statRecalculators:
|
||||||
|
@ -883,7 +883,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
--numberRunning
|
--numberRunning
|
||||||
userStream.resume()
|
userStream.resume()
|
||||||
if streamFinished and usersFinished is usersTotal
|
if streamFinished and usersFinished is usersTotal
|
||||||
console.log "----------- Finished recalculating statistics for gamesCompleted for #{usersFinished} players. -----------"
|
log.info "----------- Finished recalculating statistics for gamesCompleted for #{usersFinished} players. -----------"
|
||||||
done?()
|
done?()
|
||||||
userStream.on 'error', (err) -> log.error err
|
userStream.on 'error', (err) -> log.error err
|
||||||
userStream.on 'close', -> streamFinished = true
|
userStream.on 'close', -> streamFinished = true
|
||||||
|
@ -895,7 +895,7 @@ UserHandler = class UserHandler extends Handler
|
||||||
|
|
||||||
LevelSession.count {creator: userID, 'state.complete': true}, (err, count) ->
|
LevelSession.count {creator: userID, 'state.complete': true}, (err, count) ->
|
||||||
update = if count then {$set: 'stats.gamesCompleted': count} else {$unset: 'stats.gamesCompleted': ''}
|
update = if count then {$set: 'stats.gamesCompleted': count} else {$unset: 'stats.gamesCompleted': ''}
|
||||||
console.log "... updating #{userID} gamesCompleted to #{count}, #{usersTotal} players found so far." if Math.random() < 0.001
|
log.info "... updating #{userID} gamesCompleted to #{count}, #{usersTotal} players found so far." if Math.random() < 0.001
|
||||||
User.findByIdAndUpdate user.get('_id'), update, doneWithUser
|
User.findByIdAndUpdate user.get('_id'), update, doneWithUser
|
||||||
|
|
||||||
articleEdits: (done) ->
|
articleEdits: (done) ->
|
||||||
|
|
|
@ -39,7 +39,7 @@ module.exports =
|
||||||
throw new errors.NotFound('Level original ObjectId not found in that course')
|
throw new errors.NotFound('Level original ObjectId not found in that course')
|
||||||
|
|
||||||
if not nextLevelOriginal
|
if not nextLevelOriginal
|
||||||
res.status(200).send({})
|
return res.status(200).send({})
|
||||||
|
|
||||||
dbq = Level.findOne({original: mongoose.Types.ObjectId(nextLevelOriginal)})
|
dbq = Level.findOne({original: mongoose.Types.ObjectId(nextLevelOriginal)})
|
||||||
|
|
||||||
|
|
|
@ -350,7 +350,6 @@ UserSchema.pre('save', (next) ->
|
||||||
Classroom = require './Classroom'
|
Classroom = require './Classroom'
|
||||||
if @isTeacher() and not @wasTeacher
|
if @isTeacher() and not @wasTeacher
|
||||||
Classroom.update({members: @_id}, {$pull: {members: @_id}}, {multi: true}).exec (err, res) ->
|
Classroom.update({members: @_id}, {$pull: {members: @_id}}, {multi: true}).exec (err, res) ->
|
||||||
console.log 'removed self from all classrooms as a member', err, res
|
|
||||||
if email = @get('email')
|
if email = @get('email')
|
||||||
@set('emailLower', email.toLowerCase())
|
@set('emailLower', email.toLowerCase())
|
||||||
if name = @get('name')
|
if name = @get('name')
|
||||||
|
|
|
@ -84,7 +84,7 @@ setupExpressMiddleware = (app) ->
|
||||||
app.use express.compress filter: (req, res) ->
|
app.use express.compress filter: (req, res) ->
|
||||||
return false if req.headers.host is 'codecombat.com' # CloudFlare will gzip it for us on codecombat.com
|
return false if req.headers.host is 'codecombat.com' # CloudFlare will gzip it for us on codecombat.com
|
||||||
compressible res.getHeader('Content-Type')
|
compressible res.getHeader('Content-Type')
|
||||||
else
|
else if not global.testing
|
||||||
express.logger.format('dev', developmentLogging)
|
express.logger.format('dev', developmentLogging)
|
||||||
app.use(express.logger('dev'))
|
app.use(express.logger('dev'))
|
||||||
app.use(express.static(path.join(__dirname, 'public'), maxAge: 0)) # CloudFlare overrides maxAge, and we don't want local development caching.
|
app.use(express.static(path.join(__dirname, 'public'), maxAge: 0)) # CloudFlare overrides maxAge, and we don't want local development caching.
|
||||||
|
|
|
@ -39,11 +39,22 @@ if (database.generateMongoConnectionString() !== dbString) {
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 10; // for long Stripe tests
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 10; // for long Stripe tests
|
||||||
require('../server/common'); // Make sure global testing functions are set up
|
require('../server/common'); // Make sure global testing functions are set up
|
||||||
|
|
||||||
|
// Ignore Stripe/Nocking erroring
|
||||||
|
console.error = function() {
|
||||||
|
try {
|
||||||
|
if(arguments[1].stack.indexOf('An error occurred with our connection to Stripe') > -1)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (e) { }
|
||||||
|
console.log.apply(console, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
var initialized = false;
|
var initialized = false;
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
|
console.log('/spec/helpers/helper.js - Initializing spec environment...');
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
async.series([
|
async.series([
|
||||||
|
@ -103,6 +114,7 @@ beforeEach(function(done) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
console.log('/spec/helpers/helper.js - Done');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# import this at the top of every file so we're not juggling connections
|
# import this at the top of every file so we're not juggling connections
|
||||||
# and common libraries are available
|
# and common libraries are available
|
||||||
|
|
||||||
console.log 'IT BEGINS'
|
console.log '/spec/server/common.coffee - Setting up spec globals...'
|
||||||
if process.env.COCO_MONGO_HOST
|
if process.env.COCO_MONGO_HOST
|
||||||
throw Error('Tests may not run with production environment')
|
throw Error('Tests may not run with production environment')
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ unittest.getUser = (name, email, password, done, force) ->
|
||||||
return done(unittest.users[email]) if unittest.users[email] and not force
|
return done(unittest.users[email]) if unittest.users[email] and not force
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
request.get getURL('/auth/whoami'), ->
|
request.get getURL('/auth/whoami'), ->
|
||||||
req = request.post(getURL('/db/user'), (err, response, body) ->
|
req = request.post({url: getURL('/db/user'), json: {email, password}}, (err, response, body) ->
|
||||||
throw err if err
|
throw err if err
|
||||||
User.findOne({email: email}).exec((err, user) ->
|
User.findOne({email: email}).exec((err, user) ->
|
||||||
throw err if err
|
throw err if err
|
||||||
|
@ -70,9 +70,6 @@ unittest.getUser = (name, email, password, done, force) ->
|
||||||
wrapUpGetUser(email, user, done)
|
wrapUpGetUser(email, user, done)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('email', email)
|
|
||||||
form.append('password', password)
|
|
||||||
|
|
||||||
wrapUpGetUser = (email, user, done) ->
|
wrapUpGetUser = (email, user, done) ->
|
||||||
unittest.users[email] = user
|
unittest.users[email] = user
|
||||||
|
@ -139,58 +136,48 @@ GLOBAL.loginNewUser = (done) ->
|
||||||
email = "#{name}@me.com"
|
email = "#{name}@me.com"
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
unittest.getUser name, email, password, (user) ->
|
unittest.getUser name, email, password, (user) ->
|
||||||
req = request.post(getURL('/auth/login'), (error, response) ->
|
json = {username: email, password}
|
||||||
|
req = request.post({url: getURL('/auth/login'), json}, (error, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
done(user)
|
done(user)
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('username', email)
|
|
||||||
form.append('password', password)
|
|
||||||
, true
|
, true
|
||||||
|
|
||||||
GLOBAL.loginJoe = (done) ->
|
GLOBAL.loginJoe = (done) ->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
unittest.getNormalJoe (user) ->
|
unittest.getNormalJoe (user) ->
|
||||||
req = request.post(getURL('/auth/login'), (error, response) ->
|
json = {username: 'normal@jo.com', password: 'food'}
|
||||||
|
req = request.post({url: getURL('/auth/login'), json}, (error, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
done(user)
|
done(user)
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('username', 'normal@jo.com')
|
|
||||||
form.append('password', 'food')
|
|
||||||
|
|
||||||
GLOBAL.loginSam = (done) ->
|
GLOBAL.loginSam = (done) ->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
unittest.getOtherSam (user) ->
|
unittest.getOtherSam (user) ->
|
||||||
req = request.post(getURL('/auth/login'), (error, response) ->
|
json = { username: 'other@sam.com', password: 'beer'}
|
||||||
|
req = request.post({url: getURL('/auth/login'), json}, (error, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
done(user)
|
done(user)
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('username', 'other@sam.com')
|
|
||||||
form.append('password', 'beer')
|
|
||||||
|
|
||||||
GLOBAL.loginAdmin = (done) ->
|
GLOBAL.loginAdmin = (done) ->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
unittest.getAdmin (user) ->
|
unittest.getAdmin (user) ->
|
||||||
req = request.post(getURL('/auth/login'), (error, response) ->
|
json = { username: 'admin@afc.com', password: '80yqxpb38j' }
|
||||||
|
req = request.post({url: getURL('/auth/login'), json}, (error, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
done(user)
|
done(user)
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('username', 'admin@afc.com')
|
|
||||||
form.append('password', '80yqxpb38j')
|
|
||||||
# find some other way to make the admin object an admin... maybe directly?
|
# find some other way to make the admin object an admin... maybe directly?
|
||||||
|
|
||||||
GLOBAL.loginUser = (user, done) ->
|
GLOBAL.loginUser = (user, done) ->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
req = request.post(getURL('/auth/login'), (error, response) ->
|
json = { username: user.get('email'), password: user.get('name') }
|
||||||
|
req = request.post({ url: getURL('/auth/login'), json}, (error, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
done(user)
|
done(user)
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('username', user.get('email'))
|
|
||||||
form.append('password', user.get('name'))
|
|
||||||
|
|
||||||
GLOBAL.logoutUser = (done) ->
|
GLOBAL.logoutUser = (done) ->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
|
@ -213,3 +200,4 @@ _drop = (done) ->
|
||||||
GLOBAL.resetUserIDCounter = (number=0) ->
|
GLOBAL.resetUserIDCounter = (number=0) ->
|
||||||
User.idCounter = number
|
User.idCounter = number
|
||||||
|
|
||||||
|
console.log '/spec/server/common.coffee - Done'
|
||||||
|
|
|
@ -4,23 +4,23 @@ request = require '../request'
|
||||||
User = require '../../../server/models/User'
|
User = require '../../../server/models/User'
|
||||||
|
|
||||||
# TODO: need to update this test since /contact calls external Close.io API now
|
# TODO: need to update this test since /contact calls external Close.io API now
|
||||||
xdescribe 'POST /contact', ->
|
#xdescribe 'POST /contact', ->
|
||||||
|
#
|
||||||
beforeEach utils.wrap (done) ->
|
# beforeEach utils.wrap (done) ->
|
||||||
spyOn(sendwithus.api, 'send')
|
# spyOn(sendwithus.api, 'send')
|
||||||
@teacher = yield utils.initUser({role: 'teacher'})
|
# @teacher = yield utils.initUser({role: 'teacher'})
|
||||||
yield utils.loginUser(@teacher)
|
# yield utils.loginUser(@teacher)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
describe 'when recipientID is "schools@codecombat.com"', ->
|
# describe 'when recipientID is "schools@codecombat.com"', ->
|
||||||
it 'sends to that email', utils.wrap (done) ->
|
# it 'sends to that email', utils.wrap (done) ->
|
||||||
[res, body] = yield request.postAsync({url: getURL('/contact'), json: {
|
# [res, body] = yield request.postAsync({url: getURL('/contact'), json: {
|
||||||
sender: 'some@email.com'
|
# sender: 'some@email.com'
|
||||||
message: 'A message'
|
# message: 'A message'
|
||||||
recipientID: 'schools@codecombat.com'
|
# recipientID: 'schools@codecombat.com'
|
||||||
}})
|
# }})
|
||||||
expect(sendwithus.api.send).toHaveBeenCalled()
|
# expect(sendwithus.api.send).toHaveBeenCalled()
|
||||||
user = yield User.findById(@teacher.id)
|
# user = yield User.findById(@teacher.id)
|
||||||
yield new Promise((resolve) -> setTimeout(resolve, 10))
|
# yield new Promise((resolve) -> setTimeout(resolve, 10))
|
||||||
expect(user.get('enrollmentRequestSent')).toBe(true)
|
# expect(user.get('enrollmentRequestSent')).toBe(true)
|
||||||
done()
|
# done()
|
||||||
|
|
|
@ -1,178 +1,178 @@
|
||||||
require '../common'
|
#require '../common'
|
||||||
|
#
|
||||||
# Doesn't work on Travis. Need to figure out why, probably by having the
|
## Doesn't work on Travis. Need to figure out why, probably by having the
|
||||||
# url not depend on some external resource.
|
## url not depend on some external resource.
|
||||||
mongoose = require 'mongoose'
|
#mongoose = require 'mongoose'
|
||||||
request = require '../request'
|
#request = require '../request'
|
||||||
|
#
|
||||||
xdescribe '/file', ->
|
#xdescribe '/file', ->
|
||||||
url = getURL('/file')
|
# url = getURL('/file')
|
||||||
files = []
|
# files = []
|
||||||
options = {
|
# options = {
|
||||||
uri: url
|
# uri: url
|
||||||
json: {
|
# json: {
|
||||||
# url: 'http://scotterickson.info/images/where-are-you.jpg'
|
# # url: 'http://scotterickson.info/images/where-are-you.jpg'
|
||||||
url: 'http://fc07.deviantart.net/fs37/f/2008/283/5/1/Chu_Chu_Pikachu_by_angelishi.gif'
|
# url: 'http://fc07.deviantart.net/fs37/f/2008/283/5/1/Chu_Chu_Pikachu_by_angelishi.gif'
|
||||||
filename: 'where-are-you.jpg'
|
# filename: 'where-are-you.jpg'
|
||||||
mimetype: 'image/jpeg'
|
# mimetype: 'image/jpeg'
|
||||||
description: 'None!'
|
# description: 'None!'
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
filepath = 'tmp/file' # TODO Warning hard coded path !!!
|
# filepath = 'tmp/file' # TODO Warning hard coded path !!!
|
||||||
|
#
|
||||||
jsonOptions= {
|
# jsonOptions= {
|
||||||
path: 'my_path'
|
# path: 'my_path'
|
||||||
postName: 'my_buffer'
|
# postName: 'my_buffer'
|
||||||
filename: 'ittybitty.data'
|
# filename: 'ittybitty.data'
|
||||||
mimetype: 'application/octet-stream'
|
# mimetype: 'application/octet-stream'
|
||||||
description: 'rando-info'
|
# description: 'rando-info'
|
||||||
# my_buffer_url: 'http://scotterickson.info/images/where-are-you.jpg'
|
# # my_buffer_url: 'http://scotterickson.info/images/where-are-you.jpg'
|
||||||
my_buffer_url: 'http://fc07.deviantart.net/fs37/f/2008/283/5/1/Chu_Chu_Pikachu_by_angelishi.gif'
|
# my_buffer_url: 'http://fc07.deviantart.net/fs37/f/2008/283/5/1/Chu_Chu_Pikachu_by_angelishi.gif'
|
||||||
}
|
# }
|
||||||
|
#
|
||||||
allowHeader = 'GET, POST'
|
# allowHeader = 'GET, POST'
|
||||||
|
#
|
||||||
it 'preparing test : deletes all the files first', (done) ->
|
# it 'preparing test : deletes all the files first', (done) ->
|
||||||
dropGridFS ->
|
# dropGridFS ->
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it 'can\'t be created if invalid (property path is required)', (done) ->
|
# it 'can\'t be created if invalid (property path is required)', (done) ->
|
||||||
func = (err, res, body) ->
|
# func = (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(422)
|
# expect(res.statusCode).toBe(422)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
loginAdmin ->
|
# loginAdmin ->
|
||||||
request.post(options, func)
|
# request.post(options, func)
|
||||||
|
#
|
||||||
it 'can be created by an admin', (done) ->
|
# it 'can be created by an admin', (done) ->
|
||||||
func = (err, res, body) ->
|
# func = (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(200)
|
# expect(res.statusCode).toBe(200)
|
||||||
expect(body._id).toBeDefined()
|
# expect(body._id).toBeDefined()
|
||||||
expect(body.filename).toBe(options.json.filename)
|
# expect(body.filename).toBe(options.json.filename)
|
||||||
expect(body.contentType).toBe(options.json.mimetype)
|
# expect(body.contentType).toBe(options.json.mimetype)
|
||||||
expect(body.length).toBeDefined()
|
# expect(body.length).toBeDefined()
|
||||||
expect(body.uploadDate).toBeDefined()
|
# expect(body.uploadDate).toBeDefined()
|
||||||
expect(body.metadata).toBeDefined()
|
# expect(body.metadata).toBeDefined()
|
||||||
expect(body.metadata.name).toBeDefined()
|
# expect(body.metadata.name).toBeDefined()
|
||||||
expect(body.metadata.path).toBe(options.json.path)
|
# expect(body.metadata.path).toBe(options.json.path)
|
||||||
expect(body.metadata.creator).toBeDefined()
|
# expect(body.metadata.creator).toBeDefined()
|
||||||
expect(body.metadata.description).toBe(options.json.description)
|
# expect(body.metadata.description).toBe(options.json.description)
|
||||||
expect(body.md5).toBeDefined()
|
# expect(body.md5).toBeDefined()
|
||||||
files.push(body)
|
# files.push(body)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
options.json.path = filepath
|
# options.json.path = filepath
|
||||||
request.post(options, func)
|
# request.post(options, func)
|
||||||
|
#
|
||||||
it 'can be read by an admin.', (done) ->
|
# it 'can be read by an admin.', (done) ->
|
||||||
request.get {uri: url+'/'+files[0]._id}, (err, res) ->
|
# request.get {uri: url+'/'+files[0]._id}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(200)
|
# expect(res.statusCode).toBe(200)
|
||||||
expect(res.headers['content-type']).toBe(files[0].contentType)
|
# expect(res.headers['content-type']).toBe(files[0].contentType)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it 'returns 404 for missing files', (done) ->
|
# it 'returns 404 for missing files', (done) ->
|
||||||
id = '000000000000000000000000'
|
# id = '000000000000000000000000'
|
||||||
request.get {uri: url+'/'+id}, (err, res) ->
|
# request.get {uri: url+'/'+id}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(404)
|
# expect(res.statusCode).toBe(404)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it 'returns 404 for invalid ids', (done) ->
|
# it 'returns 404 for invalid ids', (done) ->
|
||||||
request.get {uri: url+'/thiswillnotwork'}, (err, res) ->
|
# request.get {uri: url+'/thiswillnotwork'}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(404)
|
# expect(res.statusCode).toBe(404)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it 'can be created directly with form parameters', (done) ->
|
# it 'can be created directly with form parameters', (done) ->
|
||||||
options2 = {
|
# options2 = {
|
||||||
uri: url
|
# uri: url
|
||||||
}
|
# }
|
||||||
|
#
|
||||||
func = (err, res, body) ->
|
# func = (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(200)
|
# expect(res.statusCode).toBe(200)
|
||||||
body = JSON.parse(body)
|
# body = JSON.parse(body)
|
||||||
expect(body._id).toBeDefined()
|
# expect(body._id).toBeDefined()
|
||||||
expect(body.filename).toBe(jsonOptions.filename)
|
# expect(body.filename).toBe(jsonOptions.filename)
|
||||||
expect(body.contentType).toBe(jsonOptions.mimetype)
|
# expect(body.contentType).toBe(jsonOptions.mimetype)
|
||||||
expect(body.length).toBeDefined()
|
# expect(body.length).toBeDefined()
|
||||||
expect(body.uploadDate).toBeDefined()
|
# expect(body.uploadDate).toBeDefined()
|
||||||
expect(body.metadata).toBeDefined()
|
# expect(body.metadata).toBeDefined()
|
||||||
expect(body.metadata.name).toBeDefined()
|
# expect(body.metadata.name).toBeDefined()
|
||||||
expect(body.metadata.path).toBe(jsonOptions.path)
|
# expect(body.metadata.path).toBe(jsonOptions.path)
|
||||||
expect(body.metadata.creator).toBeDefined()
|
# expect(body.metadata.creator).toBeDefined()
|
||||||
expect(body.metadata.description).toBe(jsonOptions.description)
|
# expect(body.metadata.description).toBe(jsonOptions.description)
|
||||||
expect(body.md5).toBeDefined()
|
# expect(body.md5).toBeDefined()
|
||||||
files.push(body)
|
# files.push(body)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
# the only way I could figure out how to get request to do what I wanted...
|
# # the only way I could figure out how to get request to do what I wanted...
|
||||||
r = request.post(options2, func)
|
# r = request.post(options2, func)
|
||||||
form = r.form()
|
# form = r.form()
|
||||||
form.append('path', jsonOptions.path)
|
# form.append('path', jsonOptions.path)
|
||||||
form.append('postName', jsonOptions.postName)
|
# form.append('postName', jsonOptions.postName)
|
||||||
form.append('filename', jsonOptions.filename)
|
# form.append('filename', jsonOptions.filename)
|
||||||
form.append('mimetype', jsonOptions.mimetype)
|
# form.append('mimetype', jsonOptions.mimetype)
|
||||||
form.append('description', jsonOptions.description)
|
# form.append('description', jsonOptions.description)
|
||||||
form.append('my_buffer', request(jsonOptions.my_buffer_url))
|
# form.append('my_buffer', request(jsonOptions.my_buffer_url))
|
||||||
|
#
|
||||||
it 'created directly, can be read', (done) ->
|
# it 'created directly, can be read', (done) ->
|
||||||
request.get {uri: url+'/'+files[1]._id}, (err, res) ->
|
# request.get {uri: url+'/'+files[1]._id}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(200)
|
# expect(res.statusCode).toBe(200)
|
||||||
expect(res.headers['content-type']).toBe(files[1].contentType)
|
# expect(res.headers['content-type']).toBe(files[1].contentType)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it 'does not overwrite existing files', (done) ->
|
# it 'does not overwrite existing files', (done) ->
|
||||||
options.json.description = 'Face'
|
# options.json.description = 'Face'
|
||||||
|
#
|
||||||
func = (err, res, body) ->
|
# func = (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(409)
|
# expect(res.statusCode).toBe(409)
|
||||||
collection = mongoose.connection.db.collection('media.files')
|
# collection = mongoose.connection.db.collection('media.files')
|
||||||
collection.find({}).toArray (err, results) ->
|
# collection.find({}).toArray (err, results) ->
|
||||||
# ittybitty.data, and just one Where are you.jpg
|
# # ittybitty.data, and just one Where are you.jpg
|
||||||
expect(results.length).toBe(2)
|
# expect(results.length).toBe(2)
|
||||||
for f in results
|
# for f in results
|
||||||
expect(f.metadata.description).not.toBe('Face')
|
# expect(f.metadata.description).not.toBe('Face')
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
request.post(options, func)
|
# request.post(options, func)
|
||||||
|
#
|
||||||
it 'does overwrite existing files if force is true', (done) ->
|
# it 'does overwrite existing files if force is true', (done) ->
|
||||||
options.json.force = 'true' # TODO ask why it's a string and not a boolean ?
|
# options.json.force = 'true' # TODO ask why it's a string and not a boolean ?
|
||||||
|
#
|
||||||
func = (err, res, body) ->
|
# func = (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(200)
|
# expect(res.statusCode).toBe(200)
|
||||||
collection = mongoose.connection.db.collection('media.files')
|
# collection = mongoose.connection.db.collection('media.files')
|
||||||
collection.find({}).toArray (err, results) ->
|
# collection.find({}).toArray (err, results) ->
|
||||||
# ittybitty.data, and just one Where are you.jpg
|
# # ittybitty.data, and just one Where are you.jpg
|
||||||
expect(results.length).toBe(2)
|
# expect(results.length).toBe(2)
|
||||||
hit = false
|
# hit = false
|
||||||
for f in results
|
# for f in results
|
||||||
hit = true if f.metadata.description is 'Face'
|
# hit = true if f.metadata.description is 'Face'
|
||||||
expect(hit).toBe(true)
|
# expect(hit).toBe(true)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
request.post(options, func)
|
# request.post(options, func)
|
||||||
|
#
|
||||||
it ' can\'t be requested with HTTP PATCH method', (done) ->
|
# it ' can\'t be requested with HTTP PATCH method', (done) ->
|
||||||
request {method: 'patch', uri: url}, (err, res) ->
|
# request {method: 'patch', uri: url}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it ' can\'t be requested with HTTP PUT method', (done) ->
|
# it ' can\'t be requested with HTTP PUT method', (done) ->
|
||||||
request.put {uri: url}, (err, res) ->
|
# request.put {uri: url}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it ' can\'t be requested with HTTP HEAD method', (done) ->
|
# it ' can\'t be requested with HTTP HEAD method', (done) ->
|
||||||
request.head {uri: url}, (err, res) ->
|
# request.head {uri: url}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
it ' can\'t be requested with HTTP DEL method', (done) ->
|
# it ' can\'t be requested with HTTP DEL method', (done) ->
|
||||||
request.del {uri: url}, (err, res) ->
|
# request.del {uri: url}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
# TODO: test server errors, see what they do
|
## TODO: test server errors, see what they do
|
||||||
|
|
|
@ -23,14 +23,14 @@ describe '/db/level.session', ->
|
||||||
|
|
||||||
# TODO Tried to mimic what happens on the site. Why is this even so hard to do.
|
# TODO Tried to mimic what happens on the site. Why is this even so hard to do.
|
||||||
# Right now it's even possible to create ownerless sessions through POST
|
# Right now it's even possible to create ownerless sessions through POST
|
||||||
xit 'allows users to create level sessions through PATCH', (done) ->
|
# xit 'allows users to create level sessions through PATCH', (done) ->
|
||||||
loginJoe (joe) ->
|
# loginJoe (joe) ->
|
||||||
request {method: 'patch', uri: url + mongoose.Types.ObjectId(), json: session}, (err, res, body) ->
|
# request {method: 'patch', uri: url + mongoose.Types.ObjectId(), json: session}, (err, res, body) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
expect(res.statusCode).toBe 200
|
# expect(res.statusCode).toBe 200
|
||||||
console.log body
|
# console.log body
|
||||||
expect(body.creator).toEqual joe.get('_id').toHexString()
|
# expect(body.creator).toEqual joe.get('_id').toHexString()
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
# Should remove this as soon as the PATCH test case above works
|
# Should remove this as soon as the PATCH test case above works
|
||||||
it 'create a level session', (done) ->
|
it 'create a level session', (done) ->
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
require '../common'
|
|
||||||
config = require '../../../server_config'
|
|
||||||
nockUtils = require('../nock-utils')
|
|
||||||
request = require '../request'
|
|
||||||
|
|
||||||
xdescribe 'nock-utils', ->
|
|
||||||
afterEach nockUtils.teardownNock
|
|
||||||
|
|
||||||
describe 'a test using setupNock', ->
|
|
||||||
it 'records and plays back third-party requests, but not localhost requests', (done) ->
|
|
||||||
nockUtils.setupNock 'nock-test.json', (err, nockDone) ->
|
|
||||||
request.get { uri: getURL('/db/level') }, (err) ->
|
|
||||||
expect(err).toBeNull()
|
|
||||||
t0 = new Date().getTime()
|
|
||||||
request.get { uri: 'http://zombo.com/' }, (err) ->
|
|
||||||
console.log 'cached speed', new Date().getTime() - t0
|
|
||||||
expect(err).toBeNull()
|
|
||||||
nockDone()
|
|
||||||
done()
|
|
||||||
|
|
||||||
describe 'another, sibling test that does not use setupNock', ->
|
|
||||||
it 'is proceeds normally', (done) ->
|
|
||||||
request.get { uri: getURL('/db/level') }, (err) ->
|
|
||||||
expect(err).toBeNull()
|
|
||||||
t0 = new Date().getTime()
|
|
||||||
request.get { uri: 'http://zombo.com/' }, (err) ->
|
|
||||||
console.log 'uncached speed', new Date().getTime() - t0
|
|
||||||
expect(err).toBeNull()
|
|
||||||
done()
|
|
|
@ -1,24 +1,24 @@
|
||||||
require '../common'
|
#require '../common'
|
||||||
request = require '../request'
|
#request = require '../request'
|
||||||
|
#
|
||||||
describe 'queue', ->
|
#describe 'queue', ->
|
||||||
someURL = getURL('/queue/')
|
# someURL = getURL('/queue/')
|
||||||
allowHeader = 'GET, POST, PUT'
|
# allowHeader = 'GET, POST, PUT'
|
||||||
|
#
|
||||||
xit 'can\'t be requested with HTTP PATCH method', (done) ->
|
# xit 'can\'t be requested with HTTP PATCH method', (done) ->
|
||||||
request {method: 'patch', uri: someURL}, (err, res, body) ->
|
# request {method: 'patch', uri: someURL}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
xit 'can\'t be requested with HTTP HEAD method', (done) ->
|
# xit 'can\'t be requested with HTTP HEAD method', (done) ->
|
||||||
request.head {uri: someURL}, (err, res, body) ->
|
# request.head {uri: someURL}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
xit 'can\'t be requested with HTTP DELETE method', (done) ->
|
# xit 'can\'t be requested with HTTP DELETE method', (done) ->
|
||||||
request.del {uri: someURL}, (err, res, body) ->
|
# request.del {uri: someURL}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(405)
|
# expect(res.statusCode).toBe(405)
|
||||||
expect(res.headers.allow).toBe(allowHeader)
|
# expect(res.headers.allow).toBe(allowHeader)
|
||||||
done()
|
# done()
|
||||||
|
|
|
@ -1441,62 +1441,62 @@ describe 'Subscriptions', ->
|
||||||
nockDone()
|
nockDone()
|
||||||
done()
|
done()
|
||||||
|
|
||||||
xit 'Unsubscribed user1 subscribes 13 users, unsubcribes 2', (done) ->
|
# xit 'Unsubscribed user1 subscribes 13 users, unsubcribes 2', (done) ->
|
||||||
nockUtils.setupNock 'sub-test-34.json', (err, nockDone) ->
|
# nockUtils.setupNock 'sub-test-34.json', (err, nockDone) ->
|
||||||
# TODO: Hits the Stripe error 'Request rate limit exceeded'.
|
# # TODO: Hits the Stripe error 'Request rate limit exceeded'.
|
||||||
# TODO: Need a better test for 12+ bulk discounts. Or, we could update the bulk disount logic.
|
# # TODO: Need a better test for 12+ bulk discounts. Or, we could update the bulk disount logic.
|
||||||
# TODO: verify interim invoices?
|
# # TODO: verify interim invoices?
|
||||||
recipientCount = 13
|
# recipientCount = 13
|
||||||
recipientsToVerify = [0, 1, 10, 11, 12]
|
# recipientsToVerify = [0, 1, 10, 11, 12]
|
||||||
recipients = new SubbedRecipients recipientCount, recipientsToVerify
|
# recipients = new SubbedRecipients recipientCount, recipientsToVerify
|
||||||
|
#
|
||||||
# Create recipients
|
# # Create recipients
|
||||||
recipients.createRecipients ->
|
# recipients.createRecipients ->
|
||||||
expect(recipients.length()).toEqual(recipientCount)
|
# expect(recipients.length()).toEqual(recipientCount)
|
||||||
|
#
|
||||||
stripe.tokens.create {
|
# stripe.tokens.create {
|
||||||
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
# card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
||||||
}, (err, token) ->
|
# }, (err, token) ->
|
||||||
|
#
|
||||||
# Create sponsor user
|
# # Create sponsor user
|
||||||
loginNewUser (user1) ->
|
# loginNewUser (user1) ->
|
||||||
|
#
|
||||||
# Subscribe recipients
|
# # Subscribe recipients
|
||||||
recipients.subRecipients user1, token, ->
|
# recipients.subRecipients user1, token, ->
|
||||||
User.findById user1.id, (err, user1) ->
|
# User.findById user1.id, (err, user1) ->
|
||||||
|
#
|
||||||
# Unsubscribe first recipient
|
# # Unsubscribe first recipient
|
||||||
unsubscribeRecipient user1, recipients.get(0), ->
|
# unsubscribeRecipient user1, recipients.get(0), ->
|
||||||
User.findById user1.id, (err, user1) ->
|
# User.findById user1.id, (err, user1) ->
|
||||||
|
#
|
||||||
stripeInfo = user1.get('stripe')
|
# stripeInfo = user1.get('stripe')
|
||||||
expect(stripeInfo.recipients.length).toEqual(recipientCount - 1)
|
# expect(stripeInfo.recipients.length).toEqual(recipientCount - 1)
|
||||||
verifyNotSponsoring user1.id, recipients.get(0).id, ->
|
# verifyNotSponsoring user1.id, recipients.get(0).id, ->
|
||||||
verifyNotRecipient recipients.get(0).id, ->
|
# verifyNotRecipient recipients.get(0).id, ->
|
||||||
stripe.customers.retrieveSubscription stripeInfo.customerID, stripeInfo.sponsorSubscriptionID, (err, subscription) ->
|
# stripe.customers.retrieveSubscription stripeInfo.customerID, stripeInfo.sponsorSubscriptionID, (err, subscription) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
expect(subscription).not.toBeNull()
|
# expect(subscription).not.toBeNull()
|
||||||
expect(subscription.quantity).toEqual(getUnsubscribedQuantity(recipientCount - 1))
|
# expect(subscription.quantity).toEqual(getUnsubscribedQuantity(recipientCount - 1))
|
||||||
|
#
|
||||||
# Unsubscribe last recipient
|
# # Unsubscribe last recipient
|
||||||
unsubscribeRecipient user1, recipients.get(recipientCount - 1), ->
|
# unsubscribeRecipient user1, recipients.get(recipientCount - 1), ->
|
||||||
User.findById user1.id, (err, user1) ->
|
# User.findById user1.id, (err, user1) ->
|
||||||
stripeInfo = user1.get('stripe')
|
# stripeInfo = user1.get('stripe')
|
||||||
expect(stripeInfo.recipients.length).toEqual(recipientCount - 2)
|
# expect(stripeInfo.recipients.length).toEqual(recipientCount - 2)
|
||||||
verifyNotSponsoring user1.id, recipients.get(recipientCount - 1).id, ->
|
# verifyNotSponsoring user1.id, recipients.get(recipientCount - 1).id, ->
|
||||||
verifyNotRecipient recipients.get(recipientCount - 1).id, ->
|
# verifyNotRecipient recipients.get(recipientCount - 1).id, ->
|
||||||
stripe.customers.retrieveSubscription stripeInfo.customerID, stripeInfo.sponsorSubscriptionID, (err, subscription) ->
|
# stripe.customers.retrieveSubscription stripeInfo.customerID, stripeInfo.sponsorSubscriptionID, (err, subscription) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
expect(subscription).not.toBeNull()
|
# expect(subscription).not.toBeNull()
|
||||||
numSponsored = recipientCount - 2
|
# numSponsored = recipientCount - 2
|
||||||
if numSponsored <= 1
|
# if numSponsored <= 1
|
||||||
expect(subscription.quantity).toEqual(subPrice)
|
# expect(subscription.quantity).toEqual(subPrice)
|
||||||
else if numSponsored <= 11
|
# else if numSponsored <= 11
|
||||||
expect(subscription.quantity).toEqual(subPrice + (numSponsored - 1) * subPrice * 0.8)
|
# expect(subscription.quantity).toEqual(subPrice + (numSponsored - 1) * subPrice * 0.8)
|
||||||
else
|
# else
|
||||||
expect(subscription.quantity).toEqual(subPrice + 10 * subPrice * 0.8 + (numSponsored - 11) * subPrice * 0.6)
|
# expect(subscription.quantity).toEqual(subPrice + 10 * subPrice * 0.8 + (numSponsored - 11) * subPrice * 0.6)
|
||||||
nockDone()
|
# nockDone()
|
||||||
done()
|
# done()
|
||||||
|
|
||||||
describe 'APIs', ->
|
describe 'APIs', ->
|
||||||
subscriptionURL = getURL('/db/subscription')
|
subscriptionURL = getURL('/db/subscription')
|
||||||
|
@ -1694,7 +1694,6 @@ describe 'Subscriptions', ->
|
||||||
token: token.id
|
token: token.id
|
||||||
timestamp: new Date()
|
timestamp: new Date()
|
||||||
request.put {uri: "#{subscriptionURL}/-/year_sale", json: requestBody, headers: headers }, (err, res) ->
|
request.put {uri: "#{subscriptionURL}/-/year_sale", json: requestBody, headers: headers }, (err, res) ->
|
||||||
console.log err
|
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
nockDone()
|
nockDone()
|
||||||
done()
|
done()
|
||||||
|
|
|
@ -11,16 +11,13 @@ describe 'POST /db/user', ->
|
||||||
createAnonNameUser = (name, done)->
|
createAnonNameUser = (name, done)->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
request.get getURL('/auth/whoami'), ->
|
request.get getURL('/auth/whoami'), ->
|
||||||
req = request.post(getURL('/db/user'), (err, response) ->
|
req = request.post({ url: getURL('/db/user'), json: {name}}, (err, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
request.get getURL('/auth/whoami'), (request, response, body) ->
|
request.get { url: getURL('/auth/whoami'), json: true }, (request, response, body) ->
|
||||||
res = JSON.parse(response.body)
|
expect(body.anonymous).toBeTruthy()
|
||||||
expect(res.anonymous).toBeTruthy()
|
expect(body.name).toEqual(name)
|
||||||
expect(res.name).toEqual(name)
|
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('name', name)
|
|
||||||
|
|
||||||
it 'preparing test : clears the db first', (done) ->
|
it 'preparing test : clears the db first', (done) ->
|
||||||
clearModels [User], (err) ->
|
clearModels [User], (err) ->
|
||||||
|
@ -77,16 +74,13 @@ describe 'POST /db/user', ->
|
||||||
createAnonNameUser('Jim', done)
|
createAnonNameUser('Jim', done)
|
||||||
|
|
||||||
it 'should allow setting existing user name to anonymous user', (done) ->
|
it 'should allow setting existing user name to anonymous user', (done) ->
|
||||||
req = request.post(getURL('/db/user'), (err, response, body) ->
|
req = request.post({url: getURL('/db/user'), json: {email: 'new@user.com', password: 'new'}}, (err, response, body) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
request.get getURL('/auth/whoami'), (request, response, body) ->
|
request.get getURL('/auth/whoami'), (request, response, body) ->
|
||||||
res = JSON.parse(response.body)
|
res = JSON.parse(response.body)
|
||||||
expect(res.anonymous).toBeFalsy()
|
expect(res.anonymous).toBeFalsy()
|
||||||
createAnonNameUser 'Jim', done
|
createAnonNameUser 'Jim', done
|
||||||
)
|
)
|
||||||
form = req.form()
|
|
||||||
form.append('email', 'new@user.com')
|
|
||||||
form.append('password', 'new')
|
|
||||||
|
|
||||||
describe 'PUT /db/user', ->
|
describe 'PUT /db/user', ->
|
||||||
|
|
||||||
|
@ -103,23 +97,22 @@ describe 'PUT /db/user', ->
|
||||||
|
|
||||||
it 'denies requests to edit someone who is not joe', (done) ->
|
it 'denies requests to edit someone who is not joe', (done) ->
|
||||||
unittest.getAdmin (admin) ->
|
unittest.getAdmin (admin) ->
|
||||||
req = request.put getURL(urlUser),
|
request.put {url: getURL(urlUser), json: {_id: admin.id}}, (err, res) ->
|
||||||
(err, res) ->
|
|
||||||
expect(res.statusCode).toBe(403)
|
expect(res.statusCode).toBe(403)
|
||||||
done()
|
done()
|
||||||
req.form().append('_id', admin.id)
|
|
||||||
|
|
||||||
it 'denies invalid data', (done) ->
|
it 'denies invalid data', (done) ->
|
||||||
unittest.getNormalJoe (joe) ->
|
unittest.getNormalJoe (joe) ->
|
||||||
req = request.put getURL(urlUser),
|
json = {
|
||||||
(err, res) ->
|
_id: joe.id
|
||||||
|
email: 'farghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlar
|
||||||
|
ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl'
|
||||||
|
}
|
||||||
|
request.put { url: getURL(urlUser), json }, (err, res) ->
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
expect(res.body.indexOf('too long')).toBeGreaterThan(-1)
|
expect(res.body[0].message.indexOf('too long')).toBeGreaterThan(-1)
|
||||||
done()
|
done()
|
||||||
form = req.form()
|
|
||||||
form.append('_id', joe.id)
|
|
||||||
form.append('email', 'farghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlar
|
|
||||||
ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl')
|
|
||||||
|
|
||||||
it 'does not allow normals to edit their permissions', utils.wrap (done) ->
|
it 'does not allow normals to edit their permissions', utils.wrap (done) ->
|
||||||
user = yield utils.initUser()
|
user = yield utils.initUser()
|
||||||
|
@ -132,47 +125,45 @@ ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl
|
||||||
loginAdmin -> done()
|
loginAdmin -> done()
|
||||||
|
|
||||||
it 'denies non-existent ids', (done) ->
|
it 'denies non-existent ids', (done) ->
|
||||||
req = request.put getURL(urlUser),
|
json = {
|
||||||
(err, res) ->
|
_id: '513108d4cb8b610000000004',
|
||||||
|
email: 'perfectly@good.com'
|
||||||
|
}
|
||||||
|
request.put {url: getURL(urlUser), json}, (err, res) ->
|
||||||
expect(res.statusCode).toBe(404)
|
expect(res.statusCode).toBe(404)
|
||||||
done()
|
done()
|
||||||
form = req.form()
|
|
||||||
form.append('_id', '513108d4cb8b610000000004')
|
|
||||||
form.append('email', 'perfectly@good.com')
|
|
||||||
|
|
||||||
it 'denies if the email being changed is already taken', (done) ->
|
it 'denies if the email being changed is already taken', (done) ->
|
||||||
unittest.getNormalJoe (joe) ->
|
unittest.getNormalJoe (joe) ->
|
||||||
unittest.getAdmin (admin) ->
|
unittest.getAdmin (admin) ->
|
||||||
req = request.put getURL(urlUser), (err, res) ->
|
json = { _id: admin.id, email: joe.get('email').toUpperCase() }
|
||||||
|
request.put { url: getURL(urlUser), json }, (err, res) ->
|
||||||
expect(res.statusCode).toBe(409)
|
expect(res.statusCode).toBe(409)
|
||||||
expect(res.body.indexOf('already used')).toBeGreaterThan(-1)
|
expect(res.body.message.indexOf('already used')).toBeGreaterThan(-1)
|
||||||
done()
|
done()
|
||||||
form = req.form()
|
|
||||||
form.append('_id', String(admin._id))
|
|
||||||
form.append('email', joe.get('email').toUpperCase())
|
|
||||||
|
|
||||||
it 'does not care if you include your existing name', (done) ->
|
it 'does not care if you include your existing name', (done) ->
|
||||||
unittest.getNormalJoe (joe) ->
|
unittest.getNormalJoe (joe) ->
|
||||||
req = request.put getURL(urlUser+'/'+joe._id), (err, res) ->
|
json = { _id: joe._id, name: 'Joe' }
|
||||||
|
request.put { url: getURL(urlUser+'/'+joe._id), json }, (err, res) ->
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
done()
|
done()
|
||||||
form = req.form()
|
|
||||||
form.append('_id', String(joe._id))
|
|
||||||
form.append('name', 'Joe')
|
|
||||||
|
|
||||||
it 'accepts name and email changes', (done) ->
|
it 'accepts name and email changes', (done) ->
|
||||||
unittest.getNormalJoe (joe) ->
|
unittest.getNormalJoe (joe) ->
|
||||||
req = request.put getURL(urlUser), (err, res) ->
|
json = {
|
||||||
|
_id: joe.id
|
||||||
|
email: 'New@email.com'
|
||||||
|
name: 'Wilhelm'
|
||||||
|
}
|
||||||
|
request.put { url: getURL(urlUser), json }, (err, res) ->
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
unittest.getUser('Wilhelm', 'New@email.com', 'null', (joe) ->
|
unittest.getUser('Wilhelm', 'New@email.com', 'null', (joe) ->
|
||||||
expect(joe.get('name')).toBe('Wilhelm')
|
expect(joe.get('name')).toBe('Wilhelm')
|
||||||
expect(joe.get('emailLower')).toBe('new@email.com')
|
expect(joe.get('emailLower')).toBe('new@email.com')
|
||||||
expect(joe.get('email')).toBe('New@email.com')
|
expect(joe.get('email')).toBe('New@email.com')
|
||||||
done())
|
done())
|
||||||
form = req.form()
|
|
||||||
form.append('_id', String(joe._id))
|
|
||||||
form.append('email', 'New@email.com')
|
|
||||||
form.append('name', 'Wilhelm')
|
|
||||||
|
|
||||||
it 'should not allow two users with the same name slug', (done) ->
|
it 'should not allow two users with the same name slug', (done) ->
|
||||||
loginSam (sam) ->
|
loginSam (sam) ->
|
||||||
|
@ -189,7 +180,8 @@ ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl
|
||||||
it 'should silently rename an anonymous user if their name conflicts upon signup', (done) ->
|
it 'should silently rename an anonymous user if their name conflicts upon signup', (done) ->
|
||||||
request.post getURL('/auth/logout'), ->
|
request.post getURL('/auth/logout'), ->
|
||||||
request.get getURL('/auth/whoami'), ->
|
request.get getURL('/auth/whoami'), ->
|
||||||
req = request.post getURL('/db/user'), (err, response) ->
|
json = { name: 'admin' }
|
||||||
|
request.post { url: getURL('/db/user'), json }, (err, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
request.get getURL('/auth/whoami'), (err, response) ->
|
request.get getURL('/auth/whoami'), (err, response) ->
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
|
@ -205,8 +197,6 @@ ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl
|
||||||
expect(finalGuy.name).not.toEqual guy.name
|
expect(finalGuy.name).not.toEqual guy.name
|
||||||
expect(finalGuy.name.length).toBe guy.name.length + 1
|
expect(finalGuy.name.length).toBe guy.name.length + 1
|
||||||
done()
|
done()
|
||||||
form = req.form()
|
|
||||||
form.append('name', 'admin')
|
|
||||||
|
|
||||||
it 'should be able to unset a slug by setting an empty name', (done) ->
|
it 'should be able to unset a slug by setting an empty name', (done) ->
|
||||||
loginSam (sam) ->
|
loginSam (sam) ->
|
||||||
|
@ -467,13 +457,13 @@ describe 'PUT /db/user/-/remain-teacher', ->
|
||||||
describe 'GET /db/user', ->
|
describe 'GET /db/user', ->
|
||||||
|
|
||||||
it 'logs in as admin', (done) ->
|
it 'logs in as admin', (done) ->
|
||||||
req = request.post(getURL('/auth/login'), (error, response) ->
|
json = {
|
||||||
|
username: 'admin@afc.com'
|
||||||
|
password: '80yqxpb38j'
|
||||||
|
}
|
||||||
|
request.post { url: getURL('/auth/login'), json }, (error, response) ->
|
||||||
expect(response.statusCode).toBe(200)
|
expect(response.statusCode).toBe(200)
|
||||||
done()
|
done()
|
||||||
)
|
|
||||||
form = req.form()
|
|
||||||
form.append('username', 'admin@afc.com')
|
|
||||||
form.append('password', '80yqxpb38j')
|
|
||||||
|
|
||||||
it 'get schema', (done) ->
|
it 'get schema', (done) ->
|
||||||
request.get {uri: getURL(urlUser+'/schema')}, (err, res, body) ->
|
request.get {uri: getURL(urlUser+'/schema')}, (err, res, body) ->
|
||||||
|
@ -523,7 +513,7 @@ describe 'GET /db/user', ->
|
||||||
# TODO Ruben should be able to fetch other users but probably with restricted data access
|
# TODO Ruben should be able to fetch other users but probably with restricted data access
|
||||||
# Add to the test case above an extra data check
|
# Add to the test case above an extra data check
|
||||||
|
|
||||||
xit 'can fetch another user with restricted fields'
|
# xit 'can fetch another user with restricted fields'
|
||||||
|
|
||||||
|
|
||||||
describe 'GET /db/user/:handle', ->
|
describe 'GET /db/user/:handle', ->
|
||||||
|
|
|
@ -1,77 +1,77 @@
|
||||||
GLOBAL._ = require 'lodash'
|
#GLOBAL._ = require 'lodash'
|
||||||
|
#
|
||||||
require '../common'
|
#require '../common'
|
||||||
AnalyticsUsersActive = require '../../../server/models/AnalyticsUsersActive'
|
#AnalyticsUsersActive = require '../../../server/models/AnalyticsUsersActive'
|
||||||
LevelSession = require '../../../server/models/LevelSession'
|
#LevelSession = require '../../../server/models/LevelSession'
|
||||||
User = require '../../../server/models/User'
|
#User = require '../../../server/models/User'
|
||||||
mongoose = require 'mongoose'
|
#mongoose = require 'mongoose'
|
||||||
|
#
|
||||||
# TODO: these tests have some rerun/cleanup issues
|
## TODO: these tests have some rerun/cleanup issues
|
||||||
# TODO: add tests for purchase, payment, subscribe, unsubscribe, and earned achievements
|
## TODO: add tests for purchase, payment, subscribe, unsubscribe, and earned achievements
|
||||||
|
#
|
||||||
# TODO: AnalyticsUsersActive collection isn't currently used.
|
## TODO: AnalyticsUsersActive collection isn't currently used.
|
||||||
# TODO: Will remove these tests if we end up ripping out the disabled saveActiveUser calls.
|
## TODO: Will remove these tests if we end up ripping out the disabled saveActiveUser calls.
|
||||||
|
#
|
||||||
describe 'Analytics', ->
|
#describe 'Analytics', ->
|
||||||
|
#
|
||||||
xit 'registered user', (done) ->
|
# xit 'registered user', (done) ->
|
||||||
clearModels [AnalyticsUsersActive], (err) ->
|
# clearModels [AnalyticsUsersActive], (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
user = new User
|
# user = new User
|
||||||
permissions: []
|
# permissions: []
|
||||||
name: "Fred" + Math.floor(Math.random() * 10000)
|
# name: "Fred" + Math.floor(Math.random() * 10000)
|
||||||
user.save (err) ->
|
# user.save (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
userID = mongoose.Types.ObjectId(user.get('_id'))
|
# userID = mongoose.Types.ObjectId(user.get('_id'))
|
||||||
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
# AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
||||||
expect(activeUsers.length).toEqual(0)
|
# expect(activeUsers.length).toEqual(0)
|
||||||
user.register ->
|
# user.register ->
|
||||||
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
# AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
expect(activeUsers.length).toEqual(1)
|
# expect(activeUsers.length).toEqual(1)
|
||||||
expect(activeUsers[0]?.get('event')).toEqual('register')
|
# expect(activeUsers[0]?.get('event')).toEqual('register')
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
xit 'level completed', (done) ->
|
# xit 'level completed', (done) ->
|
||||||
clearModels [AnalyticsUsersActive], (err) ->
|
# clearModels [AnalyticsUsersActive], (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
unittest.getNormalJoe (joe) ->
|
# unittest.getNormalJoe (joe) ->
|
||||||
userID = mongoose.Types.ObjectId(joe.get('_id'))
|
# userID = mongoose.Types.ObjectId(joe.get('_id'))
|
||||||
session = new LevelSession
|
# session = new LevelSession
|
||||||
name: 'Beat Gandalf'
|
# name: 'Beat Gandalf'
|
||||||
levelID: 'lotr'
|
# levelID: 'lotr'
|
||||||
permissions: simplePermissions
|
# permissions: simplePermissions
|
||||||
state: complete: false
|
# state: complete: false
|
||||||
creator: userID
|
# creator: userID
|
||||||
session.save (err) ->
|
# session.save (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
# AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
||||||
expect(activeUsers.length).toEqual(0)
|
# expect(activeUsers.length).toEqual(0)
|
||||||
session.set 'state', complete: true
|
# session.set 'state', complete: true
|
||||||
session.save (err) ->
|
# session.save (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
# AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
expect(activeUsers.length).toEqual(1)
|
# expect(activeUsers.length).toEqual(1)
|
||||||
expect(activeUsers[0]?.get('event')).toEqual('level-completed/lotr')
|
# expect(activeUsers[0]?.get('event')).toEqual('level-completed/lotr')
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
xit 'level playtime', (done) ->
|
# xit 'level playtime', (done) ->
|
||||||
clearModels [AnalyticsUsersActive], (err) ->
|
# clearModels [AnalyticsUsersActive], (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
unittest.getNormalJoe (joe) ->
|
# unittest.getNormalJoe (joe) ->
|
||||||
userID = mongoose.Types.ObjectId(joe.get('_id'))
|
# userID = mongoose.Types.ObjectId(joe.get('_id'))
|
||||||
session = new LevelSession
|
# session = new LevelSession
|
||||||
name: 'Beat Gandalf'
|
# name: 'Beat Gandalf'
|
||||||
levelID: 'lotr'
|
# levelID: 'lotr'
|
||||||
permissions: simplePermissions
|
# permissions: simplePermissions
|
||||||
playtime: 60
|
# playtime: 60
|
||||||
creator: userID
|
# creator: userID
|
||||||
session.save (err) ->
|
# session.save (err) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
# AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
||||||
expect(err).toBeNull()
|
# expect(err).toBeNull()
|
||||||
expect(activeUsers.length).toEqual(1)
|
# expect(activeUsers.length).toEqual(1)
|
||||||
expect(activeUsers[0]?.get('event')).toEqual('level-playtime/lotr')
|
# expect(activeUsers[0]?.get('event')).toEqual('level-playtime/lotr')
|
||||||
done()
|
# done()
|
||||||
|
#
|
||||||
|
|
Loading…
Reference in a new issue