Merge pull request #18188 from overleaf/jel-react-group-invite
[web] Migrate team invite to React GitOrigin-RevId: 32e968c3b512020aef9a396808c73a7b4859e6d1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Subscription/TeamInvitesController'
|
||||
|
||||
@@ -26,19 +27,30 @@ describe('TeamInvitesController', function () {
|
||||
}
|
||||
|
||||
this.TeamInvitesHandler = {
|
||||
promises: { acceptInvite: sinon.stub().resolves(this.subscription) },
|
||||
promises: {
|
||||
acceptInvite: sinon.stub().resolves(this.subscription),
|
||||
getInvite: sinon.stub().resolves({
|
||||
invite: {
|
||||
email: this.user.email,
|
||||
token: 'token123',
|
||||
inviterName: this.user_email,
|
||||
},
|
||||
subscription: this.subscription,
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
this.SubscriptionLocator = {
|
||||
promises: {
|
||||
hasSSOEnabled: sinon.stub().resolves(true),
|
||||
getUsersSubscription: sinon.stub().resolves(),
|
||||
},
|
||||
}
|
||||
this.ErrorController = { notFound: sinon.stub() }
|
||||
|
||||
this.SessionManager = {
|
||||
getLoggedInUserId(session) {
|
||||
return session.user._id
|
||||
return session.user?._id
|
||||
},
|
||||
getSessionUser(session) {
|
||||
return session.user
|
||||
@@ -75,6 +87,18 @@ describe('TeamInvitesController', function () {
|
||||
'../User/UserGetter': this.UserGetter,
|
||||
'../Email/EmailHandler': this.EmailHandler,
|
||||
'../../infrastructure/RateLimiter': this.RateLimiter,
|
||||
'../../infrastructure/Modules': (this.Modules = {
|
||||
promises: {
|
||||
hooks: {
|
||||
fire: sinon.stub().resolves([]),
|
||||
},
|
||||
},
|
||||
}),
|
||||
'../SplitTests/SplitTestHandler': (this.SplitTestHandler = {
|
||||
promises: {
|
||||
getAssignment: sinon.stub().resolves({}),
|
||||
},
|
||||
}),
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -99,4 +123,126 @@ describe('TeamInvitesController', function () {
|
||||
this.Controller.acceptInvite(this.req, res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('viewInvite', function () {
|
||||
const req = {
|
||||
params: { token: 'token123' },
|
||||
query: {},
|
||||
session: {
|
||||
user: { _id: 'user123' },
|
||||
},
|
||||
}
|
||||
|
||||
describe('hasIndividualRecurlySubscription', function () {
|
||||
it('is true for personal subscription', function (done) {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.resolves({
|
||||
recurlySubscription_id: 'subscription123',
|
||||
groupPlan: false,
|
||||
})
|
||||
const res = {
|
||||
render: (template, data) => {
|
||||
expect(data.hasIndividualRecurlySubscription).to.be.true
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(req, res)
|
||||
})
|
||||
|
||||
it('is true for group subscriptions', function (done) {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.resolves({
|
||||
recurlySubscription_id: 'subscription123',
|
||||
groupPlan: true,
|
||||
})
|
||||
const res = {
|
||||
render: (template, data) => {
|
||||
expect(data.hasIndividualRecurlySubscription).to.be.false
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(req, res)
|
||||
})
|
||||
|
||||
it('is false for canceled subscriptions', function (done) {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.resolves({
|
||||
recurlySubscription_id: 'subscription123',
|
||||
groupPlan: false,
|
||||
recurlyStatus: {
|
||||
state: 'canceled',
|
||||
},
|
||||
})
|
||||
const res = {
|
||||
render: (template, data) => {
|
||||
expect(data.hasIndividualRecurlySubscription).to.be.false
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(req, res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when user is logged out', function () {
|
||||
it('renders logged out invite page', function (done) {
|
||||
const res = {
|
||||
render: template => {
|
||||
expect(template).to.equal('subscriptions/team/invite_logged_out')
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(
|
||||
{ params: { token: 'token123' }, session: {} },
|
||||
res
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Feature rollout of React migration', function () {
|
||||
describe('feature rollout is not active', function () {
|
||||
it('renders old Angular template', function (done) {
|
||||
const res = {
|
||||
render: template => {
|
||||
expect(template).to.equal('subscriptions/team/invite')
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(req, res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('user is on default variant', function () {
|
||||
beforeEach(function () {
|
||||
this.SplitTestHandler.promises.getAssignment.resolves({
|
||||
variant: 'default',
|
||||
})
|
||||
})
|
||||
|
||||
it('renders old Angular template', function (done) {
|
||||
const res = {
|
||||
render: template => {
|
||||
expect(template).to.equal('subscriptions/team/invite')
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(req, res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('user is on enabled variant', function () {
|
||||
beforeEach(function () {
|
||||
this.SplitTestHandler.promises.getAssignment.resolves({
|
||||
variant: 'enabled',
|
||||
})
|
||||
})
|
||||
|
||||
it('renders React template', function (done) {
|
||||
const res = {
|
||||
render: template => {
|
||||
expect(template).to.equal('subscriptions/team/invite-react')
|
||||
done()
|
||||
},
|
||||
}
|
||||
this.Controller.viewInvite(req, res)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user