Merge branch 'master' into master-redesign

This commit is contained in:
James Allen 2014-07-08 13:24:48 +01:00
commit 8c56a46594
7 changed files with 0 additions and 105 deletions

View file

@ -1,5 +1,4 @@
settings = require('settings-sharelatex')
SubscriptionBackgroundTasks = require("./app/js/Features/Subscription/SubscriptionBackgroundTasks")
TpdsPollingBackgroundTasks = require("./app/js/Features/ThirdPartyDataStore/TpdsPollingBackgroundTasks")
time =
@ -19,7 +18,4 @@ runPeriodically = (funcToRun, periodLength)->
setTimeout recursiveReference, periodLength
setTimeout recursiveReference, 0
# TODO: Remove this one month after the ability to start free trials was removed
runPeriodically ((cb) -> SubscriptionBackgroundTasks.downgradeExpiredFreeTrials(cb)), time.oneHour
runPeriodically ((cb) -> TpdsPollingBackgroundTasks.pollUsersWithDropbox(cb)), time.fifteenMinutes

View file

@ -1,19 +0,0 @@
async = require 'async'
logger = require 'logger-sharelatex'
SubscriptionUpdater = require("./SubscriptionUpdater")
SubscriptionLocator = require("./SubscriptionLocator")
module.exports = SubscriptionBackgroundJobs =
# TODO: Remove this one month after the ability to start free trials was removed
downgradeExpiredFreeTrials: (callback = (error, subscriptions)->) ->
SubscriptionLocator.expiredFreeTrials (error, subscriptions) =>
return callback(error) if error?
logger.log total_subscriptions:subscriptions.length, "downgraging subscriptions"
downgrades = []
for subscription in subscriptions
do (subscription) =>
downgrades.push (cb) =>
logger.log subscription: subscription, "downgrading free trial"
SubscriptionUpdater.downgradeFreeTrial(subscription, cb)
async.series downgrades, (error) -> callback(error, subscriptions)

View file

@ -12,9 +12,3 @@ module.exports =
logger.log user_id:user_id, "getting users subscription"
Subscription.findOne admin_id:user_id, callback
# TODO: Remove this one month after the ability to start free trials was removed
expiredFreeTrials: (callback = (error, subscriptions)->) ->
query =
"freeTrial.expiresAt": "$lt": new Date()
"freeTrial.downgraded": "$ne": true
Subscription.find query, callback

View file

@ -24,12 +24,6 @@ module.exports =
self._createNewSubscription adminUser_id, (err, subscription)->
self._updateSubscription recurlySubscription, subscription, callback
# TODO: Remove this one month after the ability to start free trials was removed
downgradeFreeTrial: (subscription, callback = (error)->) ->
UserFeaturesUpdater.updateFeatures subscription.admin_id, Settings.defaultPlanCode, ->
subscription.freeTrial.downgraded = true
subscription.save callback
addUserToGroup: (adminUser_id, user_id, callback)->
logger.log adminUser_id:adminUser_id, user_id:user_id, "adding user into mongo subscription"
searchOps =

View file

@ -1,38 +0,0 @@
sinon = require('sinon')
require('chai').should()
SandboxedModule = require('sandboxed-module')
modulePath = require('path').join __dirname, '../../../../app/js/Features/Subscription/SubscriptionBackgroundTasks'
describe "SubscriptionBackgroundTasks", ->
beforeEach ->
@SubscriptionLocator = {}
@Settings = defaultPlanCode:
collaborators: 13
versioning: true
@SubscriptionUpdater = {}
@SubscriptionBackgroundTasks = SandboxedModule.require modulePath, requires:
"./SubscriptionLocator" : @SubscriptionLocator
"./SubscriptionUpdater" : @SubscriptionUpdater
"settings-sharelatex" : @Settings
"logger-sharelatex" : log:->
describe 'downgradeExpiredFreeTrials', ->
beforeEach ->
@subscriptions = [
{ admin_id : 1 },
{ admin_id : 2 }
]
@SubscriptionUpdater.downgradeFreeTrial = sinon.stub().callsArg(1)
@SubscriptionLocator.expiredFreeTrials = sinon.stub().callsArgWith(0, null, @subscriptions)
@callback = sinon.stub()
@SubscriptionBackgroundTasks.downgradeExpiredFreeTrials(@callback)
it "should downgrade each expired subscription", ->
@SubscriptionUpdater.downgradeFreeTrial.callCount.should.equal @subscriptions.length
for subscription in @subscriptions
@SubscriptionUpdater.downgradeFreeTrial.calledWith(subscription).should.equal true
it "should return the subscriptions in the callback", ->
@callback.called.should.equal true
@callback.args[0][1].should.deep.equal @subscriptions

View file

@ -40,21 +40,3 @@ describe "Subscription Locator Tests", ->
subscription.should.equal @subscription
done()
describe "expiredFreeTrials", ->
beforeEach ->
@subscriptions = [ _id : 1, freeTrial:{} ]
@Subscription.find = sinon.stub().callsArgWith(1, null, @subscriptions)
it "should look for subscriptions with an expired free trial that haven't been downgraded", (done)->
@SubscriptionLocator.expiredFreeTrials =>
@Subscription.find.called.should.equal true
query = @Subscription.find.args[0][0]
assert.isDefined(query["freeTrial.expiresAt"].$lt)
assert.deepEqual(query["freeTrial.downgraded"],"$ne": true)
done()
it "should return the subscriptions in a callback", (done)->
@SubscriptionLocator.expiredFreeTrials (err, subscriptions)=>
subscriptions.should.deep.equal @subscriptions
done()

View file

@ -119,20 +119,6 @@ describe "Subscription Updater", ->
@subscription.save.called.should.equal true
done()
describe 'downgradeFreeTrial', ->
it "should tell the feature updater to update the user", (done)->
@SubscriptionUpdater.downgradeFreeTrial @subscription, =>
@UserFeaturesUpdater.updateFeatures.calledWith(@subscription.admin_id, @Settings.defaultPlanCode).should.equal true
done()
it "should update the subscription", (done)->
@SubscriptionUpdater.downgradeFreeTrial @subscription, =>
@subscription.freeTrial.downgraded.should.equal true
@subscription.save.called.should.equal true
done()
describe "addUserToGroup", ->
it "should add the users id to the group as a set", (done)->
@SubscriptionUpdater.addUserToGroup @adminUser._id, @otherUserId, =>