mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #2543 from overleaf/hb-remove-unused-v1-endpoints
Remove unused v1 endpoints GitOrigin-RevId: b7d629b42f10074cf17dfb1d851316f970584a81
This commit is contained in:
parent
1f514ec603
commit
60554cb634
2 changed files with 115 additions and 1 deletions
|
@ -278,6 +278,28 @@ const FeaturesUpdater = {
|
|||
}
|
||||
|
||||
return mismatchReasons
|
||||
},
|
||||
|
||||
doSyncFromV1(v1UserId, callback) {
|
||||
logger.log({ v1UserId }, '[AccountSync] starting account sync')
|
||||
return UserGetter.getUser({ 'overleaf.id': v1UserId }, { _id: 1 }, function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
if (err != null) {
|
||||
logger.warn({ v1UserId }, '[AccountSync] error getting user')
|
||||
return callback(err)
|
||||
}
|
||||
if ((user != null ? user._id : undefined) == null) {
|
||||
logger.warn({ v1UserId }, '[AccountSync] no user found for v1 id')
|
||||
return callback(null)
|
||||
}
|
||||
logger.log(
|
||||
{ v1UserId, userId: user._id },
|
||||
'[AccountSync] updating user subscription and features'
|
||||
)
|
||||
return FeaturesUpdater.refreshFeatures(user._id, callback)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,10 @@ describe('FeaturesUpdater', function() {
|
|||
'./SubscriptionLocator': (this.SubscriptionLocator = {}),
|
||||
'./PlansLocator': (this.PlansLocator = {}),
|
||||
'logger-sharelatex': {
|
||||
log() {}
|
||||
log() {},
|
||||
warn(obj, text) {
|
||||
console.log(text)
|
||||
}
|
||||
},
|
||||
'settings-sharelatex': (this.Settings = {}),
|
||||
'../Referal/ReferalFeatures': (this.ReferalFeatures = {}),
|
||||
|
@ -318,4 +321,93 @@ describe('FeaturesUpdater', function() {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('doSyncFromV1', function() {
|
||||
beforeEach(function() {
|
||||
this.v1UserId = 1
|
||||
this.user = {
|
||||
_id: this.user_id,
|
||||
email: 'user@example.com',
|
||||
overleaf: {
|
||||
id: this.v1UserId
|
||||
}
|
||||
}
|
||||
|
||||
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, this.user)
|
||||
this.FeaturesUpdater.refreshFeatures = sinon.stub().yields(null)
|
||||
return (this.call = cb => {
|
||||
return this.FeaturesUpdater.doSyncFromV1(this.v1UserId, cb)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when all goes well', function() {
|
||||
it('should call getUser', function(done) {
|
||||
return this.call(() => {
|
||||
expect(this.UserGetter.getUser.callCount).to.equal(1)
|
||||
expect(
|
||||
this.UserGetter.getUser.calledWith({ 'overleaf.id': this.v1UserId })
|
||||
).to.equal(true)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call refreshFeatures', function(done) {
|
||||
return this.call(() => {
|
||||
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(1)
|
||||
expect(
|
||||
this.FeaturesUpdater.refreshFeatures.calledWith(this.user_id)
|
||||
).to.equal(true)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.exist
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when getUser produces an error', function() {
|
||||
beforeEach(function() {
|
||||
return (this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, new Error('woops')))
|
||||
})
|
||||
|
||||
it('should not call refreshFeatures', function() {
|
||||
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(0)
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.exist
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when getUser does not find a user', function() {
|
||||
beforeEach(function() {
|
||||
return (this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, null))
|
||||
})
|
||||
|
||||
it('should not call refreshFeatures', function(done) {
|
||||
return this.call(() => {
|
||||
expect(this.FeaturesUpdater.refreshFeatures.callCount).to.equal(0)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.exist
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue