SubscriptionControllerTests.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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.LimitationsManager = {
  59. hasPaidSubscription: sinon.stub(),
  60. userHasV1OrV2Subscription: sinon.stub(),
  61. userHasV2Subscription: sinon.stub(),
  62. promises: {
  63. hasPaidSubscription: sinon.stub().resolves(),
  64. userHasV1OrV2Subscription: sinon.stub().resolves(),
  65. userHasV2Subscription: sinon.stub().resolves(),
  66. },
  67. }
  68. this.SubscriptionViewModelBuilder = {
  69. buildUsersSubscriptionViewModel: sinon.stub().callsArgWith(1, null, {}),
  70. buildPlansList: sinon.stub(),
  71. promises: {
  72. buildUsersSubscriptionViewModel: sinon.stub().resolves({}),
  73. getBestSubscription: sinon.stub().resolves({}),
  74. },
  75. buildPlansListForSubscriptionDash: sinon
  76. .stub()
  77. .returns({ plans: [], planCodesChangingAtTermEnd: [] }),
  78. }
  79. this.settings = {
  80. coupon_codes: {
  81. upgradeToAnnualPromo: {
  82. student: 'STUDENTCODEHERE',
  83. collaborator: 'COLLABORATORCODEHERE',
  84. },
  85. },
  86. groupPlanModalOptions: {
  87. plan_codes: [],
  88. currencies: [
  89. {
  90. display: 'GBP (£)',
  91. code: 'GBP',
  92. },
  93. ],
  94. sizes: ['42'],
  95. usages: [{ code: 'foo', display: 'Foo' }],
  96. },
  97. apis: {
  98. recurly: {
  99. subdomain: 'sl',
  100. },
  101. },
  102. siteUrl: 'http://de.overleaf.dev:3000',
  103. }
  104. this.AuthorizationManager = {
  105. promises: {
  106. isUserSiteAdmin: sinon.stub().resolves(false),
  107. },
  108. }
  109. this.GeoIpLookup = {
  110. isValidCurrencyParam: sinon.stub().returns(true),
  111. getCurrencyCode: sinon.stub().yields('USD', 'US'),
  112. promises: {
  113. getCurrencyCode: sinon.stub().resolves({
  114. countryCode: 'US',
  115. currencyCode: 'USD',
  116. }),
  117. },
  118. }
  119. this.UserGetter = {
  120. getUser: sinon.stub().callsArgWith(2, null, this.user),
  121. promises: {
  122. getUser: sinon.stub().resolves(this.user),
  123. },
  124. }
  125. this.SplitTestV2Hander = {
  126. promises: {
  127. getAssignment: sinon.stub().resolves({ variant: 'default' }),
  128. isSplitTestActive: sinon.stub().resolves(true),
  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. './SubscriptionViewModelBuilder': this.SubscriptionViewModelBuilder,
  145. './LimitationsManager': this.LimitationsManager,
  146. '../../infrastructure/GeoIpLookup': this.GeoIpLookup,
  147. '@overleaf/settings': this.settings,
  148. '../User/UserGetter': this.UserGetter,
  149. './RecurlyWrapper': (this.RecurlyWrapper = {
  150. updateAccountEmailAddress: sinon.stub().yields(),
  151. }),
  152. './RecurlyEventHandler': {
  153. sendRecurlyAnalyticsEvent: sinon.stub().resolves(),
  154. },
  155. './FeaturesUpdater': (this.FeaturesUpdater = {}),
  156. './GroupPlansData': (this.GroupPlansData = {}),
  157. './V1SubscriptionManager': (this.V1SubscriptionManager = {}),
  158. '../Errors/HttpErrorHandler': (this.HttpErrorHandler = {
  159. unprocessableEntity: sinon.stub().callsFake((req, res, message) => {
  160. res.status(422)
  161. res.json({ message })
  162. }),
  163. }),
  164. './Errors': SubscriptionErrors,
  165. '../Analytics/AnalyticsManager': (this.AnalyticsManager = {
  166. recordEventForUser: sinon.stub(),
  167. recordEventForSession: sinon.stub(),
  168. setUserPropertyForUser: sinon.stub(),
  169. }),
  170. '../../infrastructure/Features': this.Features,
  171. '../../util/currency': (this.currency = {
  172. formatCurrencyLocalized: sinon.stub(),
  173. }),
  174. },
  175. })
  176. this.res = new MockResponse()
  177. this.req = new MockRequest()
  178. this.req.body = {}
  179. this.req.query = { planCode: '123123' }
  180. this.stubbedCurrencyCode = 'GBP'
  181. })
  182. describe('plansPage', function () {
  183. beforeEach(function () {
  184. this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
  185. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  186. currencyCode: this.stubbedCurrencyCode,
  187. })
  188. })
  189. describe('ip override', function () {
  190. beforeEach(function () {
  191. this.req.ip = '1.2.3.4'
  192. this.req.query = { ip: '5.6.7.8' }
  193. this.GeoIpLookup.promises.getCurrencyCode.withArgs('1.2.3.4').resolves({
  194. currencyCode: 'GBP',
  195. })
  196. this.GeoIpLookup.promises.getCurrencyCode.withArgs('5.6.7.8').resolves({
  197. currencyCode: 'USD',
  198. })
  199. })
  200. it('should ignore override for non admin', function (done) {
  201. this.res.render = (page, opts) => {
  202. opts.recommendedCurrency.should.equal('GBP')
  203. done()
  204. }
  205. this.AuthorizationManager.promises.isUserSiteAdmin.resolves(false)
  206. this.SubscriptionController.plansPage(this.req, this.res)
  207. })
  208. it('should accept override for admin', function (done) {
  209. this.res.render = (page, opts) => {
  210. opts.recommendedCurrency.should.equal('USD')
  211. done()
  212. }
  213. this.AuthorizationManager.promises.isUserSiteAdmin.resolves(true)
  214. this.SubscriptionController.plansPage(this.req, this.res)
  215. })
  216. })
  217. describe('groupPlanModal data', function () {
  218. it('should pass local currency if valid', function (done) {
  219. this.res.render = (page, opts) => {
  220. page.should.equal('subscriptions/plans')
  221. opts.groupPlanModalDefaults.currency.should.equal('GBP')
  222. done()
  223. }
  224. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  225. currencyCode: 'GBP',
  226. })
  227. this.SubscriptionController.plansPage(this.req, this.res)
  228. })
  229. it('should fallback to USD when valid', function (done) {
  230. this.res.render = (page, opts) => {
  231. page.should.equal('subscriptions/plans')
  232. opts.groupPlanModalDefaults.currency.should.equal('USD')
  233. done()
  234. }
  235. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  236. currencyCode: 'FOO',
  237. })
  238. this.SubscriptionController.plansPage(this.req, this.res)
  239. })
  240. it('should pass valid options for group plan modal and discard invalid', function (done) {
  241. this.res.render = (page, opts) => {
  242. page.should.equal('subscriptions/plans')
  243. opts.groupPlanModalDefaults.size.should.equal('42')
  244. opts.groupPlanModalDefaults.plan_code.should.equal('collaborator')
  245. opts.groupPlanModalDefaults.currency.should.equal('GBP')
  246. opts.groupPlanModalDefaults.usage.should.equal('foo')
  247. done()
  248. }
  249. this.GeoIpLookup.isValidCurrencyParam.returns(false)
  250. this.req.query = {
  251. number: '42',
  252. currency: 'ABC',
  253. plan: 'does-not-exist',
  254. usage: 'foo',
  255. }
  256. this.SubscriptionController.plansPage(this.req, this.res)
  257. })
  258. })
  259. describe('showInrGeoBanner data', function () {
  260. it('should return true for Indian Users', function (done) {
  261. this.res.render = (page, opts) => {
  262. page.should.equal('subscriptions/plans')
  263. opts.showInrGeoBanner.should.equal(true)
  264. done()
  265. }
  266. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  267. countryCode: 'IN',
  268. })
  269. this.SubscriptionController.plansPage(this.req, this.res)
  270. })
  271. it('should return false for US Users', function (done) {
  272. this.res.render = (page, opts) => {
  273. page.should.equal('subscriptions/plans')
  274. opts.showInrGeoBanner.should.equal(false)
  275. done()
  276. }
  277. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  278. countryCode: 'US',
  279. })
  280. this.SubscriptionController.plansPage(this.req, this.res)
  281. })
  282. })
  283. describe('showBrlGeoBanner data', function () {
  284. it('should return true for Brazilian users', function (done) {
  285. this.res.render = (page, opts) => {
  286. page.should.equal('subscriptions/plans')
  287. opts.showBrlGeoBanner.should.equal(true)
  288. done()
  289. }
  290. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  291. countryCode: 'BR',
  292. })
  293. this.SubscriptionController.plansPage(this.req, this.res)
  294. })
  295. it('should return false for US users', function (done) {
  296. this.res.render = (page, opts) => {
  297. page.should.equal('subscriptions/plans')
  298. opts.showBrlGeoBanner.should.equal(false)
  299. done()
  300. }
  301. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  302. countryCode: 'US',
  303. })
  304. this.SubscriptionController.plansPage(this.req, this.res)
  305. })
  306. })
  307. describe('showLATAMBanner', function () {
  308. describe('latam variant', function () {
  309. beforeEach(function () {
  310. this.SplitTestV2Hander.promises.getAssignment
  311. .withArgs(this.req, this.res, 'geo-pricing-latam-v2')
  312. .resolves({
  313. variant: 'latam',
  314. })
  315. })
  316. it('should return true for Mexican users', function (done) {
  317. this.res.render = (page, opts) => {
  318. page.should.equal('subscriptions/plans')
  319. opts.showLATAMBanner.should.equal(true)
  320. done()
  321. }
  322. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  323. countryCode: 'MX',
  324. })
  325. this.SubscriptionController.plansPage(this.req, this.res)
  326. })
  327. it('should return true for Colombian users', function (done) {
  328. this.res.render = (page, opts) => {
  329. page.should.equal('subscriptions/plans')
  330. opts.showLATAMBanner.should.equal(true)
  331. done()
  332. }
  333. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  334. countryCode: 'CO',
  335. })
  336. this.SubscriptionController.plansPage(this.req, this.res)
  337. })
  338. it('should return true for Chilean users', function (done) {
  339. this.res.render = (page, opts) => {
  340. page.should.equal('subscriptions/plans')
  341. opts.showLATAMBanner.should.equal(true)
  342. done()
  343. }
  344. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  345. countryCode: 'CL',
  346. })
  347. this.SubscriptionController.plansPage(this.req, this.res)
  348. })
  349. it('should return true for Peruvian users', function (done) {
  350. this.res.render = (page, opts) => {
  351. page.should.equal('subscriptions/plans')
  352. opts.showLATAMBanner.should.equal(true)
  353. done()
  354. }
  355. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  356. countryCode: 'PE',
  357. })
  358. this.SubscriptionController.plansPage(this.req, this.res)
  359. })
  360. it('should return true for US users', function (done) {
  361. this.res.render = (page, opts) => {
  362. page.should.equal('subscriptions/plans')
  363. opts.showLATAMBanner.should.equal(false)
  364. done()
  365. }
  366. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  367. countryCode: 'US',
  368. })
  369. this.SubscriptionController.plansPage(this.req, this.res)
  370. })
  371. })
  372. describe('default variant', function () {
  373. beforeEach(function () {
  374. this.SplitTestV2Hander.promises.getAssignment
  375. .withArgs(this.req, this.res, 'geo-pricing-latam-v2')
  376. .resolves({
  377. variant: 'default',
  378. })
  379. })
  380. it('should return false', function (done) {
  381. this.res.render = (page, opts) => {
  382. page.should.equal('subscriptions/plans')
  383. opts.showLATAMBanner.should.equal(false)
  384. done()
  385. }
  386. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  387. countryCode: 'MX',
  388. })
  389. this.SubscriptionController.plansPage(this.req, this.res)
  390. })
  391. })
  392. })
  393. describe('localCcyAssignment', function () {
  394. it('uses formatCurrencyLocalized when variant is enabled', function (done) {
  395. this.SplitTestV2Hander.promises.getAssignment
  396. .withArgs(this.req, this.res, 'local-ccy-format-v2')
  397. .resolves({
  398. variant: 'enabled',
  399. })
  400. this.res.render = (page, opts) => {
  401. expect(opts.formatCurrency).to.equal(
  402. this.currency.formatCurrencyLocalized
  403. )
  404. done()
  405. }
  406. this.SubscriptionController.plansPage(this.req, this.res)
  407. })
  408. it('uses formatCurrencyDefault when variant is default', function (done) {
  409. this.res.render = (page, opts) => {
  410. expect(opts.formatCurrency).to.equal(
  411. this.SubscriptionHelper.formatCurrencyDefault
  412. )
  413. done()
  414. }
  415. this.SubscriptionController.plansPage(this.req, this.res)
  416. })
  417. })
  418. describe('website-redesign-plans test', function () {
  419. beforeEach(function () {
  420. this.req.query = {}
  421. })
  422. describe('"default" variant', function () {
  423. // note: if test is not active, default variant is assigned
  424. beforeEach(function () {
  425. this.SplitTestV2Hander.promises.getAssignment
  426. .withArgs(this.req, this.res, 'website-redesign-plans')
  427. .resolves({
  428. variant: 'default',
  429. })
  430. })
  431. it('renders "default" variant', function (done) {
  432. this.res.render = page => {
  433. page.should.equal('subscriptions/plans')
  434. expect(this.res.redirect).to.not.have.been.called
  435. done()
  436. }
  437. this.SubscriptionController.plansPage(this.req, this.res)
  438. })
  439. })
  440. describe('"new-design" variant', function () {
  441. beforeEach(function () {
  442. this.SplitTestV2Hander.promises.getAssignment
  443. .withArgs(this.req, this.res, 'website-redesign-plans')
  444. .resolves({
  445. variant: 'new-design',
  446. })
  447. })
  448. it('redirects to "new-design" variant', function (done) {
  449. this.res.callback = () => {
  450. expect(this.res.redirect).to.have.been.calledWith(
  451. 302,
  452. '/user/subscription/plans-2'
  453. )
  454. done()
  455. }
  456. this.SubscriptionController.plansPage(this.req, this.res)
  457. })
  458. it('passes query params when redirecting to new design variant', function (done) {
  459. this.req.query = { currency: 'USD' }
  460. this.res.callback = () => {
  461. expect(this.res.redirect).to.have.been.calledWith(
  462. 302,
  463. '/user/subscription/plans-2?currency=USD'
  464. )
  465. done()
  466. }
  467. this.SubscriptionController.plansPage(this.req, this.res)
  468. })
  469. })
  470. describe('"light-design" variant', function () {
  471. beforeEach(function () {
  472. this.SplitTestV2Hander.promises.getAssignment
  473. .withArgs(this.req, this.res, 'website-redesign-plans')
  474. .resolves({
  475. variant: 'light-design',
  476. })
  477. })
  478. it('renders "light-design" variant', function (done) {
  479. this.res.callback = () => {
  480. expect(this.res.redirect).to.have.been.calledWith(
  481. 302,
  482. '/user/subscription/plans-3'
  483. )
  484. done()
  485. }
  486. this.SubscriptionController.plansPage(this.req, this.res)
  487. })
  488. it('passes query params when redirecting to new design variant', function (done) {
  489. this.req.query = { currency: 'USD' }
  490. this.res.callback = () => {
  491. expect(this.res.redirect).to.have.been.calledWith(
  492. 302,
  493. '/user/subscription/plans-3?currency=USD'
  494. )
  495. done()
  496. }
  497. this.SubscriptionController.plansPage(this.req, this.res)
  498. })
  499. })
  500. })
  501. })
  502. describe('plansPage light touch redesign', function () {
  503. beforeEach(function () {
  504. this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
  505. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  506. currencyCode: this.stubbedCurrencyCode,
  507. })
  508. })
  509. describe('ip override', function () {
  510. beforeEach(function () {
  511. this.req.ip = '1.2.3.4'
  512. this.req.query = { ip: '5.6.7.8' }
  513. this.GeoIpLookup.promises.getCurrencyCode.withArgs('1.2.3.4').resolves({
  514. currencyCode: 'GBP',
  515. })
  516. this.GeoIpLookup.promises.getCurrencyCode.withArgs('5.6.7.8').resolves({
  517. currencyCode: 'USD',
  518. })
  519. })
  520. it('should ignore override for non admin', function (done) {
  521. this.res.render = (page, opts) => {
  522. opts.recommendedCurrency.should.equal('GBP')
  523. done()
  524. }
  525. this.AuthorizationManager.promises.isUserSiteAdmin.resolves(false)
  526. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  527. })
  528. it('should accept override for admin', function (done) {
  529. this.res.render = (page, opts) => {
  530. opts.recommendedCurrency.should.equal('USD')
  531. done()
  532. }
  533. this.AuthorizationManager.promises.isUserSiteAdmin.resolves(true)
  534. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  535. })
  536. })
  537. describe('groupPlanModal data', function () {
  538. it('should pass local currency if valid', function (done) {
  539. this.res.render = (page, opts) => {
  540. page.should.equal('subscriptions/plans-light-design')
  541. opts.groupPlanModalDefaults.currency.should.equal('GBP')
  542. done()
  543. }
  544. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  545. currencyCode: 'GBP',
  546. })
  547. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  548. })
  549. it('should fallback to USD when valid', function (done) {
  550. this.res.render = (page, opts) => {
  551. page.should.equal('subscriptions/plans-light-design')
  552. opts.groupPlanModalDefaults.currency.should.equal('USD')
  553. done()
  554. }
  555. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  556. currencyCode: 'FOO',
  557. })
  558. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  559. })
  560. it('should pass valid options for group plan modal and discard invalid', function (done) {
  561. this.res.render = (page, opts) => {
  562. page.should.equal('subscriptions/plans-light-design')
  563. opts.groupPlanModalDefaults.size.should.equal('42')
  564. opts.groupPlanModalDefaults.plan_code.should.equal('collaborator')
  565. opts.groupPlanModalDefaults.currency.should.equal('GBP')
  566. opts.groupPlanModalDefaults.usage.should.equal('foo')
  567. done()
  568. }
  569. this.GeoIpLookup.isValidCurrencyParam.returns(false)
  570. this.req.query = {
  571. number: '42',
  572. currency: 'ABC',
  573. plan: 'does-not-exist',
  574. usage: 'foo',
  575. }
  576. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  577. })
  578. })
  579. describe('showInrGeoBanner data', function () {
  580. it('should return true for Indian Users', function (done) {
  581. this.res.render = (page, opts) => {
  582. page.should.equal('subscriptions/plans-light-design')
  583. opts.showInrGeoBanner.should.equal(true)
  584. done()
  585. }
  586. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  587. countryCode: 'IN',
  588. })
  589. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  590. })
  591. it('should return false for US Users', function (done) {
  592. this.res.render = (page, opts) => {
  593. page.should.equal('subscriptions/plans-light-design')
  594. opts.showInrGeoBanner.should.equal(false)
  595. done()
  596. }
  597. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  598. countryCode: 'US',
  599. })
  600. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  601. })
  602. })
  603. describe('showBrlGeoBanner data', function () {
  604. it('should return true for Brazilian users', function (done) {
  605. this.res.render = (page, opts) => {
  606. page.should.equal('subscriptions/plans-light-design')
  607. opts.showBrlGeoBanner.should.equal(true)
  608. done()
  609. }
  610. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  611. countryCode: 'BR',
  612. })
  613. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  614. })
  615. it('should return false for US users', function (done) {
  616. this.res.render = (page, opts) => {
  617. page.should.equal('subscriptions/plans-light-design')
  618. opts.showBrlGeoBanner.should.equal(false)
  619. done()
  620. }
  621. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  622. countryCode: 'US',
  623. })
  624. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  625. })
  626. })
  627. describe('showLATAMBanner', function () {
  628. describe('latam variant', function () {
  629. beforeEach(function () {
  630. this.SplitTestV2Hander.promises.getAssignment
  631. .withArgs(this.req, this.res, 'geo-pricing-latam-v2')
  632. .resolves({
  633. variant: 'latam',
  634. })
  635. })
  636. it('should return true for Mexican users', function (done) {
  637. this.res.render = (page, opts) => {
  638. page.should.equal('subscriptions/plans-light-design')
  639. opts.showLATAMBanner.should.equal(true)
  640. done()
  641. }
  642. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  643. countryCode: 'MX',
  644. })
  645. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  646. })
  647. it('should return true for Colombian users', function (done) {
  648. this.res.render = (page, opts) => {
  649. page.should.equal('subscriptions/plans-light-design')
  650. opts.showLATAMBanner.should.equal(true)
  651. done()
  652. }
  653. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  654. countryCode: 'CO',
  655. })
  656. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  657. })
  658. it('should return true for Chilean users', function (done) {
  659. this.res.render = (page, opts) => {
  660. page.should.equal('subscriptions/plans-light-design')
  661. opts.showLATAMBanner.should.equal(true)
  662. done()
  663. }
  664. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  665. countryCode: 'CL',
  666. })
  667. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  668. })
  669. it('should return true for Peruvian users', function (done) {
  670. this.res.render = (page, opts) => {
  671. page.should.equal('subscriptions/plans-light-design')
  672. opts.showLATAMBanner.should.equal(true)
  673. done()
  674. }
  675. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  676. countryCode: 'PE',
  677. })
  678. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  679. })
  680. it('should return true for US users', function (done) {
  681. this.res.render = (page, opts) => {
  682. page.should.equal('subscriptions/plans-light-design')
  683. opts.showLATAMBanner.should.equal(false)
  684. done()
  685. }
  686. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  687. countryCode: 'US',
  688. })
  689. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  690. })
  691. })
  692. describe('default variant', function () {
  693. beforeEach(function () {
  694. this.SplitTestV2Hander.promises.getAssignment
  695. .withArgs(this.req, this.res, 'geo-pricing-latam-v2')
  696. .resolves({
  697. variant: 'default',
  698. })
  699. })
  700. it('should return false', function (done) {
  701. this.res.render = (page, opts) => {
  702. page.should.equal('subscriptions/plans-light-design')
  703. opts.showLATAMBanner.should.equal(false)
  704. done()
  705. }
  706. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  707. countryCode: 'MX',
  708. })
  709. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  710. })
  711. })
  712. })
  713. describe('localCcyAssignment', function () {
  714. it('uses formatCurrencyLocalized when variant is enabled', function (done) {
  715. this.SplitTestV2Hander.promises.getAssignment
  716. .withArgs(this.req, this.res, 'local-ccy-format-v2')
  717. .resolves({
  718. variant: 'enabled',
  719. })
  720. this.res.render = (page, opts) => {
  721. expect(opts.formatCurrency).to.equal(
  722. this.currency.formatCurrencyLocalized
  723. )
  724. done()
  725. }
  726. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  727. })
  728. it('uses formatCurrencyDefault when variant is default', function (done) {
  729. this.res.render = (page, opts) => {
  730. expect(opts.formatCurrency).to.equal(
  731. this.SubscriptionHelper.formatCurrencyDefault
  732. )
  733. done()
  734. }
  735. this.SubscriptionController.plansPageLightDesign(this.req, this.res)
  736. })
  737. })
  738. })
  739. describe('interstitialPaymentPage', function () {
  740. beforeEach(function () {
  741. this.req.ip = '1234.3123.3131.333 313.133.445.666 653.5345.5345.534'
  742. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  743. currencyCode: this.stubbedCurrencyCode,
  744. })
  745. })
  746. describe('with a user without subscription', function () {
  747. it('should render the interstitial payment page', function (done) {
  748. this.res.render = (page, opts) => {
  749. page.should.equal('subscriptions/interstitial-payment')
  750. done()
  751. }
  752. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  753. })
  754. })
  755. describe('with a user with subscription', function () {
  756. it('should redirect to the subscription dashboard', function (done) {
  757. this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(
  758. true
  759. )
  760. this.res.redirect = url => {
  761. url.should.equal('/user/subscription?hasSubscription=true')
  762. done()
  763. }
  764. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  765. })
  766. })
  767. describe('showInrGeoBanner data', function () {
  768. it('should return true for Indian users', function (done) {
  769. this.res.render = (page, opts) => {
  770. page.should.equal('subscriptions/interstitial-payment')
  771. opts.showInrGeoBanner.should.equal(true)
  772. done()
  773. }
  774. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  775. countryCode: 'IN',
  776. })
  777. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  778. })
  779. it('should be false for US users', function (done) {
  780. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  781. countryCode: 'US',
  782. })
  783. this.res.render = (page, opts) => {
  784. page.should.equal('subscriptions/interstitial-payment')
  785. opts.showInrGeoBanner.should.equal(false)
  786. done()
  787. }
  788. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  789. })
  790. })
  791. describe('showBrlGeoBanner data', function () {
  792. it('should return true for Brazilian users', function (done) {
  793. this.res.render = (page, opts) => {
  794. page.should.equal('subscriptions/interstitial-payment')
  795. opts.showBrlGeoBanner.should.equal(true)
  796. done()
  797. }
  798. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  799. countryCode: 'BR',
  800. })
  801. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  802. })
  803. it('should return false for US users', function (done) {
  804. this.res.render = (page, opts) => {
  805. page.should.equal('subscriptions/interstitial-payment')
  806. opts.showBrlGeoBanner.should.equal(false)
  807. done()
  808. }
  809. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  810. countryCode: 'US',
  811. })
  812. this.SubscriptionController.interstitialPaymentPage(this.req, this.res)
  813. })
  814. })
  815. describe('showLATAMBanner', function () {
  816. describe('latam variant', function () {
  817. beforeEach(function () {
  818. this.SplitTestV2Hander.promises.getAssignment
  819. .withArgs(this.req, this.res, 'geo-pricing-latam-v2')
  820. .resolves({
  821. variant: 'latam',
  822. })
  823. })
  824. it('should return true for Mexican users', function (done) {
  825. this.res.render = (page, opts) => {
  826. page.should.equal('subscriptions/interstitial-payment')
  827. opts.showLATAMBanner.should.equal(true)
  828. done()
  829. }
  830. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  831. countryCode: 'MX',
  832. })
  833. this.SubscriptionController.interstitialPaymentPage(
  834. this.req,
  835. this.res
  836. )
  837. })
  838. it('should return true for Colombian users', function (done) {
  839. this.res.render = (page, opts) => {
  840. page.should.equal('subscriptions/interstitial-payment')
  841. opts.showLATAMBanner.should.equal(true)
  842. done()
  843. }
  844. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  845. countryCode: 'CO',
  846. })
  847. this.SubscriptionController.interstitialPaymentPage(
  848. this.req,
  849. this.res
  850. )
  851. })
  852. it('should return true for Chilean users', function (done) {
  853. this.res.render = (page, opts) => {
  854. page.should.equal('subscriptions/interstitial-payment')
  855. opts.showLATAMBanner.should.equal(true)
  856. done()
  857. }
  858. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  859. countryCode: 'CL',
  860. })
  861. this.SubscriptionController.interstitialPaymentPage(
  862. this.req,
  863. this.res
  864. )
  865. })
  866. it('should return true for Peruvian users', function (done) {
  867. this.res.render = (page, opts) => {
  868. page.should.equal('subscriptions/interstitial-payment')
  869. opts.showLATAMBanner.should.equal(true)
  870. done()
  871. }
  872. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  873. countryCode: 'PE',
  874. })
  875. this.SubscriptionController.interstitialPaymentPage(
  876. this.req,
  877. this.res
  878. )
  879. })
  880. it('should return true for US users', function (done) {
  881. this.res.render = (page, opts) => {
  882. page.should.equal('subscriptions/interstitial-payment')
  883. opts.showLATAMBanner.should.equal(false)
  884. done()
  885. }
  886. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  887. countryCode: 'US',
  888. })
  889. this.SubscriptionController.interstitialPaymentPage(
  890. this.req,
  891. this.res
  892. )
  893. })
  894. })
  895. describe('default variant', function () {
  896. beforeEach(function () {
  897. this.SplitTestV2Hander.promises.getAssignment
  898. .withArgs(this.req, this.res, 'website-redesign-plan')
  899. .resolves({
  900. variant: 'default',
  901. })
  902. })
  903. it('should return false', function (done) {
  904. this.res.render = (page, opts) => {
  905. page.should.equal('subscriptions/interstitial-payment')
  906. opts.showLATAMBanner.should.equal(false)
  907. done()
  908. }
  909. this.GeoIpLookup.promises.getCurrencyCode.resolves({
  910. countryCode: 'MX',
  911. })
  912. this.SubscriptionController.interstitialPaymentPage(
  913. this.req,
  914. this.res
  915. )
  916. })
  917. })
  918. })
  919. })
  920. describe('successfulSubscription', function () {
  921. it('without a personal subscription', function (done) {
  922. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  923. {}
  924. )
  925. this.res.redirect = url => {
  926. url.should.equal('/user/subscription/plans')
  927. done()
  928. }
  929. this.SubscriptionController.successfulSubscription(this.req, this.res)
  930. })
  931. it('with a personal subscription', function (done) {
  932. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  933. {
  934. personalSubscription: 'foo',
  935. }
  936. )
  937. this.res.render = (url, variables) => {
  938. url.should.equal('subscriptions/successful-subscription-react')
  939. assert.deepEqual(variables, {
  940. title: 'thank_you',
  941. personalSubscription: 'foo',
  942. postCheckoutRedirect: undefined,
  943. })
  944. done()
  945. }
  946. this.SubscriptionController.successfulSubscription(this.req, this.res)
  947. })
  948. it('with an error', function (done) {
  949. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  950. undefined
  951. )
  952. this.SubscriptionController.successfulSubscription(
  953. this.req,
  954. this.res,
  955. error => {
  956. assert.isNotNull(error)
  957. done()
  958. }
  959. )
  960. })
  961. })
  962. describe('userSubscriptionPage', function () {
  963. beforeEach(function (done) {
  964. this.SubscriptionViewModelBuilder.promises.buildUsersSubscriptionViewModel.resolves(
  965. {
  966. personalSubscription: (this.personalSubscription = {
  967. 'personal-subscription': 'mock',
  968. }),
  969. memberGroupSubscriptions: (this.memberGroupSubscriptions = {
  970. 'group-subscriptions': 'mock',
  971. }),
  972. }
  973. )
  974. this.SubscriptionViewModelBuilder.buildPlansList.returns(
  975. (this.plans = { plans: 'mock' })
  976. )
  977. this.SubscriptionViewModelBuilder.buildPlansListForSubscriptionDash.returns(
  978. {
  979. plans: this.plans,
  980. planCodesChangingAtTermEnd: [],
  981. }
  982. )
  983. this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
  984. this.res.render = (view, data) => {
  985. this.data = data
  986. expect(view).to.equal('subscriptions/dashboard-react')
  987. done()
  988. }
  989. this.SubscriptionController.userSubscriptionPage(this.req, this.res, done)
  990. })
  991. it('should load the personal, groups and v1 subscriptions', function () {
  992. expect(this.data.personalSubscription).to.deep.equal(
  993. this.personalSubscription
  994. )
  995. expect(this.data.memberGroupSubscriptions).to.deep.equal(
  996. this.memberGroupSubscriptions
  997. )
  998. })
  999. it('should load the user', function () {
  1000. expect(this.data.user).to.deep.equal(this.user)
  1001. })
  1002. it('should load the plans', function () {
  1003. expect(this.data.plans).to.deep.equal(this.plans)
  1004. })
  1005. it('should load an empty list of groups with settings available', function () {
  1006. expect(this.data.groupSettingsEnabledFor).to.deep.equal([])
  1007. })
  1008. })
  1009. describe('updateSubscription via post', function () {
  1010. beforeEach(function (done) {
  1011. this.res = {
  1012. redirect() {
  1013. done()
  1014. },
  1015. }
  1016. sinon.spy(this.res, 'redirect')
  1017. this.plan_code = '1234'
  1018. this.req.body.plan_code = this.plan_code
  1019. this.SubscriptionController.updateSubscription(this.req, this.res)
  1020. })
  1021. it('should send the user and subscriptionId to the handler', function (done) {
  1022. this.SubscriptionHandler.updateSubscription
  1023. .calledWith(this.user, this.plan_code)
  1024. .should.equal(true)
  1025. done()
  1026. })
  1027. it('should redurect to the subscription page', function (done) {
  1028. this.res.redirect.calledWith('/user/subscription').should.equal(true)
  1029. done()
  1030. })
  1031. })
  1032. describe('updateAccountEmailAddress via put', function () {
  1033. it('should send the user and subscriptionId to RecurlyWrapper', function () {
  1034. this.res.sendStatus = sinon.spy()
  1035. this.SubscriptionController.updateAccountEmailAddress(this.req, this.res)
  1036. this.RecurlyWrapper.updateAccountEmailAddress
  1037. .calledWith(this.user._id, this.user.email)
  1038. .should.equal(true)
  1039. })
  1040. it('should respond with 200', function () {
  1041. this.res.sendStatus = sinon.spy()
  1042. this.SubscriptionController.updateAccountEmailAddress(this.req, this.res)
  1043. this.res.sendStatus.calledWith(200).should.equal(true)
  1044. })
  1045. it('should send the error to the next handler when updating recurly account email fails', function (done) {
  1046. this.RecurlyWrapper.updateAccountEmailAddress.yields(new Error())
  1047. this.next = sinon.spy(error => {
  1048. expect(error).instanceOf(Error)
  1049. done()
  1050. })
  1051. this.SubscriptionController.updateAccountEmailAddress(
  1052. this.req,
  1053. this.res,
  1054. this.next
  1055. )
  1056. })
  1057. })
  1058. describe('reactivateSubscription', function () {
  1059. describe('when the user has permission', function () {
  1060. beforeEach(function (done) {
  1061. this.res = {
  1062. redirect() {
  1063. done()
  1064. },
  1065. }
  1066. this.req.assertPermission = sinon.stub()
  1067. this.next = sinon.stub().callsFake(error => {
  1068. done(error)
  1069. })
  1070. sinon.spy(this.res, 'redirect')
  1071. this.SubscriptionController.reactivateSubscription(
  1072. this.req,
  1073. this.res,
  1074. this.next
  1075. )
  1076. })
  1077. it('should assert the user has permission to reactivate their subscription', function (done) {
  1078. this.req.assertPermission
  1079. .calledWith('reactivate-subscription')
  1080. .should.equal(true)
  1081. done()
  1082. })
  1083. it('should tell the handler to reactivate this user', function (done) {
  1084. this.SubscriptionHandler.reactivateSubscription
  1085. .calledWith(this.user)
  1086. .should.equal(true)
  1087. done()
  1088. })
  1089. it('should redurect to the subscription page', function (done) {
  1090. this.res.redirect.calledWith('/user/subscription').should.equal(true)
  1091. done()
  1092. })
  1093. })
  1094. describe('when the user does not have permission', function () {
  1095. beforeEach(function (done) {
  1096. this.res = {
  1097. redirect() {
  1098. done()
  1099. },
  1100. }
  1101. this.req.assertPermission = sinon.stub().throws()
  1102. this.next = sinon.stub().callsFake(() => {
  1103. done()
  1104. })
  1105. sinon.spy(this.res, 'redirect')
  1106. this.SubscriptionController.reactivateSubscription(
  1107. this.req,
  1108. this.res,
  1109. this.next
  1110. )
  1111. })
  1112. it('should not reactivate the user', function (done) {
  1113. this.req.assertPermission = sinon.stub().throws()
  1114. this.SubscriptionHandler.reactivateSubscription.called.should.equal(
  1115. false
  1116. )
  1117. done()
  1118. })
  1119. it('should call next with an error', function (done) {
  1120. this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
  1121. done()
  1122. })
  1123. })
  1124. })
  1125. describe('cancelSubscription', function () {
  1126. beforeEach(function (done) {
  1127. this.res = {
  1128. redirect() {
  1129. done()
  1130. },
  1131. }
  1132. sinon.spy(this.res, 'redirect')
  1133. this.SubscriptionController.cancelSubscription(this.req, this.res)
  1134. })
  1135. it('should tell the handler to cancel this user', function (done) {
  1136. this.SubscriptionHandler.cancelSubscription
  1137. .calledWith(this.user)
  1138. .should.equal(true)
  1139. done()
  1140. })
  1141. it('should redurect to the subscription page', function (done) {
  1142. this.res.redirect
  1143. .calledWith('/user/subscription/canceled')
  1144. .should.equal(true)
  1145. done()
  1146. })
  1147. })
  1148. describe('recurly callback', function () {
  1149. describe('with a sync subscription request', function () {
  1150. beforeEach(function (done) {
  1151. this.req = {
  1152. body: {
  1153. expired_subscription_notification: {
  1154. account: {
  1155. account_code: this.user._id,
  1156. },
  1157. subscription: {
  1158. uuid: this.activeRecurlySubscription.uuid,
  1159. plan: {
  1160. plan_code: 'collaborator',
  1161. state: 'active',
  1162. },
  1163. },
  1164. },
  1165. },
  1166. }
  1167. this.res = {
  1168. sendStatus() {
  1169. done()
  1170. },
  1171. }
  1172. sinon.spy(this.res, 'sendStatus')
  1173. this.SubscriptionController.recurlyCallback(this.req, this.res)
  1174. })
  1175. it('should tell the SubscriptionHandler to process the recurly callback', function (done) {
  1176. this.SubscriptionHandler.syncSubscription.called.should.equal(true)
  1177. done()
  1178. })
  1179. it('should send a 200', function (done) {
  1180. this.res.sendStatus.calledWith(200)
  1181. done()
  1182. })
  1183. })
  1184. describe('with a billing info updated request', function () {
  1185. beforeEach(function (done) {
  1186. this.req = {
  1187. body: {
  1188. billing_info_updated_notification: {
  1189. account: {
  1190. account_code: 'mock-account-code',
  1191. },
  1192. },
  1193. },
  1194. }
  1195. this.res = {
  1196. sendStatus() {
  1197. done()
  1198. },
  1199. }
  1200. sinon.spy(this.res, 'sendStatus')
  1201. this.SubscriptionController.recurlyCallback(this.req, this.res)
  1202. })
  1203. it('should call attemptPaypalInvoiceCollection', function (done) {
  1204. this.SubscriptionHandler.attemptPaypalInvoiceCollection
  1205. .calledWith('mock-account-code')
  1206. .should.equal(true)
  1207. done()
  1208. })
  1209. it('should send a 200', function (done) {
  1210. this.res.sendStatus.calledWith(200)
  1211. done()
  1212. })
  1213. })
  1214. describe('with a non-actionable request', function () {
  1215. beforeEach(function (done) {
  1216. this.user.id = this.activeRecurlySubscription.account.account_code
  1217. this.req = {
  1218. body: {
  1219. renewed_subscription_notification: {
  1220. account: {
  1221. account_code: this.user._id,
  1222. },
  1223. subscription: {
  1224. uuid: this.activeRecurlySubscription.uuid,
  1225. plan: {
  1226. plan_code: 'collaborator',
  1227. state: 'active',
  1228. },
  1229. },
  1230. },
  1231. },
  1232. }
  1233. this.res = {
  1234. sendStatus() {
  1235. done()
  1236. },
  1237. }
  1238. sinon.spy(this.res, 'sendStatus')
  1239. this.SubscriptionController.recurlyCallback(this.req, this.res)
  1240. })
  1241. it('should not call the subscriptionshandler', function () {
  1242. this.SubscriptionHandler.syncSubscription.called.should.equal(false)
  1243. this.SubscriptionHandler.attemptPaypalInvoiceCollection.called.should.equal(
  1244. false
  1245. )
  1246. })
  1247. it('should respond with a 200 status', function () {
  1248. this.res.sendStatus.calledWith(200)
  1249. })
  1250. })
  1251. })
  1252. })