SubscriptionViewModelBuilderTests.coffee 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require 'sinon'
  3. should = require("chai").should()
  4. modulePath = '../../../../app/js/Features/Subscription/SubscriptionViewModelBuilder'
  5. describe 'SubscriptionViewModelBuilder', ->
  6. mockSubscription =
  7. uuid: "subscription-123-active"
  8. plan:
  9. name: "Gold"
  10. plan_code: "gold"
  11. current_period_ends_at: new Date()
  12. state: "active"
  13. unit_amount_in_cents: 999
  14. account:
  15. account_code: "user-123"
  16. beforeEach ->
  17. @user =
  18. email:"tom@yahoo.com",
  19. _id: 'one',
  20. signUpDate: new Date('2000-10-01')
  21. @plan =
  22. name: "test plan"
  23. @SubscriptionFormatters =
  24. formatDate: sinon.stub().returns("Formatted date")
  25. formatPrice: sinon.stub().returns("Formatted price")
  26. @RecurlyWrapper =
  27. sign: sinon.stub().callsArgWith(1, null, "something")
  28. getSubscription: sinon.stub().callsArgWith 2, null,
  29. account:
  30. hosted_login_token: "hosted_login_token"
  31. @builder = SandboxedModule.require modulePath, requires:
  32. "settings-sharelatex": { apis: { recurly: { subdomain: "example.com" }}}
  33. "./RecurlyWrapper": @RecurlyWrapper
  34. "./PlansLocator": @PlansLocator = {}
  35. "./SubscriptionLocator": @SubscriptionLocator = {}
  36. "./SubscriptionFormatters": @SubscriptionFormatters
  37. "./LimitationsManager": {}
  38. "logger-sharelatex":
  39. log:->
  40. warn:->
  41. "underscore": {}
  42. @PlansLocator.findLocalPlanInSettings = sinon.stub().returns(@plan)
  43. @SubscriptionLocator.getUsersSubscription = sinon.stub().callsArgWith(1, null, mockSubscription)
  44. @SubscriptionLocator.getMemberSubscriptions = sinon.stub().callsArgWith(1, null, null)
  45. it 'builds the user view model', ->
  46. callback = (error, subscription, memberSubscriptions, billingDetailsLink) =>
  47. @error = error
  48. @subscription = subscription
  49. @memberSubscriptions = memberSubscriptions
  50. @billingDetailsLink = billingDetailsLink
  51. @builder.buildUsersSubscriptionViewModel(@user, callback)
  52. @subscription.name.should.eq 'test plan'
  53. @subscription.nextPaymentDueAt.should.eq 'Formatted date'
  54. @subscription.price.should.eq 'Formatted price'
  55. @billingDetailsLink.should.eq "https://example.com.recurly.com/account/billing_info/edit?ht=hosted_login_token"