mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #2611 from overleaf/ta-cmg-recurly-email-update-test-plus
Improve Recurly API Acceptance Test GitOrigin-RevId: 89f4707c9baaa20e59f64821daa36551ad700118
This commit is contained in:
parent
174af14d46
commit
17969c50ce
5 changed files with 68 additions and 67 deletions
|
@ -34,8 +34,9 @@ describe('Subscriptions', function() {
|
||||||
return done(error)
|
return done(error)
|
||||||
}
|
}
|
||||||
expect(statusCode).to.equal(200)
|
expect(statusCode).to.equal(200)
|
||||||
// the actual email update is not tested as the mocked Recurly API
|
expect(this.recurlyUser.email).to.equal(
|
||||||
// doesn't handle it
|
this.recurlySubscription.account.email
|
||||||
|
)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,6 +16,7 @@ const User = require('./helpers/User')
|
||||||
const { Subscription } = require('../../../app/src/models/Subscription')
|
const { Subscription } = require('../../../app/src/models/Subscription')
|
||||||
const { Institution } = require('../../../app/src/models/Institution')
|
const { Institution } = require('../../../app/src/models/Institution')
|
||||||
const SubscriptionViewModelBuilder = require('../../../app/src/Features/Subscription/SubscriptionViewModelBuilder')
|
const SubscriptionViewModelBuilder = require('../../../app/src/Features/Subscription/SubscriptionViewModelBuilder')
|
||||||
|
const RecurlySubscription = require('./helpers/RecurlySubscription')
|
||||||
|
|
||||||
const MockRecurlyApi = require('./helpers/MockRecurlyApi')
|
const MockRecurlyApi = require('./helpers/MockRecurlyApi')
|
||||||
const MockV1Api = require('./helpers/MockV1Api')
|
const MockV1Api = require('./helpers/MockV1Api')
|
||||||
|
@ -61,56 +62,45 @@ describe('Subscriptions', function() {
|
||||||
|
|
||||||
describe('when the user has a subscription with recurly', function() {
|
describe('when the user has a subscription with recurly', function() {
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
MockRecurlyApi.accounts['mock-account-id'] = this.accounts = {
|
this.recurlySubscription = new RecurlySubscription({
|
||||||
hosted_login_token: 'mock-login-token',
|
adminId: this.user._id,
|
||||||
email: 'mock@email.com'
|
planCode: 'collaborator',
|
||||||
}
|
|
||||||
MockRecurlyApi.subscriptions[
|
|
||||||
'mock-subscription-id'
|
|
||||||
] = this.subscription = {
|
|
||||||
plan_code: 'collaborator',
|
|
||||||
tax_in_cents: 100,
|
tax_in_cents: 100,
|
||||||
tax_rate: 0.2,
|
tax_rate: 0.2,
|
||||||
unit_amount_in_cents: 500,
|
unit_amount_in_cents: 500,
|
||||||
currency: 'GBP',
|
currency: 'GBP',
|
||||||
current_period_ends_at: new Date(2018, 4, 5),
|
current_period_ends_at: new Date(2018, 4, 5),
|
||||||
state: 'active',
|
state: 'active',
|
||||||
account_id: 'mock-account-id',
|
trial_ends_at: new Date(2018, 6, 7),
|
||||||
trial_ends_at: new Date(2018, 6, 7)
|
account: {
|
||||||
}
|
hosted_login_token: 'mock-login-token',
|
||||||
|
email: 'mock@email.com'
|
||||||
|
}
|
||||||
|
})
|
||||||
MockRecurlyApi.coupons = this.coupons = {
|
MockRecurlyApi.coupons = this.coupons = {
|
||||||
'test-coupon-1': { description: 'Test Coupon 1' },
|
'test-coupon-1': { description: 'Test Coupon 1' },
|
||||||
'test-coupon-2': { description: 'Test Coupon 2' },
|
'test-coupon-2': { description: 'Test Coupon 2' },
|
||||||
'test-coupon-3': { name: 'TestCoupon3' }
|
'test-coupon-3': { name: 'TestCoupon3' }
|
||||||
}
|
}
|
||||||
Subscription.create(
|
this.recurlySubscription.ensureExists(error => {
|
||||||
{
|
if (error != null) {
|
||||||
admin_id: this.user._id,
|
return done(error)
|
||||||
manager_ids: [this.user._id],
|
|
||||||
recurlySubscription_id: 'mock-subscription-id',
|
|
||||||
planCode: 'collaborator'
|
|
||||||
},
|
|
||||||
error => {
|
|
||||||
if (error != null) {
|
|
||||||
return done(error)
|
|
||||||
}
|
|
||||||
return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
||||||
this.user,
|
|
||||||
(error, data) => {
|
|
||||||
this.data = data
|
|
||||||
if (error != null) {
|
|
||||||
return done(error)
|
|
||||||
}
|
|
||||||
return done()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
||||||
|
this.user,
|
||||||
|
(error, data) => {
|
||||||
|
this.data = data
|
||||||
|
if (error != null) {
|
||||||
|
return done(error)
|
||||||
|
}
|
||||||
|
return done()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
MockRecurlyApi.accounts = {}
|
MockRecurlyApi.mockSubscriptions = []
|
||||||
MockRecurlyApi.subscriptions = {}
|
|
||||||
MockRecurlyApi.coupons = {}
|
MockRecurlyApi.coupons = {}
|
||||||
MockRecurlyApi.redemptions = {}
|
MockRecurlyApi.redemptions = {}
|
||||||
Subscription.remove(
|
Subscription.remove(
|
||||||
|
@ -141,7 +131,7 @@ describe('Subscriptions', function() {
|
||||||
trial_ends_at: new Date(2018, 6, 7),
|
trial_ends_at: new Date(2018, 6, 7),
|
||||||
trialEndsAtFormatted: '7th July 2018',
|
trialEndsAtFormatted: '7th July 2018',
|
||||||
account: {
|
account: {
|
||||||
account_code: 'mock-account-id',
|
account_code: this.user._id,
|
||||||
email: 'mock@email.com',
|
email: 'mock@email.com',
|
||||||
hosted_login_token: 'mock-login-token'
|
hosted_login_token: 'mock-login-token'
|
||||||
}
|
}
|
||||||
|
@ -153,7 +143,7 @@ describe('Subscriptions', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should include redeemed coupons', function(done) {
|
it('should include redeemed coupons', function(done) {
|
||||||
MockRecurlyApi.redemptions['mock-account-id'] = [
|
MockRecurlyApi.redemptions[this.user._id] = [
|
||||||
{ state: 'active', coupon_code: 'test-coupon-1' },
|
{ state: 'active', coupon_code: 'test-coupon-1' },
|
||||||
{ state: 'inactive', coupon_code: 'test-coupon-2' },
|
{ state: 'inactive', coupon_code: 'test-coupon-2' },
|
||||||
{ state: 'active', coupon_code: 'test-coupon-3' }
|
{ state: 'active', coupon_code: 'test-coupon-3' }
|
||||||
|
|
|
@ -19,25 +19,31 @@ const SubscriptionController = require('../../../../app/src/Features/Subscriptio
|
||||||
app.use(bodyParser.json())
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
module.exports = MockRecurlyApi = {
|
module.exports = MockRecurlyApi = {
|
||||||
subscriptions: {},
|
mockSubscriptions: [],
|
||||||
|
|
||||||
accounts: {},
|
|
||||||
|
|
||||||
redemptions: {},
|
redemptions: {},
|
||||||
|
|
||||||
coupons: {},
|
coupons: {},
|
||||||
|
|
||||||
addSubscription(subscription) {
|
addMockSubscription(recurlySubscription) {
|
||||||
this.subscriptions[subscription.uuid] = subscription
|
this.mockSubscriptions.push(recurlySubscription)
|
||||||
},
|
},
|
||||||
|
|
||||||
addAccount(account) {
|
getMockSubscriptionByAccountId(accountId) {
|
||||||
this.accounts[account.id] = account
|
return this.mockSubscriptions.find(
|
||||||
|
mockSubscription => mockSubscription.account.id === accountId
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
getMockSubscriptionById(uuid) {
|
||||||
|
return this.mockSubscriptions.find(
|
||||||
|
mockSubscription => mockSubscription.uuid === uuid
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
app.get('/subscriptions/:id', (req, res, next) => {
|
app.get('/subscriptions/:id', (req, res, next) => {
|
||||||
const subscription = this.subscriptions[req.params.id]
|
const subscription = this.getMockSubscriptionById(req.params.id)
|
||||||
if (subscription == null) {
|
if (subscription == null) {
|
||||||
return res.status(404).end()
|
return res.status(404).end()
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,7 +60,7 @@ module.exports = MockRecurlyApi = {
|
||||||
<unit_amount_in_cents type="integer">${
|
<unit_amount_in_cents type="integer">${
|
||||||
subscription.unit_amount_in_cents
|
subscription.unit_amount_in_cents
|
||||||
}</unit_amount_in_cents>
|
}</unit_amount_in_cents>
|
||||||
<account href="accounts/${subscription.account_id}" />
|
<account href="accounts/${subscription.account.id}" />
|
||||||
<trial_ends_at type="datetime">${subscription.trial_ends_at}</trial_ends_at>
|
<trial_ends_at type="datetime">${subscription.trial_ends_at}</trial_ends_at>
|
||||||
</subscription>\
|
</subscription>\
|
||||||
`)
|
`)
|
||||||
|
@ -62,15 +68,17 @@ module.exports = MockRecurlyApi = {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/accounts/:id', (req, res, next) => {
|
app.get('/accounts/:id', (req, res, next) => {
|
||||||
const account = this.accounts[req.params.id]
|
const subscription = this.getMockSubscriptionByAccountId(req.params.id)
|
||||||
if (account == null) {
|
if (subscription == null) {
|
||||||
return res.status(404).end()
|
return res.status(404).end()
|
||||||
} else {
|
} else {
|
||||||
return res.send(`\
|
return res.send(`\
|
||||||
<account>
|
<account>
|
||||||
<account_code>${req.params.id}</account_code>
|
<account_code>${req.params.id}</account_code>
|
||||||
<hosted_login_token>${account.hosted_login_token}</hosted_login_token>
|
<hosted_login_token>${
|
||||||
<email>${account.email}</email>
|
subscription.account.hosted_login_token
|
||||||
|
}</hosted_login_token>
|
||||||
|
<email>${subscription.account.email}</email>
|
||||||
</account>\
|
</account>\
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
@ -80,14 +88,15 @@ module.exports = MockRecurlyApi = {
|
||||||
'/accounts/:id',
|
'/accounts/:id',
|
||||||
SubscriptionController.recurlyNotificationParser, // required to parse XML requests
|
SubscriptionController.recurlyNotificationParser, // required to parse XML requests
|
||||||
(req, res, next) => {
|
(req, res, next) => {
|
||||||
const account = this.accounts[req.params.id]
|
const subscription = this.getMockSubscriptionByAccountId(req.params.id)
|
||||||
if (account == null) {
|
if (subscription == null) {
|
||||||
return res.status(404).end()
|
return res.status(404).end()
|
||||||
} else {
|
} else {
|
||||||
|
Object.assign(subscription.account, req.body.account)
|
||||||
return res.send(`\
|
return res.send(`\
|
||||||
<account>
|
<account>
|
||||||
<account_code>${req.params.id}</account_code>
|
<account_code>${req.params.id}</account_code>
|
||||||
<email>${account.email}</email>
|
<email>${subscription.account.email}</email>
|
||||||
</account>\
|
</account>\
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,21 @@ const RecurlyWrapper = require('../../../../app/src/Features/Subscription/Recurl
|
||||||
|
|
||||||
class RecurlySubscription {
|
class RecurlySubscription {
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
|
options.recurlySubscription_id = ObjectId().toString()
|
||||||
this.subscription = new Subscription(options)
|
this.subscription = new Subscription(options)
|
||||||
|
|
||||||
this.uuid = ObjectId().toString()
|
this.uuid = options.recurlySubscription_id
|
||||||
this.accountId = this.subscription.admin_id.toString()
|
|
||||||
this.state = options.state || 'active'
|
this.state = options.state || 'active'
|
||||||
|
this.tax_in_cents = 100
|
||||||
|
this.tax_rate = 0.2
|
||||||
|
this.unit_amount_in_cents = 500
|
||||||
|
this.currency = 'GBP'
|
||||||
|
this.current_period_ends_at = new Date(2018, 4, 5)
|
||||||
|
this.trial_ends_at = new Date(2018, 6, 7)
|
||||||
this.account = {
|
this.account = {
|
||||||
email: options.account && options.account.email
|
id: this.subscription.admin_id.toString(),
|
||||||
|
email: options.account && options.account.email,
|
||||||
|
hosted_login_token: options.account && options.account.hosted_login_token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,15 +28,7 @@ class RecurlySubscription {
|
||||||
if (error) {
|
if (error) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
MockRecurlyApi.addSubscription({
|
MockRecurlyApi.addMockSubscription(this)
|
||||||
uuid: this.uuid,
|
|
||||||
account_id: this.accountId,
|
|
||||||
state: this.state
|
|
||||||
})
|
|
||||||
MockRecurlyApi.addAccount({
|
|
||||||
id: this.accountId,
|
|
||||||
email: this.account.email
|
|
||||||
})
|
|
||||||
callback()
|
callback()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ class Subscription {
|
||||||
this.invited_emails = options.invitedEmails || []
|
this.invited_emails = options.invitedEmails || []
|
||||||
this.teamInvites = options.teamInvites || []
|
this.teamInvites = options.teamInvites || []
|
||||||
this.planCode = options.planCode
|
this.planCode = options.planCode
|
||||||
|
this.recurlySubscription_id = options.recurlySubscription_id
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureExists(callback) {
|
ensureExists(callback) {
|
||||||
|
|
Loading…
Reference in a new issue