organizationProfile.spec.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {createStore} from "~/tests/unit/Helpers";
  2. import {$organizationProfile} from "~/services/profile/organizationProfile";
  3. import {organizationProfile as organizationModule} from "~/tests/unit/fixture/state/profile"
  4. import {OrganizationStore} from "~/types/interfaces";
  5. let store:OrganizationStore, organizationProfile:any
  6. beforeAll(()=>{
  7. process.env = {
  8. school_product: 'school',
  9. school_premium_product: 'school-premium',
  10. artist_product: 'artist',
  11. artist_premium_product: 'artist-premium',
  12. manager_product: 'manager',
  13. cmf_network: 'CMF',
  14. ffec_network: 'FFEC',
  15. }
  16. })
  17. beforeEach(()=>{
  18. store = createStore()
  19. store.registerModule('profile',{})
  20. store.registerModule(['profile','organization'], organizationModule)
  21. organizationProfile = $organizationProfile(store)
  22. })
  23. describe('hasModule()', () => {
  24. it('should return false if organization dont have one of the module', () => {
  25. expect(organizationProfile.hasModule(['PedagogicsAdministation'])).toBeFalsy()
  26. })
  27. it('should return true if organization have one of the module', () => {
  28. store.commit('organization/setModules', ['PedagogicsAdministation', 'Courses'])
  29. expect(organizationProfile.hasModule(['PedagogicsAdministation', 'Examens'])).toBeTruthy()
  30. })
  31. })
  32. describe('isInsideNetwork()', () => {
  33. it('should call isCmf function', ()=>{
  34. organizationProfile.isCmf = jest.fn()
  35. organizationProfile.isInsideNetwork()
  36. expect(organizationProfile.isCmf).toHaveBeenCalled();
  37. })
  38. it('should call isFfec function if isCmf return false', ()=>{
  39. organizationProfile.isCmf = jest.fn().mockReturnValue(false)
  40. organizationProfile.isFfec = jest.fn()
  41. organizationProfile.isInsideNetwork()
  42. expect(organizationProfile.isFfec).toHaveBeenCalled();
  43. })
  44. it('should return false if isCmf AND isFfec return false', ()=>{
  45. organizationProfile.isCmf = jest.fn().mockReturnValue(false)
  46. organizationProfile.isFfec = jest.fn().mockReturnValue(false)
  47. expect(organizationProfile.isInsideNetwork()).toBeFalsy()
  48. })
  49. it('should return true if isCmf OR Ffec return true', ()=>{
  50. organizationProfile.isCmf = jest.fn().mockReturnValue(true)
  51. expect(organizationProfile.isInsideNetwork()).toBeTruthy()
  52. organizationProfile.isCmf = jest.fn().mockReturnValue(false)
  53. organizationProfile.isFfec = jest.fn().mockReturnValue(true)
  54. expect(organizationProfile.isInsideNetwork()).toBeTruthy()
  55. })
  56. })
  57. describe('isCmf()', () => {
  58. it('should return false if the organization is not CMF', ()=>{
  59. expect(organizationProfile.isCmf()).toBeFalsy()
  60. })
  61. it('should return true if the organization is not CMF', ()=>{
  62. store.commit('organization/setNetworks', ['CMF'])
  63. expect(organizationProfile.isCmf()).toBeTruthy()
  64. })
  65. })
  66. describe('isFfec()', () => {
  67. it('should return false if the organization is not FFEC', ()=>{
  68. expect(organizationProfile.isFfec()).toBeFalsy()
  69. })
  70. it('should return true if the organization is not FFEC', ()=>{
  71. store.commit('organization/setNetworks', ['FFEC'])
  72. expect(organizationProfile.isFfec()).toBeTruthy()
  73. })
  74. })
  75. describe('isSchool()', () => {
  76. it('should call isSchoolProduct function', ()=>{
  77. organizationProfile.isSchoolProduct = jest.fn()
  78. organizationProfile.isSchool()
  79. expect(organizationProfile.isSchoolProduct).toHaveBeenCalled();
  80. })
  81. it('should call isSchoolPremiumProduct function if isSchool return false', ()=>{
  82. organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(false)
  83. organizationProfile.isSchoolPremiumProduct = jest.fn()
  84. organizationProfile.isSchool()
  85. expect(organizationProfile.isSchoolPremiumProduct).toHaveBeenCalled();
  86. })
  87. it('should return false if isSchoolProduct AND isSchoolPremiumProduct return false', ()=>{
  88. organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(false)
  89. organizationProfile.isSchoolPremiumProduct = jest.fn().mockReturnValue(false)
  90. expect(organizationProfile.isSchool()).toBeFalsy()
  91. })
  92. it('should return true if isSchoolProduct OR isSchoolPremiumProduct return true', ()=>{
  93. organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(true)
  94. expect(organizationProfile.isSchool()).toBeTruthy()
  95. organizationProfile.isSchoolProduct = jest.fn().mockReturnValue(false)
  96. organizationProfile.isSchoolPremiumProduct = jest.fn().mockReturnValue(true)
  97. expect(organizationProfile.isSchool()).toBeTruthy()
  98. })
  99. })
  100. describe('isArtist()', () => {
  101. it('should call isArtistProduct function', ()=>{
  102. organizationProfile.isArtistProduct = jest.fn()
  103. organizationProfile.isArtist()
  104. expect(organizationProfile.isArtistProduct).toHaveBeenCalled();
  105. })
  106. it('should call isArtistPremiumProduct function if isArtistProduct return false', ()=>{
  107. organizationProfile.isArtistProduct = jest.fn().mockReturnValue(false)
  108. organizationProfile.isArtistPremiumProduct = jest.fn()
  109. organizationProfile.isArtist()
  110. expect(organizationProfile.isArtistPremiumProduct).toHaveBeenCalled();
  111. })
  112. it('should return false if isArtistProduct AND isArtistPremiumProduct return false', ()=>{
  113. organizationProfile.isArtistProduct = jest.fn().mockReturnValue(false)
  114. organizationProfile.isArtistPremiumProduct = jest.fn().mockReturnValue(false)
  115. expect(organizationProfile.isArtist()).toBeFalsy()
  116. })
  117. it('should return true if isArtistProduct OR isArtistPremiumProduct return true', ()=>{
  118. organizationProfile.isArtistProduct = jest.fn().mockReturnValue(true)
  119. expect(organizationProfile.isArtist()).toBeTruthy()
  120. organizationProfile.isArtistProduct = jest.fn().mockReturnValue(false)
  121. organizationProfile.isArtistPremiumProduct = jest.fn().mockReturnValue(true)
  122. expect(organizationProfile.isArtist()).toBeTruthy()
  123. })
  124. })
  125. describe('isSchoolProduct()', () => {
  126. it('should return false if the organization dont have a shool product', ()=>{
  127. expect(organizationProfile.isSchoolProduct()).toBeFalsy()
  128. })
  129. it('should return true if the organization have a shool product', ()=>{
  130. store.commit('organization/setProduct', 'school')
  131. expect(organizationProfile.isSchoolProduct()).toBeTruthy()
  132. })
  133. })
  134. describe('isSchoolPremiumProduct()', () => {
  135. it('should return false if the organization dont have a shool premium product', ()=>{
  136. expect(organizationProfile.isSchoolPremiumProduct()).toBeFalsy()
  137. })
  138. it('should return true if the organization have a shool premium product', ()=>{
  139. store.commit('organization/setProduct', 'school-premium')
  140. expect(organizationProfile.isSchoolPremiumProduct()).toBeTruthy()
  141. })
  142. })
  143. describe('isArtistProduct()', () => {
  144. it('should return false if the organization dont have a artist product', ()=>{
  145. expect(organizationProfile.isArtistProduct()).toBeFalsy()
  146. })
  147. it('should return true if the organization have a artist product', ()=>{
  148. store.commit('organization/setProduct', 'artist')
  149. expect(organizationProfile.isArtistProduct()).toBeTruthy()
  150. })
  151. })
  152. describe('isArtistPremiumProduct()', () => {
  153. it('should return false if the organization dont have a artist premium product', ()=>{
  154. expect(organizationProfile.isArtistPremiumProduct()).toBeFalsy()
  155. })
  156. it('should return true if the organization have a artist premium product', ()=>{
  157. store.commit('organization/setProduct', 'artist-premium')
  158. expect(organizationProfile.isArtistPremiumProduct()).toBeTruthy()
  159. })
  160. })
  161. describe('isManagerProduct()', () => {
  162. it('should return false if the organization dont have a manager product', ()=>{
  163. expect(organizationProfile.isManagerProduct()).toBeFalsy()
  164. })
  165. it('should return true if the organization have a manager product', ()=>{
  166. store.commit('organization/setProduct', 'manager')
  167. expect(organizationProfile.isManagerProduct()).toBeTruthy()
  168. })
  169. })
  170. describe('isOrganizationWithChildren()', () => {
  171. it('should return false if the organization dont have children', ()=>{
  172. expect(organizationProfile.isOrganizationWithChildren()).toBeFalsy()
  173. })
  174. it('should return true if the organization have children', ()=>{
  175. store.commit('organization/setHasChildren', true)
  176. expect(organizationProfile.isOrganizationWithChildren()).toBeTruthy()
  177. })
  178. })