diff --git a/services/web/test/acceptance/src/RecurlySubscriptionUpdateTests.js b/services/web/test/acceptance/src/RecurlySubscriptionUpdateTests.js
index eb3b4e2016..180ab808ee 100644
--- a/services/web/test/acceptance/src/RecurlySubscriptionUpdateTests.js
+++ b/services/web/test/acceptance/src/RecurlySubscriptionUpdateTests.js
@@ -34,8 +34,9 @@ describe('Subscriptions', function() {
return done(error)
}
expect(statusCode).to.equal(200)
- // the actual email update is not tested as the mocked Recurly API
- // doesn't handle it
+ expect(this.recurlyUser.email).to.equal(
+ this.recurlySubscription.account.email
+ )
done()
})
})
diff --git a/services/web/test/acceptance/src/SubscriptionDashboardTests.js b/services/web/test/acceptance/src/SubscriptionDashboardTests.js
index 9fae81e9f2..d019cb17bb 100644
--- a/services/web/test/acceptance/src/SubscriptionDashboardTests.js
+++ b/services/web/test/acceptance/src/SubscriptionDashboardTests.js
@@ -16,6 +16,7 @@ const User = require('./helpers/User')
const { Subscription } = require('../../../app/src/models/Subscription')
const { Institution } = require('../../../app/src/models/Institution')
const SubscriptionViewModelBuilder = require('../../../app/src/Features/Subscription/SubscriptionViewModelBuilder')
+const RecurlySubscription = require('./helpers/RecurlySubscription')
const MockRecurlyApi = require('./helpers/MockRecurlyApi')
const MockV1Api = require('./helpers/MockV1Api')
@@ -61,56 +62,45 @@ describe('Subscriptions', function() {
describe('when the user has a subscription with recurly', function() {
beforeEach(function(done) {
- MockRecurlyApi.accounts['mock-account-id'] = this.accounts = {
- hosted_login_token: 'mock-login-token',
- email: 'mock@email.com'
- }
- MockRecurlyApi.subscriptions[
- 'mock-subscription-id'
- ] = this.subscription = {
- plan_code: 'collaborator',
+ this.recurlySubscription = new RecurlySubscription({
+ adminId: this.user._id,
+ planCode: 'collaborator',
tax_in_cents: 100,
tax_rate: 0.2,
unit_amount_in_cents: 500,
currency: 'GBP',
current_period_ends_at: new Date(2018, 4, 5),
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 = {
'test-coupon-1': { description: 'Test Coupon 1' },
'test-coupon-2': { description: 'Test Coupon 2' },
'test-coupon-3': { name: 'TestCoupon3' }
}
- Subscription.create(
- {
- admin_id: this.user._id,
- 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()
- }
- )
+ this.recurlySubscription.ensureExists(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()
+ }
+ )
+ })
})
after(function(done) {
- MockRecurlyApi.accounts = {}
- MockRecurlyApi.subscriptions = {}
+ MockRecurlyApi.mockSubscriptions = []
MockRecurlyApi.coupons = {}
MockRecurlyApi.redemptions = {}
Subscription.remove(
@@ -141,7 +131,7 @@ describe('Subscriptions', function() {
trial_ends_at: new Date(2018, 6, 7),
trialEndsAtFormatted: '7th July 2018',
account: {
- account_code: 'mock-account-id',
+ account_code: this.user._id,
email: 'mock@email.com',
hosted_login_token: 'mock-login-token'
}
@@ -153,7 +143,7 @@ describe('Subscriptions', function() {
})
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: 'inactive', coupon_code: 'test-coupon-2' },
{ state: 'active', coupon_code: 'test-coupon-3' }
diff --git a/services/web/test/acceptance/src/helpers/MockRecurlyApi.js b/services/web/test/acceptance/src/helpers/MockRecurlyApi.js
index 723ecb626a..b82adf5178 100644
--- a/services/web/test/acceptance/src/helpers/MockRecurlyApi.js
+++ b/services/web/test/acceptance/src/helpers/MockRecurlyApi.js
@@ -19,25 +19,31 @@ const SubscriptionController = require('../../../../app/src/Features/Subscriptio
app.use(bodyParser.json())
module.exports = MockRecurlyApi = {
- subscriptions: {},
-
- accounts: {},
+ mockSubscriptions: [],
redemptions: {},
coupons: {},
- addSubscription(subscription) {
- this.subscriptions[subscription.uuid] = subscription
+ addMockSubscription(recurlySubscription) {
+ this.mockSubscriptions.push(recurlySubscription)
},
- addAccount(account) {
- this.accounts[account.id] = account
+ getMockSubscriptionByAccountId(accountId) {
+ return this.mockSubscriptions.find(
+ mockSubscription => mockSubscription.account.id === accountId
+ )
+ },
+
+ getMockSubscriptionById(uuid) {
+ return this.mockSubscriptions.find(
+ mockSubscription => mockSubscription.uuid === uuid
+ )
},
run() {
app.get('/subscriptions/:id', (req, res, next) => {
- const subscription = this.subscriptions[req.params.id]
+ const subscription = this.getMockSubscriptionById(req.params.id)
if (subscription == null) {
return res.status(404).end()
} else {
@@ -54,7 +60,7 @@ module.exports = MockRecurlyApi = {
${
subscription.unit_amount_in_cents
}
-
+
${subscription.trial_ends_at}
\
`)
@@ -62,15 +68,17 @@ module.exports = MockRecurlyApi = {
})
app.get('/accounts/:id', (req, res, next) => {
- const account = this.accounts[req.params.id]
- if (account == null) {
+ const subscription = this.getMockSubscriptionByAccountId(req.params.id)
+ if (subscription == null) {
return res.status(404).end()
} else {
return res.send(`\
${req.params.id}
- ${account.hosted_login_token}
- ${account.email}
+ ${
+ subscription.account.hosted_login_token
+ }
+ ${subscription.account.email}
\
`)
}
@@ -80,14 +88,15 @@ module.exports = MockRecurlyApi = {
'/accounts/:id',
SubscriptionController.recurlyNotificationParser, // required to parse XML requests
(req, res, next) => {
- const account = this.accounts[req.params.id]
- if (account == null) {
+ const subscription = this.getMockSubscriptionByAccountId(req.params.id)
+ if (subscription == null) {
return res.status(404).end()
} else {
+ Object.assign(subscription.account, req.body.account)
return res.send(`\
${req.params.id}
- ${account.email}
+ ${subscription.account.email}
\
`)
}
diff --git a/services/web/test/acceptance/src/helpers/RecurlySubscription.js b/services/web/test/acceptance/src/helpers/RecurlySubscription.js
index dc33509e08..e5f88318e2 100644
--- a/services/web/test/acceptance/src/helpers/RecurlySubscription.js
+++ b/services/web/test/acceptance/src/helpers/RecurlySubscription.js
@@ -5,13 +5,21 @@ const RecurlyWrapper = require('../../../../app/src/Features/Subscription/Recurl
class RecurlySubscription {
constructor(options = {}) {
+ options.recurlySubscription_id = ObjectId().toString()
this.subscription = new Subscription(options)
- this.uuid = ObjectId().toString()
- this.accountId = this.subscription.admin_id.toString()
+ this.uuid = options.recurlySubscription_id
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 = {
- 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) {
return callback(error)
}
- MockRecurlyApi.addSubscription({
- uuid: this.uuid,
- account_id: this.accountId,
- state: this.state
- })
- MockRecurlyApi.addAccount({
- id: this.accountId,
- email: this.account.email
- })
+ MockRecurlyApi.addMockSubscription(this)
callback()
})
}
diff --git a/services/web/test/acceptance/src/helpers/Subscription.js b/services/web/test/acceptance/src/helpers/Subscription.js
index 57d57aedc2..8bc52512c3 100644
--- a/services/web/test/acceptance/src/helpers/Subscription.js
+++ b/services/web/test/acceptance/src/helpers/Subscription.js
@@ -16,6 +16,7 @@ class Subscription {
this.invited_emails = options.invitedEmails || []
this.teamInvites = options.teamInvites || []
this.planCode = options.planCode
+ this.recurlySubscription_id = options.recurlySubscription_id
}
ensureExists(callback) {