SubscriptionDeletionTests.js 2.8 KB

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