SubscriptionDeletionTests.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const { expect } = require('chai')
  2. const async = require('async')
  3. const request = require('./helpers/request')
  4. const User = require('./helpers/User')
  5. const RecurlySubscription = require('./helpers/RecurlySubscription')
  6. const SubscriptionUpdater = require('../../../app/src/Features/Subscription/SubscriptionUpdater')
  7. require('./helpers/MockV1Api')
  8. describe('Subscriptions', function() {
  9. describe('deletion', function() {
  10. beforeEach(function(done) {
  11. this.adminUser = new User()
  12. this.memberUser = new User()
  13. async.series(
  14. [
  15. cb => this.adminUser.ensureUserExists(cb),
  16. cb => this.memberUser.ensureUserExists(cb),
  17. cb => {
  18. this.recurlySubscription = new RecurlySubscription({
  19. adminId: this.adminUser._id,
  20. memberIds: [this.memberUser._id],
  21. invitedEmails: ['foo@bar.com'],
  22. teamInvites: [{ email: 'foo@baz.com' }],
  23. groupPlan: true,
  24. state: 'expired',
  25. planCode: 'professional'
  26. })
  27. this.subscription = this.recurlySubscription.subscription
  28. this.recurlySubscription.ensureExists(cb)
  29. },
  30. cb => this.subscription.refreshUsersFeatures(cb)
  31. ],
  32. done
  33. )
  34. })
  35. it('deletes via Recurly callback', function(done) {
  36. let url = '/user/subscription/callback'
  37. let body = this.recurlySubscription.buildCallbackXml()
  38. request.post({ url, body }, (error, { statusCode }) => {
  39. if (error) {
  40. return done(error)
  41. }
  42. expect(statusCode).to.equal(200)
  43. this.subscription.expectDeleted({ ip: '127.0.0.1' }, done)
  44. })
  45. })
  46. it('refresh features', function(done) {
  47. let url = '/user/subscription/callback'
  48. let body = this.recurlySubscription.buildCallbackXml()
  49. request.post({ url, body }, (error, { statusCode }) => {
  50. if (error) {
  51. return done(error)
  52. }
  53. this.memberUser.getFeatures((error, features) => {
  54. expect(features.collaborators).to.equal(1)
  55. done(error)
  56. })
  57. })
  58. })
  59. it('allows deletion when deletedSubscription exists', function(done) {
  60. let url = '/user/subscription/callback'
  61. let body = this.recurlySubscription.buildCallbackXml()
  62. // create fake deletedSubscription
  63. SubscriptionUpdater._createDeletedSubscription(
  64. this.subscription,
  65. {},
  66. error => {
  67. if (error) {
  68. return done(error)
  69. }
  70. // try deleting the subscription
  71. request.post({ url, body }, (error, { statusCode }) => {
  72. if (error) {
  73. return done(error)
  74. }
  75. expect(statusCode).to.equal(200)
  76. this.subscription.expectDeleted({ ip: '127.0.0.1' }, done)
  77. })
  78. }
  79. )
  80. })
  81. })
  82. })