cotisationsMenuBuilder.test.ts 9.5 KB

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