billingMenuBuilder.test.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { describe, test, it, expect } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. import type { AnyAbility } from '@casl/ability/dist/types'
  4. import type { AccessProfile, organizationState } from '~/types/interfaces'
  5. import BillingMenuBuilder from '~/services/layout/menuBuilder/billingMenuBuilder'
  6. import type { 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(
  20. runtimeConfig,
  21. ability,
  22. organizationProfile,
  23. accessProfile,
  24. )
  25. })
  26. describe('getMenuName', () => {
  27. test('validate name', () => {
  28. expect(menuBuilder.getMenuName()).toEqual('Billing')
  29. })
  30. })
  31. describe('build', () => {
  32. test('has all items', () => {
  33. ability.can = vi.fn(() => true)
  34. // Should return a MenuGroup
  35. const result = menuBuilder.build() as MenuGroup
  36. expect(result.label).toEqual('billing')
  37. expect(result.icon).toEqual({ name: 'fas fa-euro-sign' })
  38. // @ts-ignore
  39. expect(result.children.length).toEqual(9)
  40. })
  41. test('has no items', () => {
  42. ability.can = vi.fn(() => false)
  43. expect(menuBuilder.build()).toEqual(null)
  44. })
  45. test('has only rights for menu billing_product', () => {
  46. ability.can = vi.fn(
  47. (action: string, subject: string) =>
  48. action === 'display' && subject === 'billing_product_page',
  49. )
  50. expect(menuBuilder.build()).toEqual({
  51. label: 'billing_product',
  52. icon: { name: 'fas fa-cube' },
  53. to: 'https://mydomain.com/#/intangibles/list/',
  54. type: MENU_LINK_TYPE.V1,
  55. active: false,
  56. })
  57. })
  58. test('has only rights for menu billing_products_by_student', () => {
  59. ability.can = vi.fn(
  60. (action: string, subject: string) =>
  61. action === 'display' && subject === 'billing_products_by_student_page',
  62. )
  63. expect(menuBuilder.build()).toEqual({
  64. label: 'billing_products_by_student',
  65. icon: { name: 'fas fa-cubes' },
  66. to: 'https://mydomain.com/#/access_intangibles/list/',
  67. type: MENU_LINK_TYPE.V1,
  68. active: false,
  69. })
  70. })
  71. test('has only rights for menu billing_edition', () => {
  72. ability.can = vi.fn(
  73. (action: string, subject: string) =>
  74. action === 'display' && subject === 'billing_edition_page',
  75. )
  76. expect(menuBuilder.build()).toEqual({
  77. label: 'billing_edition',
  78. icon: { name: 'fas fa-copy' },
  79. to: 'https://mydomain.com/#/billing_edition',
  80. type: MENU_LINK_TYPE.V1,
  81. active: false,
  82. })
  83. })
  84. test('has only rights for menu billing_accounting', () => {
  85. ability.can = vi.fn(
  86. (action: string, subject: string) =>
  87. action === 'display' && subject === 'billing_accounting_page',
  88. )
  89. expect(menuBuilder.build()).toEqual({
  90. label: 'billing_accounting',
  91. icon: { name: 'fas fa-file-alt' },
  92. to: 'https://mydomain.com/#/bill_accountings/list/',
  93. type: MENU_LINK_TYPE.V1,
  94. active: false,
  95. })
  96. })
  97. test('has only rights for menu billing_payment_list', () => {
  98. ability.can = vi.fn(
  99. (action: string, subject: string) =>
  100. action === 'display' && subject === 'billing_payment_list_page',
  101. )
  102. expect(menuBuilder.build()).toEqual({
  103. label: 'billing_payment_list',
  104. icon: { name: 'fas fa-credit-card' },
  105. to: 'https://mydomain.com/#/bill_payments_list/list/',
  106. type: MENU_LINK_TYPE.V1,
  107. active: false,
  108. })
  109. })
  110. test('has only rights for menu pes_export', () => {
  111. ability.can = vi.fn(
  112. (action: string, subject: string) =>
  113. action === 'display' && subject === 'pes_page',
  114. )
  115. expect(menuBuilder.build()).toEqual({
  116. label: 'pes_export',
  117. icon: { name: 'fas fa-align-justify' },
  118. to: 'https://mydomain.com/#/pes/list/',
  119. type: MENU_LINK_TYPE.V1,
  120. active: false,
  121. })
  122. })
  123. test('has only rights for menu berger_levrault_export', () => {
  124. ability.can = vi.fn(
  125. (action: string, subject: string) =>
  126. action === 'display' && subject === 'berger_levrault_page',
  127. )
  128. expect(menuBuilder.build()).toEqual({
  129. label: 'berger_levrault_export',
  130. icon: { name: 'fas fa-align-justify' },
  131. to: 'https://mydomain.com/#/berger_levraults/list/',
  132. type: MENU_LINK_TYPE.V1,
  133. active: false,
  134. })
  135. })
  136. test('has only rights for menu jvs_export', () => {
  137. ability.can = vi.fn(
  138. (action: string, subject: string) =>
  139. action === 'display' && subject === 'jvs_page',
  140. )
  141. expect(menuBuilder.build()).toEqual({
  142. label: 'jvs_export',
  143. icon: { name: 'fas fa-align-justify' },
  144. to: 'https://mydomain.com/#/jvs/list/',
  145. type: MENU_LINK_TYPE.V1,
  146. active: false,
  147. })
  148. })
  149. test('has only rights for menu afi_export', () => {
  150. ability.can = vi.fn(
  151. (action: string, subject: string) =>
  152. action === 'display' && subject === 'afi_page',
  153. )
  154. expect(menuBuilder.build()).toEqual({
  155. label: 'afi_export',
  156. icon: { name: 'fas fa-align-justify' },
  157. to: 'https://mydomain.com/#/afis/list/',
  158. type: MENU_LINK_TYPE.V1,
  159. active: false,
  160. })
  161. })
  162. })