cotisationsMenuBuilder.test.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import { describe, test, expect, vi, beforeEach } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. //@ts-expect-error problème de typage sans conséquence
  4. import type { AnyAbility } from '@casl/ability/dist/types'
  5. import type { Router } from 'vue-router'
  6. import type { AccessProfile, organizationState } from '~/types/interfaces'
  7. import CotisationsMenuBuilder from '~/services/layout/menuBuilder/cotisationsMenuBuilder'
  8. import type { MenuGroup } from '~/types/layout'
  9. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  10. let runtimeConfig: RuntimeConfig
  11. let ability: AnyAbility
  12. let organizationProfile: organizationState
  13. let accessProfile: AccessProfile
  14. let menuBuilder: CotisationsMenuBuilder
  15. let router: Router
  16. beforeEach(() => {
  17. runtimeConfig = vi.fn() as any as RuntimeConfig
  18. ability = vi.fn() as any as AnyAbility
  19. organizationProfile = vi.fn() as any as organizationState
  20. accessProfile = vi.fn() as any as AccessProfile
  21. // @ts-ignore
  22. router = vi.fn() as Router
  23. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  24. menuBuilder = new CotisationsMenuBuilder(
  25. runtimeConfig,
  26. ability,
  27. organizationProfile,
  28. accessProfile,
  29. router,
  30. )
  31. })
  32. describe('getMenuName', () => {
  33. test('validate name', () => {
  34. expect(menuBuilder.getMenuName()).toEqual('Cotisation')
  35. })
  36. })
  37. describe('build', () => {
  38. test('has all items', () => {
  39. ability.can = vi.fn(() => true)
  40. // Should return a MenuGroup
  41. const result = menuBuilder.build() as MenuGroup
  42. expect(result.label).toEqual('cotisations')
  43. expect(result.icon).toEqual({ name: 'fas fa-money-bill' })
  44. // @ts-ignore
  45. expect(result.children.length).toEqual(17)
  46. })
  47. test('has no items', () => {
  48. ability.can = vi.fn(() => false)
  49. expect(menuBuilder.build()).toEqual(null)
  50. })
  51. test('has only rights for menu rate_cotisation', () => {
  52. ability.can = vi.fn(
  53. (action: string, subject: string) =>
  54. action === 'display' && subject === 'rate_cotisation_page',
  55. )
  56. expect(menuBuilder.build()).toEqual({
  57. label: 'rate_cotisation',
  58. icon: { name: 'fas fa-euro-sign' },
  59. to: 'https://mydomain.com/#/cotisation/rate',
  60. target: '_self',
  61. type: MENU_LINK_TYPE.V1,
  62. active: false,
  63. endOfSubsection: false,
  64. })
  65. })
  66. test('has only rights for menu parameters_cotisation', () => {
  67. ability.can = vi.fn(
  68. (action: string, subject: string) =>
  69. action === 'display' && subject === 'parameters_cotisation_page',
  70. )
  71. expect(menuBuilder.build()).toEqual({
  72. label: 'parameters_cotisation',
  73. icon: { name: 'fas fa-euro-sign' },
  74. to: 'https://mydomain.com/#/cotisation/parameter',
  75. target: '_self',
  76. type: MENU_LINK_TYPE.V1,
  77. active: false,
  78. endOfSubsection: false,
  79. })
  80. })
  81. test('has only rights for menu send_cotisation', () => {
  82. ability.can = vi.fn(
  83. (action: string, subject: string) =>
  84. action === 'display' && subject === 'send_cotisation_page',
  85. )
  86. expect(menuBuilder.build()).toEqual({
  87. label: 'send_cotisation',
  88. icon: { name: 'fas fa-euro-sign' },
  89. to: 'https://mydomain.com/#/cotisation/send',
  90. target: '_self',
  91. type: MENU_LINK_TYPE.V1,
  92. active: false,
  93. endOfSubsection: false,
  94. })
  95. })
  96. test('has only rights for menu state_cotisation', () => {
  97. ability.can = vi.fn(
  98. (action: string, subject: string) =>
  99. action === 'display' && subject === 'state_cotisation_page',
  100. )
  101. expect(menuBuilder.build()).toEqual({
  102. label: 'state_cotisation',
  103. icon: { name: 'fas fa-euro-sign' },
  104. to: 'https://mydomain.com/#/cotisation/state',
  105. target: '_self',
  106. type: MENU_LINK_TYPE.V1,
  107. active: false,
  108. endOfSubsection: false,
  109. })
  110. })
  111. test('has only rights for menu pay_cotisation', () => {
  112. ability.can = vi.fn(
  113. (action: string, subject: string) =>
  114. action === 'display' && subject === 'pay_cotisation_page',
  115. )
  116. expect(menuBuilder.build()).toEqual({
  117. label: 'pay_cotisation',
  118. icon: { name: 'fas fa-euro-sign' },
  119. to: 'https://mydomain.com/#/cotisation/pay',
  120. target: '_self',
  121. type: MENU_LINK_TYPE.V1,
  122. active: false,
  123. endOfSubsection: false,
  124. })
  125. })
  126. test('has only rights for menu check_cotisation', () => {
  127. ability.can = vi.fn(
  128. (action: string, subject: string) =>
  129. action === 'display' && subject === 'check_cotisation_page',
  130. )
  131. expect(menuBuilder.build()).toEqual({
  132. label: 'check_cotisation',
  133. icon: { name: 'fas fa-euro-sign' },
  134. to: 'https://mydomain.com/#/cotisation/check',
  135. target: '_self',
  136. type: MENU_LINK_TYPE.V1,
  137. active: false,
  138. endOfSubsection: false,
  139. })
  140. })
  141. test('has only rights for menu ledger_cotisation', () => {
  142. ability.can = vi.fn(
  143. (action: string, subject: string) =>
  144. action === 'display' && subject === 'ledger_cotisation_page',
  145. )
  146. expect(menuBuilder.build()).toEqual({
  147. label: 'ledger_cotisation',
  148. icon: { name: 'fas fa-euro-sign' },
  149. to: 'https://mydomain.com/#/cotisation/ledger',
  150. target: '_self',
  151. type: MENU_LINK_TYPE.V1,
  152. active: false,
  153. endOfSubsection: false,
  154. })
  155. })
  156. test('has only rights for menu magazine_cotisation', () => {
  157. ability.can = vi.fn(
  158. (action: string, subject: string) =>
  159. action === 'display' && subject === 'magazine_cotisation_page',
  160. )
  161. expect(menuBuilder.build()).toEqual({
  162. label: 'magazine_cotisation',
  163. icon: { name: 'fas fa-euro-sign' },
  164. to: 'https://mydomain.com/#/cotisation/magazine',
  165. target: '_self',
  166. type: MENU_LINK_TYPE.V1,
  167. active: false,
  168. endOfSubsection: false,
  169. })
  170. })
  171. test('has only rights for menu ventilated_cotisation', () => {
  172. ability.can = vi.fn(
  173. (action: string, subject: string) =>
  174. action === 'display' && subject === 'ventilated_cotisation_page',
  175. )
  176. expect(menuBuilder.build()).toEqual({
  177. label: 'ventilated_cotisation',
  178. icon: { name: 'fas fa-euro-sign' },
  179. to: 'https://mydomain.com/#/cotisation/ventilated',
  180. target: '_self',
  181. type: MENU_LINK_TYPE.V1,
  182. active: false,
  183. endOfSubsection: false,
  184. })
  185. })
  186. test('has only rights for menu pay_erase_cotisation', () => {
  187. ability.can = vi.fn(
  188. (action: string, subject: string) =>
  189. action === 'display' && subject === 'pay_erase_cotisation_page',
  190. )
  191. expect(menuBuilder.build()).toEqual({
  192. label: 'pay_erase_cotisation',
  193. icon: { name: 'fas fa-euro-sign' },
  194. to: 'https://mydomain.com/#/cotisation/payerase',
  195. target: '_self',
  196. type: MENU_LINK_TYPE.V1,
  197. active: false,
  198. endOfSubsection: false,
  199. })
  200. })
  201. test('has only rights for menu resume_cotisation', () => {
  202. ability.can = vi.fn(
  203. (action: string, subject: string) =>
  204. action === 'display' && subject === 'resume_cotisation_page',
  205. )
  206. expect(menuBuilder.build()).toEqual({
  207. label: 'resume_cotisation',
  208. icon: { name: 'fas fa-euro-sign' },
  209. to: 'https://mydomain.com/#/cotisation/resume',
  210. target: '_self',
  211. type: MENU_LINK_TYPE.V1,
  212. active: false,
  213. endOfSubsection: false,
  214. })
  215. })
  216. test('has only rights for menu history_cotisation', () => {
  217. ability.can = vi.fn(
  218. (action: string, subject: string) =>
  219. action === 'display' && subject === 'history_cotisation_page',
  220. )
  221. expect(menuBuilder.build()).toEqual({
  222. label: 'history_cotisation',
  223. icon: { name: 'fas fa-euro-sign' },
  224. to: 'https://mydomain.com/#/cotisation/history',
  225. target: '_self',
  226. type: MENU_LINK_TYPE.V1,
  227. active: false,
  228. endOfSubsection: false,
  229. })
  230. })
  231. test('has only rights for menu call_cotisation', () => {
  232. ability.can = vi.fn(
  233. (action: string, subject: string) =>
  234. action === 'display' && subject === 'call_cotisation_page',
  235. )
  236. expect(menuBuilder.build()).toEqual({
  237. label: 'call_cotisation',
  238. icon: { name: 'fas fa-euro-sign' },
  239. to: 'https://mydomain.com/#/cotisation/call',
  240. target: '_self',
  241. type: MENU_LINK_TYPE.V1,
  242. active: false,
  243. endOfSubsection: false,
  244. })
  245. })
  246. test('has only rights for menu history_structure_cotisation', () => {
  247. ability.can = vi.fn(
  248. (action: string, subject: string) =>
  249. action === 'display' && subject === 'history_structure_cotisation_page',
  250. )
  251. expect(menuBuilder.build()).toEqual({
  252. label: 'history_structure_cotisation',
  253. icon: { name: 'fas fa-euro-sign' },
  254. to: 'https://mydomain.com/#/cotisation/historystructure',
  255. target: '_self',
  256. type: MENU_LINK_TYPE.V1,
  257. active: false,
  258. endOfSubsection: false,
  259. })
  260. })
  261. test('has only rights for menu insurance_cotisation', () => {
  262. ability.can = vi.fn(
  263. (action: string, subject: string) =>
  264. action === 'display' && subject === 'insurance_cotisation_page',
  265. )
  266. expect(menuBuilder.build()).toEqual({
  267. label: 'insurance_cotisation',
  268. icon: { name: 'fas fa-euro-sign' },
  269. to: 'https://mydomain.com/#/cotisation/insurance',
  270. target: '_self',
  271. type: MENU_LINK_TYPE.V1,
  272. active: false,
  273. endOfSubsection: false,
  274. })
  275. })
  276. test('has only rights for menu resume_all_cotisation', () => {
  277. ability.can = vi.fn(
  278. (action: string, subject: string) =>
  279. action === 'display' && subject === 'resume_all_cotisation_page',
  280. )
  281. expect(menuBuilder.build()).toEqual({
  282. label: 'resume_all_cotisation',
  283. icon: { name: 'fas fa-euro-sign' },
  284. to: 'https://mydomain.com/#/cotisation/resumeall',
  285. target: '_self',
  286. type: MENU_LINK_TYPE.V1,
  287. active: false,
  288. endOfSubsection: false,
  289. })
  290. })
  291. test('has only rights for menu resume_pay_cotisation', () => {
  292. ability.can = vi.fn(
  293. (action: string, subject: string) =>
  294. action === 'display' && subject === 'resume_pay_cotisation_page',
  295. )
  296. expect(menuBuilder.build()).toEqual({
  297. label: 'resume_pay_cotisation',
  298. icon: { name: 'fas fa-euro-sign' },
  299. to: 'https://mydomain.com/#/cotisation/resumepay',
  300. target: '_self',
  301. type: MENU_LINK_TYPE.V1,
  302. active: false,
  303. endOfSubsection: false,
  304. })
  305. })
  306. })