billingMenuBuilder.test.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { describe, test, it, expect } from 'vitest'
  2. import {RuntimeConfig} from "@nuxt/schema";
  3. import {AnyAbility} from "@casl/ability/dist/types";
  4. import {AccessProfile, organizationState} from "~/types/interfaces";
  5. import BillingMenuBuilder from "~/services/layout/menuBuilder/billingMenuBuilder";
  6. import {MenuGroup} from "~/types/layout";
  7. import {MENU_LINK_TYPE} from "~/types/enum/layout";
  8. let runtimeConfig: RuntimeConfig
  9. let ability: AnyAbility
  10. let organizationProfile: organizationState
  11. let accessProfile: AccessProfile
  12. let menuBuilder: BillingMenuBuilder
  13. beforeEach(()=> {
  14. runtimeConfig = vi.fn() as any as RuntimeConfig
  15. ability = vi.fn() as any as AnyAbility
  16. organizationProfile = vi.fn() as any as organizationState
  17. accessProfile = vi.fn() as any as AccessProfile
  18. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  19. menuBuilder = new BillingMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
  20. })
  21. describe('getMenuName', () => {
  22. test('validate name', () => {
  23. expect(menuBuilder.getMenuName()).toEqual("Billing")
  24. })
  25. })
  26. describe('build', () => {
  27. test('has all items', () => {
  28. ability.can = vi.fn(() => true)
  29. // Should return a MenuGroup
  30. const result = menuBuilder.build() as MenuGroup
  31. expect(result.label).toEqual('billing')
  32. expect(result.icon).toEqual({name: 'fas fa-euro-sign'})
  33. // @ts-ignore
  34. expect(result.children.length).toEqual(8)
  35. })
  36. test('has no items', () => {
  37. ability.can = vi.fn(() => false)
  38. expect(menuBuilder.build()).toEqual(null)
  39. })
  40. test('has only rights for menu billing_product', () => {
  41. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_product_page')
  42. expect(menuBuilder.build()).toEqual(
  43. {label: 'billing_product', icon: {name: 'fas fa-cube'}, to: 'https://mydomain.com/#/intangibles/list/', type: MENU_LINK_TYPE.V1, active: false}
  44. )
  45. })
  46. test('has only rights for menu billing_products_by_student', () => {
  47. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_products_by_student_page')
  48. expect(menuBuilder.build()).toEqual(
  49. {label: 'billing_products_by_student', icon: {name: 'fas fa-cubes'}, to: 'https://mydomain.com/#/access_intangibles/list/', type: MENU_LINK_TYPE.V1, active: false}
  50. )
  51. })
  52. test('has only rights for menu billing_edition', () => {
  53. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_edition_page')
  54. expect(menuBuilder.build()).toEqual(
  55. {label: 'billing_edition', icon: {name: 'fas fa-copy'}, to: 'https://mydomain.com/#/billing_edition', type: MENU_LINK_TYPE.V1, active: false}
  56. )
  57. })
  58. test('has only rights for menu billing_accounting', () => {
  59. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_accounting_page')
  60. expect(menuBuilder.build()).toEqual(
  61. {label: 'billing_accounting', icon: {name: 'fas fa-file-alt'}, to: 'https://mydomain.com/#/bill_accountings/list/', type: MENU_LINK_TYPE.V1, active: false}
  62. )
  63. })
  64. test('has only rights for menu billing_payment_list', () => {
  65. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'billing_payment_list_page')
  66. expect(menuBuilder.build()).toEqual(
  67. {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}
  68. )
  69. })
  70. test('has only rights for menu pes_export', () => {
  71. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'pes_page')
  72. expect(menuBuilder.build()).toEqual(
  73. {label: 'pes_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/#/pes/list/', type: MENU_LINK_TYPE.V1, active: false}
  74. )
  75. })
  76. test('has only rights for menu berger_levrault_export', () => {
  77. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'berger_levrault_page')
  78. expect(menuBuilder.build()).toEqual(
  79. {label: 'berger_levrault_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/#/berger_levraults/list/', type: MENU_LINK_TYPE.V1, active: false}
  80. )
  81. })
  82. test('has only rights for menu jvs_export', () => {
  83. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'jvs_page')
  84. expect(menuBuilder.build()).toEqual(
  85. {label: 'jvs_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/#/jvs/list/', type: MENU_LINK_TYPE.V1, active: false}
  86. )
  87. })
  88. test('has only rights for menu afi_export', () => {
  89. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'afi_page')
  90. expect(menuBuilder.build()).toEqual(
  91. {label: 'afi_export', icon: {name: 'fas fa-align-justify'}, to: 'https://mydomain.com/#/afis/list/', type: MENU_LINK_TYPE.V1, active: false}
  92. )
  93. })
  94. })