SubscriptionControllerTests.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. const SandboxedModule = require('sandboxed-module')
  2. const sinon = require('sinon')
  3. const { assert, expect } = require('chai')
  4. const MockRequest = require('../helpers/MockRequest')
  5. const MockResponse = require('../helpers/MockResponse')
  6. const modulePath =
  7. '../../../../app/src/Features/Subscription/SubscriptionController'
  8. const SubscriptionErrors = require('../../../../app/src/Features/Subscription/Errors')
  9. const mockSubscriptions = {
  10. 'subscription-123-active': {
  11. uuid: 'subscription-123-active',
  12. plan: {
  13. name: 'Gold',
  14. plan_code: 'gold',
  15. },
  16. current_period_ends_at: new Date(),
  17. state: 'active',
  18. unit_amount_in_cents: 999,
  19. account: {
  20. account_code: 'user-123',
  21. },
  22. },
  23. }
  24. describe('SubscriptionController', function () {
  25. beforeEach(function () {
  26. this.user = {
  27. email: 'tom@yahoo.com',
  28. _id: 'one',
  29. signUpDate: new Date('2000-10-01'),
  30. emails: [{ email: 'tom@yahoo.com', confirmedAt: new Date('2000-10-02') }],
  31. }
  32. this.activeRecurlySubscription =
  33. mockSubscriptions['subscription-123-active']
  34. this.SessionManager = {
  35. getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),
  36. getLoggedInUserId: sinon.stub().returns(this.user._id),
  37. getSessionUser: sinon.stub().returns(this.user),
  38. isUserLoggedIn: sinon.stub().returns(true),
  39. }
  40. this.SubscriptionHandler = {
  41. createSubscription: sinon.stub().callsArgWith(3),
  42. updateSubscription: sinon.stub().callsArgWith(3),
  43. reactivateSubscription: sinon.stub().callsArgWith(1),
  44. cancelSubscription: sinon.stub().callsArgWith(1),
  45. syncSubscription: sinon.stub().yields(),
  46. attemptPaypalInvoiceCollection: sinon.stub().yields(),
  47. startFreeTrial: sinon.stub(),
  48. promises: {
  49. createSubscription: sinon.stub().resolves(),
  50. updateSubscription: sinon.stub().resolves(),
  51. reactivateSubscription: sinon.stub().resolves(),
  52. cancelSubscription: sinon.stub().resolves(),
  53. syncSubscription: sinon.stub().resolves(),
  54. attemptPaypalInvoiceCollection: sinon.stub().resolves(),
  55. startFreeTrial: sinon.stub().resolves(),
  56. },
  57. }
  58. this.PlansLocator = { findLocalPlanInSettings: sinon.stub() }
  59. this.LimitationsManager = {
  60. hasPaidSubscription: sinon.stub(),
  61. userHasV1OrV2Subscription: sinon.stub(),
  62. userHasV2Subscription: sinon.stub(),
  63. promises: {
  64. hasPaidSubscription: sinon.stub().resolves(),
  65. userHasV1OrV2Subscription: sinon.stub().resolves(),
  66. userHasV2Subscription: sinon.stub().resolves(),
  67. },
  68. }
  69. this.SubscriptionViewModelBuilder = {
  70. buildUsersSubscriptionViewModel: sinon.stub().callsArgWith(1, null, {}),
  71. buildPlansList: sinon.stub(),
  72. promises: {
  73. buildUsersSubscriptionViewModel: sinon.stub().resolves({}),
  74. getBestSubscription: sinon.stub().resolves({}),
  75. },
  76. buildPlansListForSubscriptionDash: sinon
  77. .stub()
  78. .returns({ plans: [], planCodesChangingAtTermEnd: [] }),
  79. }
  80. this.settings = {
  81. coupon_codes: {
  82. upgradeToAnnualPromo: {
  83. student: 'STUDENTCODEHERE',
  84. collaborator: 'COLLABORATORCODEHERE',
  85. },
  86. },
  87. groupPlanModalOptions: {
  88. plan_codes: [],
  89. currencies: [
  90. {
  91. display: 'GBP (£)',
  92. code: 'GBP',
  93. },
  94. ],
  95. sizes: ['42'],
  96. usages: [{ code: 'foo', display: 'Foo' }],
  97. },
  98. apis: {
  99. recurly: {
  100. subdomain: 'sl',
  101. },
  102. },
  103. siteUrl: 'http://de.overleaf.dev:3000',
  104. }
  105. this.AuthorizationManager = {
  106. promises: {
  107. isUserSiteAdmin: sinon.stub().resolves(false),
  108. },
  109. }
  110. this.GeoIpLookup = {
  111. isValidCurrencyParam: sinon.stub().returns(true),
  112. getCurrencyCode: sinon.stub().yields('USD', 'US'),
  113. promises: {
  114. getCurrencyCode: sinon.stub().resolves({
  115. countryCode: 'US',
  116. currencyCode: 'USD',
  117. }),
  118. },
  119. }
  120. this.UserGetter = {
  121. getUser: sinon.stub().callsArgWith(2, null, this.user),
  122. promises: {
  123. getUser: sinon.stub().resolves(this.user),
  124. },
  125. }
  126. this.SplitTestV2Hander = {
  127. promises: {
  128. getAssignment: sinon.stub().resolves({ variant: 'default' }),
  129. },
  130. }
  131. this.SubscriptionHelper = {
  132. generateInitialLocalizedGroupPrice: sinon.stub(),
  133. }
  134. this.Features = {
  135. hasFeature: sinon.stub().returns(false),
  136. }
  137. this.SubscriptionController = SandboxedModule.require(modulePath, {
  138. requires: {
  139. '../Authorization/AuthorizationManager': this.AuthorizationManager,
  140. '../SplitTests/SplitTestHandler': this.SplitTestV2Hander,
  141. '../Authentication/SessionManager': this.SessionManager,
  142. './SubscriptionHandler': this.SubscriptionHandler,
  143. './SubscriptionHelper': this.SubscriptionHelper,
  144. './PlansLocator': this.PlansLocator,
  145. './SubscriptionViewModelBuilder': this.SubscriptionViewModelBuilder,
  146. './LimitationsManager': this.LimitationsManager,
  147. '../../infrastructure/GeoIpLookup': this.GeoIpLookup,
  148. '@overleaf/settings': this.settings,
  149. '../User/UserGetter': this.UserGetter,
  150. './RecurlyWrapper': (this.RecurlyWrapper = {
  151. updateAccountEmailAddress: sinon.stub().yields(),
  152. }),
  153. './RecurlyEventHandler': {
  154. sendRecurlyAnalyticsEvent: sinon.stub().resolves(),
  155. },
  156. './FeaturesUpdater': (this.FeaturesUpdater = {}),
  157. './GroupPlansData': (this.GroupPlansData = {}),
  158. './V1SubscriptionManager': (this.V1SubscriptionManager = {}),
  159. '../Errors/HttpErrorHandler': (this.HttpErrorHandler = {
  160. unprocessableEntity: sinon.stub().callsFake((req, res, message) => {
  161. res.status(422)
  162. res.json({ message })
  163. }),
  164. }),
  165. './Errors': SubscriptionErrors,
  166. '../Analytics/AnalyticsManager': (this.AnalyticsManager = {
  167. recordEventForUser: sinon.stub(),
  168. recordEventForSession: sinon.stub(),
  169. setUserPropertyForUser: sinon.stub(),
  170. }),
  171. '../../infrastructure/Features': this.Features,
  172. },
  173. })
  174. this.res = new MockResponse()
  175. this.req = new MockRequest()
  176. this.req.body = {}
  177. this.req.query = { planCode: '123123' }
  178. this.stubbedCurrencyCode = 'GBP'
  179. })
  180. describe('plansPage', function () {
  181. beforeEach(function () {
  182. this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
  183. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  184. currencyCode: this.stubbedCurrencyCode,
  185. })
  186. })
  187. describe('ip override', function () {
  188. beforeEach(function () {
  189. this.req.ip = '1.2.3.4'
  190. this.req.query = { ip: '5.6.7.8' }
  191. this.GeoIpLookup.promises.getCurrencyCode.withArgs('1.2.3.4').resolves({
  192. currencyCode: 'GBP',
  193. })
  194. this.GeoIpLookup.promises.getCurrencyCode.withArgs('5.6.7.8').resolves({
  195. currencyCode: 'USD',
  196. })
  197. })
  198. it('should ignore override for non admin', function (done) {
  199. this.res.render = (page, opts) => {
  200. opts.recommendedCurrency.should.equal('GBP')
  201. done()
  202. }
  203. this.AuthorizationManager.promises.isUserSiteAdmin.resolves(false)
  204. this.SubscriptionController.plansPage(this.req, this.res)
  205. })
  206. it('should accept override for admin', function (done) {
  207. this.res.render = (page, opts) => {
  208. opts.recommendedCurrency.should.equal('USD')
  209. done()
  210. }
  211. this.AuthorizationManager.promises.isUserSiteAdmin.resolves(true)
  212. this.SubscriptionController.plansPage(this.req, this.res)
  213. })
  214. })
  215. describe('groupPlanModal data', function () {
  216. it('should pass local currency if valid', function (done) {
  217. this.res.render = (page, opts) => {
  218. page.should.equal('subscriptions/plans')
  219. opts.groupPlanModalDefaults.currency.should.equal('GBP')
  220. done()
  221. }
  222. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  223. currencyCode: 'GBP',
  224. })
  225. this.SubscriptionController.plansPage(this.req, this.res)
  226. })
  227. it('should fallback to USD when valid', function (done) {
  228. this.res.render = (page, opts) => {
  229. page.should.equal('subscriptions/plans')
  230. opts.groupPlanModalDefaults.currency.should.equal('USD')
  231. done()
  232. }
  233. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  234. currencyCode: 'FOO',
  235. })
  236. this.SubscriptionController.plansPage(this.req, this.res)
  237. })
  238. it('should pass valid options for group plan modal and discard invalid', function (done) {
  239. this.res.render = (page, opts) => {
  240. page.should.equal('subscriptions/plans')
  241. opts.groupPlanModalDefaults.size.should.equal('42')
  242. opts.groupPlanModalDefaults.plan_code.should.equal('collaborator')
  243. opts.groupPlanModalDefaults.currency.should.equal('GBP')
  244. opts.groupPlanModalDefaults.usage.should.equal('foo')
  245. done()
  246. }
  247. this.GeoIpLookup.isValidCurrencyParam.returns(false)
  248. this.req.query = {
  249. number: '42',
  250. currency: 'ABC',
  251. plan: 'does-not-exist',
  252. usage: 'foo',
  253. }
  254. this.SubscriptionController.plansPage(this.req, this.res)
  255. })
  256. })
  257. describe('showInrGeoBanner data', function () {
  258. it('should return true for Indian Users', function (done) {
  259. this.res.render = (page, opts) => {
  260. page.should.equal('subscriptions/plans')
  261. opts.showInrGeoBanner.should.equal(true)
  262. done()
  263. }
  264. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  265. countryCode: 'IN',
  266. })
  267. this.SubscriptionController.plansPage(this.req, this.res)
  268. })
  269. })
  270. })
  271. describe('interstitialPaymentPage', function () {
  272. beforeEach(function () {
  273. this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
  274. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  275. currencyCode: this.stubbedCurrencyCode,
  276. })
  277. })
  278. describe('with a user without subscription', function () {
  279. it('should render the interstitial payment page', function (done) {
  280. this.res.render = (page, opts) => {
  281. page.should.equal('subscriptions/interstitial-payment')
  282. done()
  283. }
  284. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  285. })
  286. })
  287. describe('with a user with subscription', function () {
  288. it('should redirect to the subscription dashboard', function (done) {
  289. this.PlansLocator.findLocalPlanInSettings.returns({})
  290. this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(
  291. true
  292. )
  293. this.res.redirect = url => {
  294. url.should.equal('/user/subscription?hasSubscription=true')
  295. done()
  296. }
  297. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  298. })
  299. })
  300. describe('showInrGeoBanner data', function () {
  301. it('should return true for Indian users', function (done) {
  302. this.res.render = (page, opts) => {
  303. page.should.equal('subscriptions/interstitial-payment')
  304. opts.showInrGeoBanner.should.equal(true)
  305. done()
  306. }
  307. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  308. countryCode: 'IN',
  309. })
  310. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  311. })
  312. })
  313. })
  314. describe('successfulSubscription', function () {
  315. it('without a personal subscription', function (done) {
  316. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  317. {}
  318. )
  319. this.res.redirect = url => {
  320. url.should.equal('/user/subscription/plans')
  321. done()
  322. }
  323. this.SubscriptionController.successfulSubscription(this.req, this.res)
  324. })
  325. it('with a personal subscription', function (done) {
  326. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  327. {
  328. personalSubscription: 'foo',
  329. }
  330. )
  331. this.res.render = (url, variables) => {
  332. url.should.equal('subscriptions/successful-subscription-react')
  333. assert.deepEqual(variables, {
  334. title: 'thank_you',
  335. personalSubscription: 'foo',
  336. postCheckoutRedirect: undefined,
  337. })
  338. done()
  339. }
  340. this.SubscriptionController.successfulSubscription(this.req, this.res)
  341. })
  342. it('with an error', function (done) {
  343. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  344. undefined
  345. )
  346. this.SubscriptionController.successfulSubscription(
  347. this.req,
  348. this.res,
  349. error => {
  350. assert.isNotNull(error)
  351. done()
  352. }
  353. )
  354. })
  355. })
  356. describe('userSubscriptionPage', function () {
  357. beforeEach(function (done) {
  358. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  359. {
  360. personalSubscription: (this.personalSubscription = {
  361. 'personal-subscription': 'mock',
  362. }),
  363. memberGroupSubscriptions: (this.memberGroupSubscriptions = {
  364. 'group-subscriptions': 'mock',
  365. }),
  366. }
  367. )
  368. this.SubscriptionViewModelBuilder.buildPlansList.returns(
  369. (this.plans = { plans: 'mock' })
  370. )
  371. this.SubscriptionViewModelBuilder.buildPlansListForSubscriptionDash.returns(
  372. {
  373. plans: this.plans,
  374. planCodesChangingAtTermEnd: [],
  375. }
  376. )
  377. this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
  378. this.res.render = (view, data) => {
  379. this.data = data
  380. expect(view).to.equal('subscriptions/dashboard-react')
  381. done()
  382. }
  383. this.SubscriptionController.userSubscriptionPage(this.req, this.res, done)
  384. })
  385. it('should load the personal, groups and v1 subscriptions', function () {
  386. expect(this.data.personalSubscription).to.deep.equal(
  387. this.personalSubscription
  388. )
  389. expect(this.data.memberGroupSubscriptions).to.deep.equal(
  390. this.memberGroupSubscriptions
  391. )
  392. })
  393. it('should load the user', function () {
  394. expect(this.data.user).to.deep.equal(this.user)
  395. })
  396. it('should load the plans', function () {
  397. expect(this.data.plans).to.deep.equal(this.plans)
  398. })
  399. it('should load an empty list of groups with settings available', function () {
  400. expect(this.data.groupSettingsEnabledFor).to.deep.equal([])
  401. })
  402. })
  403. describe('updateSubscription via post', function () {
  404. beforeEach(function (done) {
  405. this.res = {
  406. redirect() {
  407. done()
  408. },
  409. }
  410. sinon.spy(this.res, 'redirect')
  411. this.plan_code = '1234'
  412. this.req.body.plan_code = this.plan_code
  413. this.SubscriptionController.updateSubscription(this.req, this.res)
  414. })
  415. it('should send the user and subscriptionId to the handler', function (done) {
  416. this.SubscriptionHandler.updateSubscription
  417. .calledWith(this.user, this.plan_code)
  418. .should.equal(true)
  419. done()
  420. })
  421. it('should redurect to the subscription page', function (done) {
  422. this.res.redirect.calledWith('/user/subscription').should.equal(true)
  423. done()
  424. })
  425. })
  426. describe('updateAccountEmailAddress via put', function () {
  427. it('should send the user and subscriptionId to RecurlyWrapper', function () {
  428. this.res.sendStatus = sinon.spy()
  429. this.SubscriptionController.updateAccountEmailAddress(this.req, this.res)
  430. this.RecurlyWrapper.updateAccountEmailAddress
  431. .calledWith(this.user._id, this.user.email)
  432. .should.equal(true)
  433. })
  434. it('should respond with 200', function () {
  435. this.res.sendStatus = sinon.spy()
  436. this.SubscriptionController.updateAccountEmailAddress(this.req, this.res)
  437. this.res.sendStatus.calledWith(200).should.equal(true)
  438. })
  439. it('should send the error to the next handler when updating recurly account email fails', function (done) {
  440. this.RecurlyWrapper.updateAccountEmailAddress.yields(new Error())
  441. this.next = sinon.spy(error => {
  442. expect(error).instanceOf(Error)
  443. done()
  444. })
  445. this.SubscriptionController.updateAccountEmailAddress(
  446. this.req,
  447. this.res,
  448. this.next
  449. )
  450. })
  451. })
  452. describe('reactivateSubscription', function () {
  453. describe('when the user has permission', function () {
  454. beforeEach(function (done) {
  455. this.res = {
  456. redirect() {
  457. done()
  458. },
  459. }
  460. this.req.assertPermission = sinon.stub()
  461. this.next = sinon.stub().callsFake(error => {
  462. done(error)
  463. })
  464. sinon.spy(this.res, 'redirect')
  465. this.SubscriptionController.reactivateSubscription(
  466. this.req,
  467. this.res,
  468. this.next
  469. )
  470. })
  471. it('should assert the user has permission to reactivate their subscription', function (done) {
  472. this.req.assertPermission
  473. .calledWith('reactivate-subscription')
  474. .should.equal(true)
  475. done()
  476. })
  477. it('should tell the handler to reactivate this user', function (done) {
  478. this.SubscriptionHandler.reactivateSubscription
  479. .calledWith(this.user)
  480. .should.equal(true)
  481. done()
  482. })
  483. it('should redurect to the subscription page', function (done) {
  484. this.res.redirect.calledWith('/user/subscription').should.equal(true)
  485. done()
  486. })
  487. })
  488. describe('when the user does not have permission', function () {
  489. beforeEach(function (done) {
  490. this.res = {
  491. redirect() {
  492. done()
  493. },
  494. }
  495. this.req.assertPermission = sinon.stub().throws()
  496. this.next = sinon.stub().callsFake(() => {
  497. done()
  498. })
  499. sinon.spy(this.res, 'redirect')
  500. this.SubscriptionController.reactivateSubscription(
  501. this.req,
  502. this.res,
  503. this.next
  504. )
  505. })
  506. it('should not reactivate the user', function (done) {
  507. this.req.assertPermission = sinon.stub().throws()
  508. this.SubscriptionHandler.reactivateSubscription.called.should.equal(
  509. false
  510. )
  511. done()
  512. })
  513. it('should call next with an error', function (done) {
  514. this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
  515. done()
  516. })
  517. })
  518. })
  519. describe('cancelSubscription', function () {
  520. beforeEach(function (done) {
  521. this.res = {
  522. redirect() {
  523. done()
  524. },
  525. }
  526. sinon.spy(this.res, 'redirect')
  527. this.SubscriptionController.cancelSubscription(this.req, this.res)
  528. })
  529. it('should tell the handler to cancel this user', function (done) {
  530. this.SubscriptionHandler.cancelSubscription
  531. .calledWith(this.user)
  532. .should.equal(true)
  533. done()
  534. })
  535. it('should redurect to the subscription page', function (done) {
  536. this.res.redirect
  537. .calledWith('/user/subscription/canceled')
  538. .should.equal(true)
  539. done()
  540. })
  541. })
  542. describe('recurly callback', function () {
  543. describe('with a sync subscription request', function () {
  544. beforeEach(function (done) {
  545. this.req = {
  546. body: {
  547. expired_subscription_notification: {
  548. account: {
  549. account_code: this.user._id,
  550. },
  551. subscription: {
  552. uuid: this.activeRecurlySubscription.uuid,
  553. plan: {
  554. plan_code: 'collaborator',
  555. state: 'active',
  556. },
  557. },
  558. },
  559. },
  560. }
  561. this.res = {
  562. sendStatus() {
  563. done()
  564. },
  565. }
  566. sinon.spy(this.res, 'sendStatus')
  567. this.SubscriptionController.recurlyCallback(this.req, this.res)
  568. })
  569. it('should tell the SubscriptionHandler to process the recurly callback', function (done) {
  570. this.SubscriptionHandler.syncSubscription.called.should.equal(true)
  571. done()
  572. })
  573. it('should send a 200', function (done) {
  574. this.res.sendStatus.calledWith(200)
  575. done()
  576. })
  577. })
  578. describe('with a billing info updated request', function () {
  579. beforeEach(function (done) {
  580. this.req = {
  581. body: {
  582. billing_info_updated_notification: {
  583. account: {
  584. account_code: 'mock-account-code',
  585. },
  586. },
  587. },
  588. }
  589. this.res = {
  590. sendStatus() {
  591. done()
  592. },
  593. }
  594. sinon.spy(this.res, 'sendStatus')
  595. this.SubscriptionController.recurlyCallback(this.req, this.res)
  596. })
  597. it('should call attemptPaypalInvoiceCollection', function (done) {
  598. this.SubscriptionHandler.attemptPaypalInvoiceCollection
  599. .calledWith('mock-account-code')
  600. .should.equal(true)
  601. done()
  602. })
  603. it('should send a 200', function (done) {
  604. this.res.sendStatus.calledWith(200)
  605. done()
  606. })
  607. })
  608. describe('with a non-actionable request', function () {
  609. beforeEach(function (done) {
  610. this.user.id = this.activeRecurlySubscription.account.account_code
  611. this.req = {
  612. body: {
  613. renewed_subscription_notification: {
  614. account: {
  615. account_code: this.user._id,
  616. },
  617. subscription: {
  618. uuid: this.activeRecurlySubscription.uuid,
  619. plan: {
  620. plan_code: 'collaborator',
  621. state: 'active',
  622. },
  623. },
  624. },
  625. },
  626. }
  627. this.res = {
  628. sendStatus() {
  629. done()
  630. },
  631. }
  632. sinon.spy(this.res, 'sendStatus')
  633. this.SubscriptionController.recurlyCallback(this.req, this.res)
  634. })
  635. it('should not call the subscriptionshandler', function () {
  636. this.SubscriptionHandler.syncSubscription.called.should.equal(false)
  637. this.SubscriptionHandler.attemptPaypalInvoiceCollection.called.should.equal(
  638. false
  639. )
  640. })
  641. it('should respond with a 200 status', function () {
  642. this.res.sendStatus.calledWith(200)
  643. })
  644. })
  645. })
  646. })