Merge pull request #3049 from overleaf/jlm-fix-referral-projection

Fix referral projection

GitOrigin-RevId: 37c68bf6bfa81a694e2f919b262634a9a1b63f8b
This commit is contained in:
Jakob Ackermann 2020-07-27 11:01:31 +02:00 committed by Copybot
parent 064ecda24f
commit 7847209eaa
5 changed files with 42 additions and 19 deletions

View file

@ -2,7 +2,8 @@ const { User } = require('../../models/User')
module.exports = {
getReferedUsers(userId, callback) {
User.findById(userId, { refered_users: 1 }, function(err, user) {
const projection = { refered_users: 1, refered_user_count: 1 }
User.findById(userId, projection, function(err, user) {
if (err) {
return callback(err)
}

View file

@ -86,7 +86,7 @@ block content
.row  
.row.ab-bonus
.col-md-10.col-md-offset-1.bonus-banner
.col-md-10.col-md-offset-1.bonus-banner.bonus-status
- if (refered_user_count == 0)
p.thanks !{translate("you_not_introed_anyone_to_sl")}
- else if (refered_user_count == 1)

View file

@ -171,6 +171,17 @@ module.exports =
'google': {
name: 'google'
},
# for testing /user/bonus
social:
twitter:
handle: 'overleaf'
facebook:
appId: '400474170024644'
picture: 'https://www.overleaf.com/img/ol-brand/logo-horizontal.png'
redirectUri: 'https://www.overleaf.com'
# setting to true since many features are enabled/disabled after availability of this
# property (check Features.js)
overleaf: true

View file

@ -0,0 +1,28 @@
const { expect } = require('chai')
const cheerio = require('cheerio')
const UserHelper = require('../src/helpers/UserHelper')
describe('Bonus', function() {
let userHelper
beforeEach(async function() {
userHelper = new UserHelper()
const email = userHelper.getDefaultEmail()
userHelper = await UserHelper.createUser({ email })
userHelper = await UserHelper.loginUser({
email,
password: userHelper.getDefaultPassword()
})
})
it('should use the count rather than refered_users', async function() {
await UserHelper.updateUser(userHelper.user._id, {
$set: { refered_user_count: 1, refered_users: [] }
})
const response = await userHelper.request.get('/user/bonus')
expect(response.statusCode).to.equal(200)
const dom = cheerio.load(response.body)
expect(dom('.bonus-status').text()).to.match(/You've introduced 1 person/)
})
})

View file

@ -87,23 +87,6 @@ describe('Referal handler', function() {
)
})
it('should return the count if it differs from the array length', function(done) {
const user = {
refered_users: ['1234', '312312', '3213129'],
refered_user_count: 5
}
this.User.findById.callsArgWith(2, null, user)
this.handler.getReferedUsers(
this.user_id,
(err, passedReferedUserIds, passedReferedUserCount) => {
should.not.exist(err)
passedReferedUserCount.should.equal(5)
done()
}
)
})
it('should error if finding the user fails', function(done) {
this.User.findById.callsArgWith(2, new Error('user not found'))