billingMenuBuilder.test.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import { describe, test, expect, vi, beforeEach } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. import type { AnyAbility } from '@casl/ability/dist/types'
  4. import type { Router } from 'vue-router'
  5. import type { AccessProfile, organizationState } from '~/types/interfaces'
  6. import BillingMenuBuilder from '~/services/layout/menuBuilder/billingMenuBuilder'
  7. import type { MenuGroup } from '~/types/layout'
  8. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  9. let runtimeConfig: RuntimeConfig
  10. let ability: AnyAbility
  11. let organizationProfile: organizationState
  12. let accessProfile: AccessProfile
  13. let menuBuilder: BillingMenuBuilder
  14. let router: Router
  15. beforeEach(() => {
  16. runtimeConfig = vi.fn() as any as RuntimeConfig
  17. ability = vi.fn() as any as AnyAbility
  18. organizationProfile = vi.fn() as any as organizationState
  19. accessProfile = vi.fn() as any as AccessProfile
  20. // @ts-ignore
  21. router = vi.fn() as Router
  22. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  23. menuBuilder = new BillingMenuBuilder(
  24. runtimeConfig,
  25. ability,
  26. organizationProfile,
  27. accessProfile,
  28. router,
  29. )
  30. })
  31. describe('getMenuName', () => {
  32. test('validate name', () => {
  33. expect(menuBuilder.getMenuName()).toEqual('Billing')
  34. })
  35. })
  36. describe('build', () => {
  37. test('has all items', () => {
  38. ability.can = vi.fn(() => true)
  39. // Should return a MenuGroup
  40. const result = menuBuilder.build() as MenuGroup
  41. expect(result.label).toEqual('billing')
  42. expect(result.icon).toEqual({ name: 'fas fa-euro-sign' })
  43. // @ts-ignore
  44. expect(result.children.length).toEqual(10)
  45. })
  46. test('has no items', () => {
  47. ability.can = vi.fn(() => false)
  48. expect(menuBuilder.build()).toEqual(null)
  49. })
  50. test('has only rights for menu billing_product', () => {
  51. ability.can = vi.fn(
  52. (action: string, subject: string) =>
  53. action === 'display' && subject === 'billing_product_page',
  54. )
  55. expect(menuBuilder.build()).toEqual({
  56. label: 'billing_product',
  57. icon: { name: 'fas fa-cube' },
  58. to: 'https://mydomain.com/#/intangibles/list/',
  59. target: '_self',
  60. type: MENU_LINK_TYPE.V1,
  61. active: false,
  62. endOfSubsection: false,
  63. })
  64. })
  65. test('has only rights for menu billing_products_by_student', () => {
  66. ability.can = vi.fn(
  67. (action: string, subject: string) =>
  68. action === 'display' && subject === 'billing_products_by_student_page',
  69. )
  70. expect(menuBuilder.build()).toEqual({
  71. label: 'billing_products_by_student',
  72. icon: { name: 'fas fa-cubes' },
  73. to: 'https://mydomain.com/#/access_intangibles/list/',
  74. target: '_self',
  75. type: MENU_LINK_TYPE.V1,
  76. active: false,
  77. endOfSubsection: false,
  78. })
  79. })
  80. test('has only rights for menu billing_edition', () => {
  81. ability.can = vi.fn(
  82. (action: string, subject: string) =>
  83. action === 'display' && subject === 'billing_edition_page',
  84. )
  85. expect(menuBuilder.build()).toEqual({
  86. label: 'billing_edition',
  87. icon: { name: 'fas fa-copy' },
  88. to: 'https://mydomain.com/#/billing_edition',
  89. target: '_self',
  90. type: MENU_LINK_TYPE.V1,
  91. active: false,
  92. endOfSubsection: false,
  93. })
  94. })
  95. test('has only rights for menu billing_accounting', () => {
  96. ability.can = vi.fn(
  97. (action: string, subject: string) =>
  98. action === 'display' && subject === 'billing_accounting_page',
  99. )
  100. expect(menuBuilder.build()).toEqual({
  101. label: 'billing_accounting',
  102. icon: { name: 'fas fa-file-alt' },
  103. to: 'https://mydomain.com/#/bill_accountings/list/',
  104. target: '_self',
  105. type: MENU_LINK_TYPE.V1,
  106. active: false,
  107. endOfSubsection: false,
  108. })
  109. })
  110. test('has only rights for menu billing_payment_list', () => {
  111. ability.can = vi.fn(
  112. (action: string, subject: string) =>
  113. action === 'display' && subject === 'billing_payment_list_page',
  114. )
  115. expect(menuBuilder.build()).toEqual({
  116. label: 'billing_payment_list',
  117. icon: { name: 'fas fa-credit-card' },
  118. to: 'https://mydomain.com/#/bill_payments_list/list/',
  119. target: '_self',
  120. type: MENU_LINK_TYPE.V1,
  121. active: false,
  122. endOfSubsection: false,
  123. })
  124. })
  125. test('has only rights for menu pes_export', () => {
  126. ability.can = vi.fn(
  127. (action: string, subject: string) =>
  128. action === 'display' && subject === 'pes_page',
  129. )
  130. expect(menuBuilder.build()).toEqual({
  131. label: 'pes_export',
  132. icon: { name: 'fas fa-align-justify' },
  133. to: 'https://mydomain.com/#/pes/list/',
  134. target: '_self',
  135. type: MENU_LINK_TYPE.V1,
  136. active: false,
  137. endOfSubsection: false,
  138. })
  139. })
  140. test('has only rights for menu berger_levrault_export', () => {
  141. ability.can = vi.fn(
  142. (action: string, subject: string) =>
  143. action === 'display' && subject === 'berger_levrault_page',
  144. )
  145. expect(menuBuilder.build()).toEqual({
  146. label: 'berger_levrault_export',
  147. icon: { name: 'fas fa-align-justify' },
  148. to: 'https://mydomain.com/#/berger_levraults/list/',
  149. target: '_self',
  150. type: MENU_LINK_TYPE.V1,
  151. active: false,
  152. endOfSubsection: false,
  153. })
  154. })
  155. test('has only rights for menu jvs_export', () => {
  156. ability.can = vi.fn(
  157. (action: string, subject: string) =>
  158. action === 'display' && subject === 'jvs_page',
  159. )
  160. expect(menuBuilder.build()).toEqual({
  161. label: 'jvs_export',
  162. icon: { name: 'fas fa-align-justify' },
  163. to: 'https://mydomain.com/#/jvs/list/',
  164. target: '_self',
  165. type: MENU_LINK_TYPE.V1,
  166. active: false,
  167. endOfSubsection: false,
  168. })
  169. })
  170. test('has only rights for menu afi_export', () => {
  171. ability.can = vi.fn(
  172. (action: string, subject: string) =>
  173. action === 'display' && subject === 'afi_page',
  174. )
  175. expect(menuBuilder.build()).toEqual({
  176. label: 'afi_export',
  177. icon: { name: 'fas fa-align-justify' },
  178. to: 'https://mydomain.com/#/afis/list/',
  179. target: '_self',
  180. type: MENU_LINK_TYPE.V1,
  181. active: false,
  182. endOfSubsection: false,
  183. })
  184. })
  185. test('has only rights for menu sdd_regie_export', () => {
  186. ability.can = vi.fn(
  187. (action: string, subject: string) =>
  188. action === 'display' && subject === 'sdd_regie_page',
  189. )
  190. expect(menuBuilder.build()).toEqual({
  191. label: 'sdd_regie_export',
  192. icon: { name: 'fas fa-align-justify' },
  193. to: 'https://mydomain.com/#/sdd_regies/list/',
  194. target: '_self',
  195. type: MENU_LINK_TYPE.V1,
  196. active: false,
  197. endOfSubsection: false,
  198. })
  199. })
  200. })