Browse Source

add billingMenuBuilder.test.ts and communicationMenuBuilder.test.ts

Olivier Massot 2 years ago
parent
commit
7af392d42f

+ 115 - 0
tests/units/services/menuBuilder/billingMenuBuilder.test.ts

@@ -0,0 +1,115 @@
+import { describe, test, it, expect } from 'vitest'
+import {RuntimeConfig} from "@nuxt/schema";
+import {AnyAbility} from "@casl/ability/dist/types";
+import {AccessProfile, organizationState} from "~/types/interfaces";
+import BillingMenuBuilder from "~/services/menuBuilder/billingMenuBuilder";
+import {MenuGroup} from "~/types/layout";
+import {MENU_LINK_TYPE} from "~/types/enum/layout";
+
+let runtimeConfig: RuntimeConfig
+let ability: AnyAbility
+let organizationProfile: organizationState
+let accessProfile: AccessProfile
+let menuBuilder: BillingMenuBuilder
+
+beforeEach(()=> {
+    runtimeConfig = vi.fn() as any as RuntimeConfig
+    ability = vi.fn() as any as AnyAbility
+    organizationProfile = vi.fn() as any as organizationState
+    accessProfile = vi.fn() as any as AccessProfile
+
+    runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
+
+    menuBuilder = new BillingMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
+})
+
+
+describe('getMenuName', () => {
+    test('validate name', () => {
+        expect(menuBuilder.getMenuName()).toEqual("Billing")
+    })
+})
+
+
+describe('build', () => {
+    test('has all items', () => {
+        ability.can = vi.fn(() => true)
+
+        // Should return a MenuGroup
+        const result = menuBuilder.build() as MenuGroup
+
+        expect(result.label).toEqual('billing')
+        expect(result.icon).toEqual({name: 'fas fa-euro-sign'})
+        // @ts-ignore
+        expect(result.children.length).toEqual(8)
+    })
+
+    test('has no items', () => {
+        ability.can = vi.fn(() => false)
+        expect(menuBuilder.build()).toEqual(null)
+    })
+
+    test('has only rights for menu billing_product', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_product_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'billing_product', icon: {name: 'fas fa-cube'}, to: 'https://mydomain.com/intangibles/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu billing_products_by_student', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_products_by_student_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'billing_products_by_student', icon: {name: 'fas fa-cubes'}, to: 'https://mydomain.com/access_intangibles/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu billing_edition', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_edition_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'billing_edition', icon: {name: 'fas fa-copy'}, to: 'https://mydomain.com/billing_edition', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu billing_accounting', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_accounting_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'billing_accounting', icon: {name: 'fas fa-file-alt'}, to: 'https://mydomain.com/bill_accountings/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu billing_payment_list', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_payment_list_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'billing_payment_list', icon: {name: 'fas fa-credit-card'}, to: 'https://mydomain.com/bill_payments_list/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu pes_export', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'pes_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'pes_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/pes/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu berger_levrault_export', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'berger_levrault_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'berger_levrault_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/berger_levraults/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu jvs_export', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'jvs_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'jvs_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/jvs/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+})

+ 76 - 0
tests/units/services/menuBuilder/communicationMenuBuilder.test.ts

@@ -0,0 +1,76 @@
+
+import { describe, test, it, expect } from 'vitest'
+import {RuntimeConfig} from "@nuxt/schema";
+import {AnyAbility} from "@casl/ability/dist/types";
+import {AccessProfile, organizationState} from "~/types/interfaces";
+import CommunicationMenuBuilder from "~/services/menuBuilder/communicationMenuBuilder";
+import {MenuGroup} from "~/types/layout";
+import {MENU_LINK_TYPE} from "~/types/enum/layout";
+
+let runtimeConfig: RuntimeConfig
+let ability: AnyAbility
+let organizationProfile: organizationState
+let accessProfile: AccessProfile
+let menuBuilder: CommunicationMenuBuilder
+
+beforeEach(()=> {
+    runtimeConfig = vi.fn() as any as RuntimeConfig
+    ability = vi.fn() as any as AnyAbility
+    organizationProfile = vi.fn() as any as organizationState
+    accessProfile = vi.fn() as any as AccessProfile
+
+    runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
+
+    menuBuilder = new CommunicationMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
+})
+
+
+describe('getMenuName', () => {
+    test('validate name', () => {
+        expect(menuBuilder.getMenuName()).toEqual("Communication")
+    })
+})
+
+
+describe('build', () => {
+    test('has all items', () => {
+        ability.can = vi.fn(() => true)
+
+        // Should return a MenuGroup
+        const result = menuBuilder.build() as MenuGroup
+
+        expect(result.label).toEqual('communication')
+        expect(result.icon).toEqual({name: 'fas fa-comments'})
+        // @ts-ignore
+        expect(result.children.length).toEqual(3)
+    })
+
+    test('has no items', () => {
+        ability.can = vi.fn(() => false)
+        expect(menuBuilder.build()).toEqual(null)
+    })
+
+    test('has only rights for menu inbox', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'inbox_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'inbox', icon: {name: 'fas fa-inbox'}, to: 'https://mydomain.com/messages/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu message_send', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'message_send_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'message_send', icon: {name: 'fas fa-paper-plane'}, to: 'https://mydomain.com/messagessends/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu message_templates', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'message_templates_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'message_templates', icon: {name: 'fas fa-edit'}, to: 'https://mydomain.com/templates/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+})