2014-12-04 15:57:57 -05:00
|
|
|
GLOBAL._ = require 'lodash'
|
|
|
|
|
|
|
|
require '../common'
|
2016-04-06 13:56:06 -04:00
|
|
|
AnalyticsUsersActive = require '../../../server/models/AnalyticsUsersActive'
|
|
|
|
LevelSession = require '../../../server/models/LevelSession'
|
|
|
|
User = require '../../../server/models/User'
|
|
|
|
mongoose = require 'mongoose'
|
2014-12-04 15:57:57 -05:00
|
|
|
|
|
|
|
# TODO: these tests have some rerun/cleanup issues
|
|
|
|
# TODO: add tests for purchase, payment, subscribe, unsubscribe, and earned achievements
|
|
|
|
|
2014-12-30 15:18:32 -05:00
|
|
|
# TODO: AnalyticsUsersActive collection isn't currently used.
|
|
|
|
# TODO: Will remove these tests if we end up ripping out the disabled saveActiveUser calls.
|
|
|
|
|
2014-12-04 15:57:57 -05:00
|
|
|
describe 'Analytics', ->
|
|
|
|
|
2014-12-30 15:18:32 -05:00
|
|
|
xit 'registered user', (done) ->
|
2014-12-04 15:57:57 -05:00
|
|
|
clearModels [AnalyticsUsersActive], (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
user = new User
|
|
|
|
permissions: []
|
|
|
|
name: "Fred" + Math.floor(Math.random() * 10000)
|
|
|
|
user.save (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
userID = mongoose.Types.ObjectId(user.get('_id'))
|
|
|
|
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
|
|
|
expect(activeUsers.length).toEqual(0)
|
|
|
|
user.register ->
|
|
|
|
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
expect(activeUsers.length).toEqual(1)
|
|
|
|
expect(activeUsers[0]?.get('event')).toEqual('register')
|
|
|
|
done()
|
|
|
|
|
2014-12-30 15:18:32 -05:00
|
|
|
xit 'level completed', (done) ->
|
2014-12-04 15:57:57 -05:00
|
|
|
clearModels [AnalyticsUsersActive], (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
unittest.getNormalJoe (joe) ->
|
|
|
|
userID = mongoose.Types.ObjectId(joe.get('_id'))
|
|
|
|
session = new LevelSession
|
|
|
|
name: 'Beat Gandalf'
|
|
|
|
levelID: 'lotr'
|
|
|
|
permissions: simplePermissions
|
|
|
|
state: complete: false
|
|
|
|
creator: userID
|
|
|
|
session.save (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
|
|
|
expect(activeUsers.length).toEqual(0)
|
|
|
|
session.set 'state', complete: true
|
|
|
|
session.save (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
expect(activeUsers.length).toEqual(1)
|
|
|
|
expect(activeUsers[0]?.get('event')).toEqual('level-completed/lotr')
|
|
|
|
done()
|
|
|
|
|
2014-12-30 15:18:32 -05:00
|
|
|
xit 'level playtime', (done) ->
|
2014-12-04 15:57:57 -05:00
|
|
|
clearModels [AnalyticsUsersActive], (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
unittest.getNormalJoe (joe) ->
|
|
|
|
userID = mongoose.Types.ObjectId(joe.get('_id'))
|
|
|
|
session = new LevelSession
|
|
|
|
name: 'Beat Gandalf'
|
|
|
|
levelID: 'lotr'
|
|
|
|
permissions: simplePermissions
|
|
|
|
playtime: 60
|
|
|
|
creator: userID
|
|
|
|
session.save (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
AnalyticsUsersActive.find {creator : userID}, (err, activeUsers) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
expect(activeUsers.length).toEqual(1)
|
|
|
|
expect(activeUsers[0]?.get('event')).toEqual('level-playtime/lotr')
|
|
|
|
done()
|
|
|
|
|