|
|
@@ -1,18 +1,6 @@
|
|
|
-/* eslint-disable
|
|
|
- node/handle-callback-err,
|
|
|
- max-len,
|
|
|
-*/
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
-/*
|
|
|
- * decaffeinate suggestions:
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
- * DS207: Consider shorter variations of null checks
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
- */
|
|
|
const { expect } = require('chai')
|
|
|
const async = require('async')
|
|
|
-const User = require('./helpers/User')
|
|
|
+const UserHelper = require('./helpers/UserHelper')
|
|
|
const { Subscription } = require('../../../app/src/models/Subscription')
|
|
|
const { Institution } = require('../../../app/src/models/Institution')
|
|
|
const SubscriptionViewModelBuilder = require('../../../app/src/Features/Subscription/SubscriptionViewModelBuilder')
|
|
|
@@ -20,6 +8,18 @@ const RecurlySubscription = require('./helpers/RecurlySubscription')
|
|
|
const MockRecurlyApiClass = require('./mocks/MockRecurlyApi')
|
|
|
const MockV1ApiClass = require('./mocks/MockV1Api')
|
|
|
|
|
|
+async function buildUsersSubscriptionViewModelPromise(userId) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
+ userId,
|
|
|
+ (error, data) => {
|
|
|
+ if (error) reject(error)
|
|
|
+ resolve(data)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
let MockV1Api, MockRecurlyApi
|
|
|
|
|
|
before(function() {
|
|
|
@@ -29,9 +29,10 @@ before(function() {
|
|
|
|
|
|
describe('Subscriptions', function() {
|
|
|
describe('dashboard', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.user = new User()
|
|
|
- return this.user.ensureUserExists(done)
|
|
|
+ let userHelper
|
|
|
+ beforeEach(async function() {
|
|
|
+ userHelper = await UserHelper.createUser()
|
|
|
+ this.user = userHelper.user
|
|
|
})
|
|
|
|
|
|
it('should not list personal plan', function() {
|
|
|
@@ -45,24 +46,24 @@ describe('Subscriptions', function() {
|
|
|
|
|
|
describe('when the user has no subscription', function() {
|
|
|
beforeEach(function(done) {
|
|
|
- return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
+ SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
this.user,
|
|
|
(error, data) => {
|
|
|
this.data = data
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return done()
|
|
|
+ done()
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should return no personalSubscription', function() {
|
|
|
- return expect(this.data.personalSubscription).to.equal(null)
|
|
|
+ expect(this.data.personalSubscription).to.equal(null)
|
|
|
})
|
|
|
|
|
|
it('should return no memberGroupSubscriptions', function() {
|
|
|
- return expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
+ expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -89,17 +90,17 @@ describe('Subscriptions', function() {
|
|
|
'test-coupon-3': { name: 'TestCoupon3' }
|
|
|
}
|
|
|
this.recurlySubscription.ensureExists(error => {
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
+ SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
this.user,
|
|
|
(error, data) => {
|
|
|
this.data = data
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return done()
|
|
|
+ done()
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
@@ -122,7 +123,7 @@ describe('Subscriptions', function() {
|
|
|
expect(subscription).to.exist
|
|
|
expect(subscription.planCode).to.equal('collaborator')
|
|
|
expect(subscription.recurly).to.exist
|
|
|
- return expect(subscription.recurly).to.deep.equal({
|
|
|
+ expect(subscription.recurly).to.deep.equal({
|
|
|
activeCoupons: [],
|
|
|
billingDetailsLink:
|
|
|
'https://test.recurly.com/account/billing_info/edit?ht=mock-login-token',
|
|
|
@@ -137,7 +138,7 @@ describe('Subscriptions', function() {
|
|
|
trial_ends_at: new Date(2018, 6, 7),
|
|
|
trialEndsAtFormatted: '7th July 2018',
|
|
|
account: {
|
|
|
- account_code: this.user._id,
|
|
|
+ account_code: this.user._id.toString(),
|
|
|
email: 'mock@email.com',
|
|
|
hosted_login_token: 'mock-login-token'
|
|
|
},
|
|
|
@@ -147,7 +148,7 @@ describe('Subscriptions', function() {
|
|
|
})
|
|
|
|
|
|
it('should return no memberGroupSubscriptions', function() {
|
|
|
- return expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
+ expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
})
|
|
|
|
|
|
it('should include redeemed coupons', function(done) {
|
|
|
@@ -158,7 +159,7 @@ describe('Subscriptions', function() {
|
|
|
]
|
|
|
|
|
|
// rebuild the view model with the redemptions
|
|
|
- return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
+ SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
this.user,
|
|
|
(error, data) => {
|
|
|
expect(error).to.not.exist
|
|
|
@@ -176,7 +177,7 @@ describe('Subscriptions', function() {
|
|
|
description: ''
|
|
|
}
|
|
|
])
|
|
|
- return done()
|
|
|
+ done()
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
@@ -197,17 +198,17 @@ describe('Subscriptions', function() {
|
|
|
planCode: 'collaborator'
|
|
|
},
|
|
|
error => {
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
+ SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
this.user,
|
|
|
(error, data) => {
|
|
|
this.data = data
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return done()
|
|
|
+ done()
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
@@ -227,61 +228,36 @@ describe('Subscriptions', function() {
|
|
|
const subscription = this.data.personalSubscription
|
|
|
expect(subscription).to.exist
|
|
|
expect(subscription.planCode).to.equal('collaborator')
|
|
|
- return expect(subscription.recurly).to.not.exist
|
|
|
+ expect(subscription.recurly).to.not.exist
|
|
|
})
|
|
|
|
|
|
it('should return no memberGroupSubscriptions', function() {
|
|
|
- return expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
+ expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when the user is a member of a group subscription', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.owner1 = new User()
|
|
|
- this.owner2 = new User()
|
|
|
- async.series(
|
|
|
- [
|
|
|
- cb => this.owner1.ensureUserExists(cb),
|
|
|
- cb => this.owner2.ensureUserExists(cb),
|
|
|
- cb =>
|
|
|
- Subscription.create(
|
|
|
- {
|
|
|
- admin_id: this.owner1._id,
|
|
|
- manager_ids: [this.owner1._id],
|
|
|
- planCode: 'collaborator',
|
|
|
- groupPlan: true,
|
|
|
- member_ids: [this.user._id]
|
|
|
- },
|
|
|
- cb
|
|
|
- ),
|
|
|
- cb =>
|
|
|
- Subscription.create(
|
|
|
- {
|
|
|
- admin_id: this.owner2._id,
|
|
|
- manager_ids: [this.owner2._id],
|
|
|
- planCode: 'collaborator',
|
|
|
- groupPlan: true,
|
|
|
- member_ids: [this.user._id]
|
|
|
- },
|
|
|
- cb
|
|
|
- )
|
|
|
- ],
|
|
|
- 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()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
+ beforeEach(async function() {
|
|
|
+ const userHelperOwner1 = await UserHelper.createUser()
|
|
|
+ const userHelperOwner2 = await UserHelper.createUser()
|
|
|
+ this.owner1 = userHelperOwner1.user
|
|
|
+ this.owner2 = userHelperOwner2.user
|
|
|
+
|
|
|
+ await Subscription.create({
|
|
|
+ admin_id: this.owner1._id,
|
|
|
+ manager_ids: [this.owner1._id],
|
|
|
+ planCode: 'collaborator',
|
|
|
+ groupPlan: true,
|
|
|
+ member_ids: [this.user._id]
|
|
|
+ })
|
|
|
+ await Subscription.create({
|
|
|
+ admin_id: this.owner2._id,
|
|
|
+ manager_ids: [this.owner2._id],
|
|
|
+ planCode: 'collaborator',
|
|
|
+ groupPlan: true,
|
|
|
+ member_ids: [this.user._id]
|
|
|
+ })
|
|
|
+ this.data = await buildUsersSubscriptionViewModelPromise(this.user._id)
|
|
|
})
|
|
|
|
|
|
after(function(done) {
|
|
|
@@ -290,10 +266,10 @@ describe('Subscriptions', function() {
|
|
|
admin_id: this.owner1._id
|
|
|
},
|
|
|
error => {
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return Subscription.deleteOne(
|
|
|
+ Subscription.deleteOne(
|
|
|
{
|
|
|
admin_id: this.owner2._id
|
|
|
},
|
|
|
@@ -304,7 +280,7 @@ describe('Subscriptions', function() {
|
|
|
})
|
|
|
|
|
|
it('should return no personalSubscription', function() {
|
|
|
- return expect(this.data.personalSubscription).to.equal(null)
|
|
|
+ expect(this.data.personalSubscription).to.equal(null)
|
|
|
})
|
|
|
|
|
|
it('should return the two memberGroupSubscriptions', function() {
|
|
|
@@ -312,48 +288,27 @@ describe('Subscriptions', function() {
|
|
|
expect(
|
|
|
// Mongoose populates the admin_id with the user
|
|
|
this.data.memberGroupSubscriptions[0].admin_id._id.toString()
|
|
|
- ).to.equal(this.owner1._id)
|
|
|
- return expect(
|
|
|
+ ).to.equal(this.owner1._id.toString())
|
|
|
+ expect(
|
|
|
this.data.memberGroupSubscriptions[1].admin_id._id.toString()
|
|
|
- ).to.equal(this.owner2._id)
|
|
|
+ ).to.equal(this.owner2._id.toString())
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when the user is a manager of a group subscription', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- this.owner1 = new User()
|
|
|
- this.owner2 = new User()
|
|
|
- async.series(
|
|
|
- [
|
|
|
- cb => this.owner1.ensureUserExists(cb),
|
|
|
- cb => this.owner2.ensureUserExists(cb),
|
|
|
- cb =>
|
|
|
- Subscription.create(
|
|
|
- {
|
|
|
- admin_id: this.owner1._id,
|
|
|
- manager_ids: [this.owner1._id, this.user._id],
|
|
|
- planCode: 'collaborator',
|
|
|
- groupPlan: true
|
|
|
- },
|
|
|
- cb
|
|
|
- )
|
|
|
- ],
|
|
|
- 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()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
+ beforeEach(async function() {
|
|
|
+ const userHelperOwner1 = await UserHelper.createUser()
|
|
|
+ const userHelperOwner2 = await UserHelper.createUser()
|
|
|
+ this.owner1 = userHelperOwner1.user
|
|
|
+ this.owner2 = userHelperOwner2.user
|
|
|
+
|
|
|
+ await Subscription.create({
|
|
|
+ admin_id: this.owner1._id,
|
|
|
+ manager_ids: [this.owner1._id, this.user._id],
|
|
|
+ planCode: 'collaborator',
|
|
|
+ groupPlan: true
|
|
|
+ })
|
|
|
+ this.data = await buildUsersSubscriptionViewModelPromise(this.user._id)
|
|
|
})
|
|
|
|
|
|
after(function(done) {
|
|
|
@@ -366,7 +321,7 @@ describe('Subscriptions', function() {
|
|
|
})
|
|
|
|
|
|
it('should return no personalSubscription', function() {
|
|
|
- return expect(this.data.personalSubscription).to.equal(null)
|
|
|
+ expect(this.data.personalSubscription).to.equal(null)
|
|
|
})
|
|
|
|
|
|
it('should return the managedGroupSubscriptions', function() {
|
|
|
@@ -375,8 +330,8 @@ describe('Subscriptions', function() {
|
|
|
expect(
|
|
|
// Mongoose populates the admin_id with the user
|
|
|
subscription.admin_id._id.toString()
|
|
|
- ).to.equal(this.owner1._id)
|
|
|
- return expect(subscription.groupPlan).to.equal(true)
|
|
|
+ ).to.equal(this.owner1._id.toString())
|
|
|
+ expect(subscription.groupPlan).to.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -386,7 +341,7 @@ describe('Subscriptions', function() {
|
|
|
async.series(
|
|
|
[
|
|
|
cb => {
|
|
|
- return Institution.create(
|
|
|
+ Institution.create(
|
|
|
{
|
|
|
v1Id: this.v1Id,
|
|
|
managerIds: [this.user._id]
|
|
|
@@ -396,17 +351,17 @@ describe('Subscriptions', function() {
|
|
|
}
|
|
|
],
|
|
|
error => {
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
+ SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
|
|
this.user,
|
|
|
(error, data) => {
|
|
|
this.data = data
|
|
|
- if (error != null) {
|
|
|
+ if (error) {
|
|
|
return done(error)
|
|
|
}
|
|
|
- return done()
|
|
|
+ done()
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
@@ -426,119 +381,67 @@ describe('Subscriptions', function() {
|
|
|
expect(this.data.managedInstitutions.length).to.equal(1)
|
|
|
const institution = this.data.managedInstitutions[0]
|
|
|
expect(institution.v1Id).to.equal(this.v1Id)
|
|
|
- return expect(institution.name).to.equal(`Institution ${this.v1Id}`)
|
|
|
+ expect(institution.name).to.equal(`Institution ${this.v1Id}`)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when the user is a member of an affiliation', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ beforeEach(async function() {
|
|
|
const v1Id = MockV1Api.nextV1Id()
|
|
|
MockV1Api.setUser(v1Id, {
|
|
|
subscription: {},
|
|
|
subscription_status: {}
|
|
|
})
|
|
|
- MockV1Api.setAffiliations(this.user._id, [
|
|
|
- {
|
|
|
- email: 'confirmed-affiliation-email@stanford.example.edu',
|
|
|
- licence: 'pro_plus',
|
|
|
- department: 'Math',
|
|
|
- role: 'Prof',
|
|
|
- inferred: false,
|
|
|
- institution: {
|
|
|
- name: 'Stanford',
|
|
|
- confirmed: true
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- email: 'unconfirmed-affiliation-email@harvard.example.edu',
|
|
|
- licence: 'pro_plus',
|
|
|
- institution: {
|
|
|
- name: 'Harvard',
|
|
|
- confirmed: true
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- email: 'confirmed-affiliation-email@mit.example.edu',
|
|
|
- licence: 'pro_plus',
|
|
|
- institution: { name: 'MIT', confirmed: false }
|
|
|
- }
|
|
|
- ])
|
|
|
- return async.series(
|
|
|
- [
|
|
|
- cb => {
|
|
|
- return this.user.setV1Id(v1Id, cb)
|
|
|
- },
|
|
|
- cb => {
|
|
|
- return this.user.addEmail(
|
|
|
- 'unconfirmed-affiliation-email@harvard.example.edu',
|
|
|
- cb
|
|
|
- )
|
|
|
- },
|
|
|
- cb => {
|
|
|
- return this.user.addEmail(
|
|
|
- 'confirmed-affiliation-email@stanford.example.edu',
|
|
|
- cb
|
|
|
- )
|
|
|
- },
|
|
|
- cb => {
|
|
|
- return this.user.confirmEmail(
|
|
|
- 'confirmed-affiliation-email@stanford.example.edu',
|
|
|
- cb
|
|
|
- )
|
|
|
- },
|
|
|
- cb => {
|
|
|
- return this.user.addEmail(
|
|
|
- 'confirmed-affiliation-email@mit.example.edu',
|
|
|
- cb
|
|
|
- )
|
|
|
- },
|
|
|
- cb => {
|
|
|
- return this.user.confirmEmail(
|
|
|
- 'confirmed-affiliation-email@mit.example.edu',
|
|
|
- cb
|
|
|
- )
|
|
|
- }
|
|
|
- ],
|
|
|
- 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()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ await UserHelper.updateUser(this.user._id, {
|
|
|
+ $set: { overleaf: { id: v1Id } }
|
|
|
+ })
|
|
|
+
|
|
|
+ const harvardDomain = 'harvard.example.edu'
|
|
|
+ const mitDomain = 'mit.example.edu'
|
|
|
+ const stanfordDomain = 'stanford.example.edu'
|
|
|
+ const harvardId = MockV1Api.createInstitution({
|
|
|
+ name: 'Harvard',
|
|
|
+ hostname: harvardDomain
|
|
|
+ })
|
|
|
+ const mitId = MockV1Api.createInstitution({
|
|
|
+ name: 'MIT',
|
|
|
+ hostname: mitDomain
|
|
|
+ })
|
|
|
+ const stanfordId = MockV1Api.createInstitution({
|
|
|
+ name: 'Stanford',
|
|
|
+ hostname: stanfordDomain
|
|
|
+ })
|
|
|
+ MockV1Api.updateInstitutionDomain(harvardId, harvardDomain, {
|
|
|
+ confirmed: true
|
|
|
+ })
|
|
|
+ MockV1Api.updateInstitutionDomain(mitId, mitDomain, {
|
|
|
+ confirmed: false
|
|
|
+ })
|
|
|
+ MockV1Api.updateInstitutionDomain(stanfordId, stanfordDomain, {
|
|
|
+ confirmed: true
|
|
|
+ })
|
|
|
+ this.harvardEmail = `unconfirmed-affiliation-email@${harvardDomain}`
|
|
|
+ this.stanfordEmail = `confirmed-affiliation-email@${stanfordDomain}`
|
|
|
+ const mitEmail = `confirmed-affiliation-email@${mitDomain}`
|
|
|
+ userHelper = await UserHelper.loginUser(
|
|
|
+ userHelper.getDefaultEmailPassword()
|
|
|
)
|
|
|
+ await userHelper.addEmail(this.harvardEmail)
|
|
|
+ await userHelper.addEmailAndConfirm(this.user._id, this.stanfordEmail)
|
|
|
+ await userHelper.addEmailAndConfirm(this.user._id, mitEmail)
|
|
|
+ this.data = await buildUsersSubscriptionViewModelPromise(this.user._id)
|
|
|
})
|
|
|
|
|
|
it('should return only the affilations with confirmed institutions, and confirmed emails', function() {
|
|
|
- return expect(this.data.confirmedMemberAffiliations).to.deep.equal([
|
|
|
- {
|
|
|
- licence: 'pro_plus',
|
|
|
- department: 'Math',
|
|
|
- role: 'Prof',
|
|
|
- inferred: false,
|
|
|
- inReconfirmNotificationPeriod: false,
|
|
|
- institution: {
|
|
|
- name: 'Stanford',
|
|
|
- confirmed: true
|
|
|
- },
|
|
|
- lastDayToReconfirm: undefined,
|
|
|
- pastReconfirmDate: false,
|
|
|
- portal: undefined
|
|
|
- }
|
|
|
- ])
|
|
|
+ expect(this.data.confirmedMemberAffiliations.length).to.equal(1)
|
|
|
+ expect(
|
|
|
+ this.data.confirmedMemberAffiliations[0].institution.name
|
|
|
+ ).to.equal('Stanford')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when the user has a v1 subscription', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
+ beforeEach(async function() {
|
|
|
let v1Id
|
|
|
MockV1Api.setUser((v1Id = MockV1Api.nextV1Id()), {
|
|
|
subscription: (this.subscription = {
|
|
|
@@ -556,33 +459,26 @@ describe('Subscriptions', function() {
|
|
|
team: null
|
|
|
})
|
|
|
})
|
|
|
- return this.user.setV1Id(v1Id, 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()
|
|
|
+ await UserHelper.updateUser(this.user._id, {
|
|
|
+ $set: {
|
|
|
+ overleaf: {
|
|
|
+ id: v1Id
|
|
|
}
|
|
|
- )
|
|
|
+ }
|
|
|
})
|
|
|
+ this.data = await buildUsersSubscriptionViewModelPromise(this.user._id)
|
|
|
})
|
|
|
|
|
|
it('should return no personalSubscription', function() {
|
|
|
- return expect(this.data.personalSubscription).to.equal(null)
|
|
|
+ expect(this.data.personalSubscription).to.equal(null)
|
|
|
})
|
|
|
|
|
|
it('should return no memberGroupSubscriptions', function() {
|
|
|
- return expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
+ expect(this.data.memberGroupSubscriptions).to.deep.equal([])
|
|
|
})
|
|
|
|
|
|
it('should return a v1SubscriptionStatus', function() {
|
|
|
- return expect(this.data.v1SubscriptionStatus).to.deep.equal(
|
|
|
+ expect(this.data.v1SubscriptionStatus).to.deep.equal(
|
|
|
this.subscription_status
|
|
|
)
|
|
|
})
|
|
|
@@ -590,39 +486,32 @@ describe('Subscriptions', function() {
|
|
|
})
|
|
|
|
|
|
describe('canceling', function() {
|
|
|
- beforeEach(function(done) {
|
|
|
- let v1Id
|
|
|
- this.user = new User()
|
|
|
- MockV1Api.setUser((v1Id = MockV1Api.nextV1Id()), (this.v1_user = {}))
|
|
|
- return async.series(
|
|
|
- [cb => this.user.login(cb), cb => this.user.setV1Id(v1Id, cb)],
|
|
|
- error => {
|
|
|
- return this.user.request(
|
|
|
- {
|
|
|
- method: 'POST',
|
|
|
- url: '/user/subscription/v1/cancel'
|
|
|
- },
|
|
|
- (error, response) => {
|
|
|
- this.response = response
|
|
|
- if (error != null) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ let userHelper, v1Id
|
|
|
+ beforeEach(async function() {
|
|
|
+ v1Id = MockV1Api.nextV1Id()
|
|
|
+ console.log('v1Id=', v1Id)
|
|
|
+ userHelper = await UserHelper.createUser({ overleaf: { id: v1Id } })
|
|
|
+ this.user = userHelper.user
|
|
|
+ MockV1Api.setUser(v1Id, (this.v1_user = {}))
|
|
|
+
|
|
|
+ userHelper = await UserHelper.loginUser(
|
|
|
+ userHelper.getDefaultEmailPassword()
|
|
|
+ )
|
|
|
+ this.response = await userHelper.request.post(
|
|
|
+ '/user/subscription/v1/cancel',
|
|
|
+ {
|
|
|
+ simple: false
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should tell v1 to cancel the subscription', function() {
|
|
|
- return expect(this.v1_user.canceled).to.equal(true)
|
|
|
+ expect(this.v1_user.canceled).to.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should redirect to the subscription dashboard', function() {
|
|
|
expect(this.response.statusCode).to.equal(302)
|
|
|
- return expect(this.response.headers.location).to.equal(
|
|
|
- '/user/subscription'
|
|
|
- )
|
|
|
+ expect(this.response.headers.location).to.equal('/user/subscription')
|
|
|
})
|
|
|
})
|
|
|
})
|