overleaf/services/web/test/unit/coffee/Subscription/SubscriptionViewModelBuilderTests.coffee

70 lines
2.4 KiB
CoffeeScript
Raw Normal View History

SandboxedModule = require('sandboxed-module')
sinon = require 'sinon'
should = require("chai").should()
modulePath = '../../../../app/js/Features/Subscription/SubscriptionViewModelBuilder'
describe 'SubscriptionViewModelBuilder', ->
mockSubscription =
uuid: "subscription-123-active"
plan:
name: "Gold"
plan_code: "gold"
current_period_ends_at: new Date()
state: "active"
unit_amount_in_cents: 999
account:
account_code: "user-123"
beforeEach ->
@user =
email:"tom@yahoo.com",
_id: 'one',
signUpDate: new Date('2000-10-01')
@plan =
name: "test plan"
@SubscriptionFormatters =
formatDate: sinon.stub().returns("Formatted date")
formatPrice: sinon.stub().returns("Formatted price")
@RecurlyWrapper =
sign: sinon.stub().callsArgWith(1, null, "something")
getSubscription: sinon.stub().callsArgWith 2, null,
account:
hosted_login_token: "hosted_login_token"
@builder = SandboxedModule.require modulePath, requires:
"settings-sharelatex": { apis: { recurly: { subdomain: "example.com" }}}
"./RecurlyWrapper": @RecurlyWrapper
"./PlansLocator": @PlansLocator = {}
"./SubscriptionLocator": @SubscriptionLocator = {}
"./SubscriptionFormatters": @SubscriptionFormatters
2018-01-10 10:26:16 +00:00
"./LimitationsManager": {}
2018-06-07 16:16:21 +00:00
"./V1SubscriptionManager": @V1SubscriptionManager = {}
"logger-sharelatex":
log:->
warn:->
"underscore": {}
@PlansLocator.findLocalPlanInSettings = sinon.stub().returns(@plan)
@SubscriptionLocator.getUsersSubscription = sinon.stub().callsArgWith(1, null, mockSubscription)
@SubscriptionLocator.getMemberSubscriptions = sinon.stub().callsArgWith(1, null, null)
2018-06-07 16:16:21 +00:00
@V1SubscriptionManager.getSubscriptionsFromV1 = sinon.stub().yields(null, @mockV1Sub = ['mock-v1-subs'])
it 'builds the user view model', ->
2018-06-07 16:16:21 +00:00
callback = (error, subscription, memberSubscriptions, billingDetailsLink, v1Sub) =>
@error = error
@subscription = subscription
@memberSubscriptions = memberSubscriptions
@billingDetailsLink = billingDetailsLink
2018-06-07 16:16:21 +00:00
@v1Sub = v1Sub
@builder.buildUsersSubscriptionViewModel(@user, callback)
@subscription.name.should.eq 'test plan'
@subscription.nextPaymentDueAt.should.eq 'Formatted date'
@subscription.price.should.eq 'Formatted price'
@billingDetailsLink.should.eq "https://example.com.recurly.com/account/billing_info/edit?ht=hosted_login_token"
2018-06-07 16:16:21 +00:00
@v1Sub.should.deep.equal @mockV1Sub