Эх сурвалжийг харах

Improve SubscriptionHelperTests unit test by decoupling the test logic from the code and make the test price different for each case (#8089)

GitOrigin-RevId: 4db0f474817651e8d17c35c529d53a5266ca4b1e
M Fahru 4 жил өмнө
parent
commit
43a069edca

+ 87 - 371
services/web/test/unit/src/Subscription/SubscriptionHelperTests.js

@@ -32,8 +32,6 @@ const plans = {
 describe('SubscriptionHelper', function () {
 describe('SubscriptionHelper', function () {
   beforeEach(function () {
   beforeEach(function () {
     this.INITIAL_LICENSE_SIZE = 2
     this.INITIAL_LICENSE_SIZE = 2
-    this.mockCollaboratorPrice = 2000
-    this.mockProfessionalPrice = 4000
     this.settings = {
     this.settings = {
       groupPlanModalOptions: {
       groupPlanModalOptions: {
         currencySymbols: {
         currencySymbols: {
@@ -48,56 +46,56 @@ describe('SubscriptionHelper', function () {
     this.GroupPlansData = {
     this.GroupPlansData = {
       enterprise: {
       enterprise: {
         collaborator: {
         collaborator: {
-          USD: {
+          CHF: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockCollaboratorPrice,
+              price_in_cents: 1000,
             },
             },
           },
           },
-          CHF: {
+          DKK: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockCollaboratorPrice,
+              price_in_cents: 2000,
             },
             },
           },
           },
-          DKK: {
+          SEK: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockCollaboratorPrice,
+              price_in_cents: 3000,
             },
             },
           },
           },
           NOK: {
           NOK: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockCollaboratorPrice,
+              price_in_cents: 4000,
             },
             },
           },
           },
-          SEK: {
+          USD: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockCollaboratorPrice,
+              price_in_cents: 5000,
             },
             },
           },
           },
         },
         },
         professional: {
         professional: {
-          USD: {
+          CHF: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockProfessionalPrice,
+              price_in_cents: 10000,
             },
             },
           },
           },
-          CHF: {
+          DKK: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockProfessionalPrice,
+              price_in_cents: 20000,
             },
             },
           },
           },
-          DKK: {
+          SEK: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockProfessionalPrice,
+              price_in_cents: 30000,
             },
             },
           },
           },
           NOK: {
           NOK: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockProfessionalPrice,
+              price_in_cents: 40000,
             },
             },
           },
           },
-          SEK: {
+          USD: {
             [this.INITIAL_LICENSE_SIZE]: {
             [this.INITIAL_LICENSE_SIZE]: {
-              price_in_cents: this.mockProfessionalPrice,
+              price_in_cents: 50000,
             },
             },
           },
           },
         },
         },
@@ -150,374 +148,92 @@ describe('SubscriptionHelper', function () {
   })
   })
 
 
   describe('generateInitialLocalizedGroupPrice', function () {
   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('CHF currency', function () {
+      it('should return the correct localized price for every plan', function () {
+        const localizedPrice =
+          this.SubscriptionHelper.generateInitialLocalizedGroupPrice('CHF')
+
+        expect(localizedPrice).to.deep.equal({
+          price: {
+            collaborator: 'Fr 10',
+            professional: 'Fr 100',
+          },
+          pricePerUser: {
+            collaborator: 'Fr 5',
+            professional: 'Fr 50',
+          },
         })
         })
       })
       })
     })
     })
 
 
-    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)
-        })
+    describe('DKK currency', function () {
+      it('should return the correct localized price for every plan', function () {
+        const localizedPrice =
+          this.SubscriptionHelper.generateInitialLocalizedGroupPrice('DKK')
 
 
-        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)
+        expect(localizedPrice).to.deep.equal({
+          price: {
+            collaborator: '20 kr',
+            professional: '200 kr',
+          },
+          pricePerUser: {
+            collaborator: '10 kr',
+            professional: '100 kr',
+          },
         })
         })
       })
       })
+    })
 
 
-      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
-        })
+    describe('SEK currency', function () {
+      it('should return the correct localized price for every plan', function () {
+        const localizedPrice =
+          this.SubscriptionHelper.generateInitialLocalizedGroupPrice('SEK')
 
 
-        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)
+        expect(localizedPrice).to.deep.equal({
+          price: {
+            collaborator: '30 kr',
+            professional: '300 kr',
+          },
+          pricePerUser: {
+            collaborator: '15 kr',
+            professional: '150 kr',
+          },
         })
         })
       })
       })
+    })
 
 
-      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)
-        })
+    describe('NOK currency', function () {
+      it('should return the correct localized price for every plan', function () {
+        const localizedPrice =
+          this.SubscriptionHelper.generateInitialLocalizedGroupPrice('NOK')
 
 
-        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)
+        expect(localizedPrice).to.deep.equal({
+          price: {
+            collaborator: '40 kr',
+            professional: '400 kr',
+          },
+          pricePerUser: {
+            collaborator: '20 kr',
+            professional: '200 kr',
+          },
         })
         })
       })
       })
+    })
 
 
-      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)
-        })
+    describe('other supported currencies', function () {
+      it('should return the correct localized price for every plan', function () {
+        const localizedPrice =
+          this.SubscriptionHelper.generateInitialLocalizedGroupPrice('USD')
 
 
-        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)
+        expect(localizedPrice).to.deep.equal({
+          price: {
+            collaborator: '$50',
+            professional: '$500',
+          },
+          pricePerUser: {
+            collaborator: '$25',
+            professional: '$250',
+          },
         })
         })
       })
       })
     })
     })