cotisationsMenuBuilder.test.ts 10 KB

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