mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Add function to properties that trigger achievement updates
This commit is contained in:
parent
2fe28852b4
commit
9088f98eae
3 changed files with 8 additions and 3 deletions
|
@ -65,7 +65,7 @@ Application = {
|
||||||
unless me.get('anonymous')
|
unless me.get('anonymous')
|
||||||
# TODO: Remove logging later, once this system has proved stable
|
# TODO: Remove logging later, once this system has proved stable
|
||||||
me.on 'change:earned', (user, newEarned) ->
|
me.on 'change:earned', (user, newEarned) ->
|
||||||
oldEarned = user.previous('earned')
|
oldEarned = user.previous('earned') ? {}
|
||||||
if oldEarned.gems isnt newEarned.gems
|
if oldEarned.gems isnt newEarned.gems
|
||||||
console.log 'Gems changed', oldEarned.gems, '->', newEarned.gems
|
console.log 'Gems changed', oldEarned.gems, '->', newEarned.gems
|
||||||
newLevels = _.difference(newEarned.levels, oldEarned.levels)
|
newLevels = _.difference(newEarned.levels, oldEarned.levels)
|
||||||
|
|
|
@ -19,7 +19,7 @@ module.exports =
|
||||||
unless hasPermission or database.isJustFillingTranslations(req, achievement)
|
unless hasPermission or database.isJustFillingTranslations(req, achievement)
|
||||||
throw new errors.Forbidden('Must be an admin, artisan or submitting translations to edit an achievement')
|
throw new errors.Forbidden('Must be an admin, artisan or submitting translations to edit an achievement')
|
||||||
|
|
||||||
propsWatching = ['query', 'proportionalTo', 'rewards', 'worth']
|
propsWatching = ['query', 'proportionalTo', 'rewards', 'worth', 'function']
|
||||||
oldCopy = _.pick(achievement.toObject(), propsWatching)
|
oldCopy = _.pick(achievement.toObject(), propsWatching)
|
||||||
database.assignBody(req, achievement)
|
database.assignBody(req, achievement)
|
||||||
newCopy = _.pick(achievement.toObject(), propsWatching)
|
newCopy = _.pick(achievement.toObject(), propsWatching)
|
||||||
|
|
|
@ -109,7 +109,7 @@ describe 'PUT /db/achievement', ->
|
||||||
expect(res.body.name).toBe('whatev')
|
expect(res.body.name).toBe('whatev')
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'touches "updated" if query, proportionalTo, worth, or rewards change', utils.wrap (done) ->
|
it 'touches "updated" if query, proportionalTo, worth, rewards or function change', utils.wrap (done) ->
|
||||||
lastUpdated = @unlockable.get('updated')
|
lastUpdated = @unlockable.get('updated')
|
||||||
expect(lastUpdated).toBeDefined()
|
expect(lastUpdated).toBeDefined()
|
||||||
[res, body] = yield request.putAsync {uri: url + '/'+@unlockable.id, json: {
|
[res, body] = yield request.putAsync {uri: url + '/'+@unlockable.id, json: {
|
||||||
|
@ -140,6 +140,11 @@ describe 'PUT /db/achievement', ->
|
||||||
newWorth = 1000
|
newWorth = 1000
|
||||||
[res, body] = yield request.putAsync {uri: url + '/'+@unlockable.id, json: {worth: newWorth}}
|
[res, body] = yield request.putAsync {uri: url + '/'+@unlockable.id, json: {worth: newWorth}}
|
||||||
expect(res.body.updated).not.toBe(lastUpdated)
|
expect(res.body.updated).not.toBe(lastUpdated)
|
||||||
|
lastUpdated = res.body.updated
|
||||||
|
|
||||||
|
newFunction = { kind: 'logarithmic', parameters: { a: 1, b: 2, c: 3 } }
|
||||||
|
[res, body] = yield request.putAsync {uri: url + '/'+@unlockable.id, json: {function: newFunction}}
|
||||||
|
expect(res.body.updated).not.toBe(lastUpdated)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue