| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- const SandboxedModule = require('sandboxed-module')
- const { expect } = require('chai')
- const modulePath =
- '../../../../app/src/Features/Subscription/SubscriptionHelper'
- const plans = {
- expensive: {
- planCode: 'expensive',
- price_in_cents: 1500,
- },
- cheaper: {
- planCode: 'cheaper',
- price_in_cents: 500,
- },
- alsoCheap: {
- plancode: 'also-cheap',
- price_in_cents: 500,
- },
- expensiveGroup: {
- plancode: 'group_expensive',
- price_in_cents: 49500,
- groupPlan: true,
- },
- cheapGroup: {
- plancode: 'group_cheap',
- price_in_cents: 1000,
- groupPlan: true,
- },
- bad: {},
- }
- describe('SubscriptionHelper', function () {
- beforeEach(function () {
- this.INITIAL_LICENSE_SIZE = 2
- this.mockCollaboratorPrice = 2000
- this.mockProfessionalPrice = 4000
- this.settings = {
- groupPlanModalOptions: {
- currencySymbols: {
- USD: '$',
- CHF: 'Fr',
- DKK: 'kr',
- NOK: 'kr',
- SEK: 'kr',
- },
- },
- }
- this.GroupPlansData = {
- enterprise: {
- collaborator: {
- USD: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockCollaboratorPrice,
- },
- },
- CHF: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockCollaboratorPrice,
- },
- },
- DKK: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockCollaboratorPrice,
- },
- },
- NOK: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockCollaboratorPrice,
- },
- },
- SEK: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockCollaboratorPrice,
- },
- },
- },
- professional: {
- USD: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockProfessionalPrice,
- },
- },
- CHF: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockProfessionalPrice,
- },
- },
- DKK: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockProfessionalPrice,
- },
- },
- NOK: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockProfessionalPrice,
- },
- },
- SEK: {
- [this.INITIAL_LICENSE_SIZE]: {
- price_in_cents: this.mockProfessionalPrice,
- },
- },
- },
- },
- }
- this.SubscriptionHelper = SandboxedModule.require(modulePath, {
- requires: {
- '@overleaf/settings': this.settings,
- './GroupPlansData': this.GroupPlansData,
- },
- })
- })
- describe('shouldPlanChangeAtTermEnd', function () {
- it('should return true if the new plan is less expensive', function () {
- const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
- plans.expensive,
- plans.cheaper
- )
- expect(changeAtTermEnd).to.be.true
- })
- it('should return false if the new plan is more exepensive', function () {
- const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
- plans.cheaper,
- plans.expensive
- )
- expect(changeAtTermEnd).to.be.false
- })
- it('should return false if the new plan is the same price', function () {
- const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
- plans.cheaper,
- plans.alsoCheap
- )
- expect(changeAtTermEnd).to.be.false
- })
- it('should return false if the change is from an individual plan to a more expensive group plan', function () {
- const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
- plans.expensive,
- plans.expensiveGroup
- )
- expect(changeAtTermEnd).to.be.false
- })
- it('should return true if the change is from an individual plan to a cheaper group plan', function () {
- const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
- plans.expensive,
- plans.cheapGroup
- )
- expect(changeAtTermEnd).to.be.true
- })
- })
- describe('generateInitialLocalizedGroupPrice', function () {
- describe('collaborator plan', function () {
- beforeEach(function () {
- this.plan = 'collaborator'
- })
- describe('for CHF currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'CHF'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.recommendedCurrencySymbol} ${this.expectedPrice}`
- const {
- price: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${this.recommendedCurrencySymbol} ${expectedPricePerUser}`
- const {
- pricePerUser: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for DKK currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'DKK'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.expectedPrice} ${this.recommendedCurrencySymbol}`
- const {
- price: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${expectedPricePerUser} ${this.recommendedCurrencySymbol}`
- const {
- pricePerUser: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for SEK currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'SEK'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.expectedPrice} ${this.recommendedCurrencySymbol}`
- const {
- price: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${expectedPricePerUser} ${this.recommendedCurrencySymbol}`
- const {
- pricePerUser: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for NOK currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'NOK'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.expectedPrice} ${this.recommendedCurrencySymbol}`
- const {
- price: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${expectedPricePerUser} ${this.recommendedCurrencySymbol}`
- const {
- pricePerUser: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for other supported currencies', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'USD'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.recommendedCurrencySymbol}${this.expectedPrice}`
- const {
- price: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${this.recommendedCurrencySymbol}${expectedPricePerUser}`
- const {
- pricePerUser: { collaborator },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(collaborator).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- })
- describe('professional plan plan', function () {
- beforeEach(function () {
- this.plan = 'professional'
- })
- describe('for CHF currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'CHF'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.recommendedCurrencySymbol} ${this.expectedPrice}`
- const {
- price: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${this.recommendedCurrencySymbol} ${expectedPricePerUser}`
- const {
- pricePerUser: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for DKK currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'DKK'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.expectedPrice} ${this.recommendedCurrencySymbol}`
- const {
- price: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${expectedPricePerUser} ${this.recommendedCurrencySymbol}`
- const {
- pricePerUser: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for SEK currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'SEK'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.expectedPrice} ${this.recommendedCurrencySymbol}`
- const {
- price: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${expectedPricePerUser} ${this.recommendedCurrencySymbol}`
- const {
- pricePerUser: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for NOK currency', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'NOK'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.expectedPrice} ${this.recommendedCurrencySymbol}`
- const {
- price: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${expectedPricePerUser} ${this.recommendedCurrencySymbol}`
- const {
- pricePerUser: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- describe('for other supported currencies', function () {
- beforeEach(function () {
- this.mockRecommendedCurrency = 'USD'
- this.recommendedCurrencySymbol =
- this.settings.groupPlanModalOptions.currencySymbols[
- this.mockRecommendedCurrency
- ]
- this.expectedPrice =
- this.GroupPlansData.enterprise[this.plan][
- this.mockRecommendedCurrency
- ][this.INITIAL_LICENSE_SIZE].price_in_cents / 100
- })
- it('should return the correct localized price', function () {
- const expectedLocalizedPrice = `${this.recommendedCurrencySymbol}${this.expectedPrice}`
- const {
- price: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPrice)
- })
- it('should return the correct localized price per user', function () {
- const expectedPricePerUser =
- this.expectedPrice / this.INITIAL_LICENSE_SIZE
- const expectedLocalizedPricePerUser = `${this.recommendedCurrencySymbol}${expectedPricePerUser}`
- const {
- pricePerUser: { professional },
- } = this.SubscriptionHelper.generateInitialLocalizedGroupPrice(
- this.mockRecommendedCurrency
- )
- expect(professional).to.be.equal(expectedLocalizedPricePerUser)
- })
- })
- })
- })
- })
|