Olivier Massot 4 месяцев назад
Родитель
Сommit
b40bbb1048

+ 1 - 0
tests/units/services/layout/menuBuilder/configurationMenuBuilder.test.ts

@@ -116,6 +116,7 @@ describe('build', () => {
         action === 'display' && subject === 'parameters_page',
     )
 
+    // @ts-expect-error accessing protected property for testing purposes
     menuBuilder.organizationProfile.id = 123
 
     const result = menuBuilder.build()

+ 62 - 82
tests/units/services/rights/abilityBuilder.test.ts

@@ -121,9 +121,7 @@ describe('buildAbilitiesFromConfig', () => {
 describe('hasConfigAbility', () => {
   beforeEach(() => {
     accessProfile.isGuardian = true
-    // @ts-ignore
     organizationProfile.isSchool = true
-    // @ts-ignore
     organizationProfile.isCmf = false
   })
   test('fulfill all conditions', () => {
@@ -158,7 +156,7 @@ describe('execAndValidateCondition', () => {
     })
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAllRoleAbilities',
         parameters: [
@@ -169,7 +167,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAllRoleAbilities',
         parameters: [
@@ -186,7 +184,7 @@ describe('execAndValidateCondition', () => {
     })
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAnyRoleAbility',
         parameters: [
@@ -197,7 +195,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAnyRoleAbility',
         parameters: [{ action: ABILITIES.READ, subject: 'subject2' }],
@@ -211,7 +209,7 @@ describe('execAndValidateCondition', () => {
     accessProfile.isPayer = true
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAnyProfile',
         parameters: ['guardian', 'payer'],
@@ -219,7 +217,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAnyProfile',
         parameters: ['guardian', 'caMember'],
@@ -227,7 +225,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessHasAnyProfile',
         parameters: ['caMember'],
@@ -236,13 +234,13 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationHasAllModules', () => {
-    // @ts-ignore
+    // @ts-expect-error for testing purposes
     organizationProfile.hasModule = vi.fn(
       (module: string) => module === 'module1' || module === 'module2',
     )
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasAllModules',
         parameters: ['module1', 'module2'],
@@ -250,7 +248,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasAllModules',
         parameters: ['module1', 'module3'],
@@ -258,7 +256,7 @@ describe('execAndValidateCondition', () => {
     ).toBeFalsy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasAllModules',
         parameters: ['module3'],
@@ -267,13 +265,13 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationHasAnyModule', () => {
-    // @ts-ignore
-    organizationProfile.hasModule = vi.fn(
+    // @ts-expect-error accessing non-existent property for testing purposes
+        organizationProfile.hasModule = vi.fn(
       (module: string) => module === 'module1' || module === 'module2',
     )
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasAnyModule',
         parameters: ['module1', 'module2'],
@@ -281,7 +279,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasAnyModule',
         parameters: ['module1', 'module3'],
@@ -289,7 +287,7 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasAnyModule',
         parameters: ['module3'],
@@ -298,19 +296,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationHasAnyModule', () => {
-    // @ts-ignore
     accessProfile.isAdminAccount = true
-    // @ts-ignore
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessIsAdminAccount',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
     accessProfile.isAdminAccount = false
-    // @ts-ignore
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'accessIsAdminAccount',
       }),
@@ -318,19 +314,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationIsSchool', () => {
-    // @ts-ignore
     organizationProfile.isSchool = true
-    // @ts-ignore
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsSchool',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.isSchool = false
-    // @ts-ignore
+        organizationProfile.isSchool = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsSchool',
       }),
@@ -338,19 +332,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationIsArtist', () => {
-    // @ts-ignore
-    organizationProfile.isArtist = true
-    // @ts-ignore
+        organizationProfile.isArtist = true
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsArtist',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.isArtist = false
-    // @ts-ignore
+        organizationProfile.isArtist = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsArtist',
       }),
@@ -358,19 +350,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationIsManagerProduct', () => {
-    // @ts-ignore
-    organizationProfile.isManagerProduct = true
-    // @ts-ignore
+        organizationProfile.isManagerProduct = true
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsManagerProduct',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.isManagerProduct = false
-    // @ts-ignore
+        organizationProfile.isManagerProduct = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsManagerProduct',
       }),
@@ -378,19 +368,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationHasChildren', () => {
-    // @ts-ignore
     organizationProfile.hasChildren = true
-    // @ts-ignore
     expect(
+    // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasChildren',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.hasChildren = false
-    // @ts-ignore
+        organizationProfile.hasChildren = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasChildren',
       }),
@@ -398,19 +386,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationIsAssociation', () => {
-    // @ts-ignore
-    organizationProfile.isAssociation = true
-    // @ts-ignore
+        organizationProfile.isAssociation = true
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsAssociation',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.isAssociation = false
-    // @ts-ignore
+        organizationProfile.isAssociation = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsAssociation',
       }),
@@ -418,19 +404,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationIsShowAdherentList', () => {
-    // @ts-ignore
-    organizationProfile.isShowAdherentList = true
-    // @ts-ignore
+        organizationProfile.isShowAdherentList = true
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsShowAdherentList',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.isShowAdherentList = false
-    // @ts-ignore
+        organizationProfile.isShowAdherentList = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsShowAdherentList',
       }),
@@ -438,19 +422,17 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationIsCmf', () => {
-    // @ts-ignore
-    organizationProfile.isCmf = true
-    // @ts-ignore
+        organizationProfile.isCmf = true
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsCmf',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
-    organizationProfile.isCmf = false
-    // @ts-ignore
+        organizationProfile.isCmf = false
     expect(
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationIsCmf',
       }),
@@ -458,19 +440,19 @@ describe('execAndValidateCondition', () => {
   })
 
   test('organizationHasWebsite', () => {
-    // @ts-ignore
+    // @ts-expect-error testing with intentionally wrong type
     organizationProfile.getWebsite = true
-    // @ts-ignore
     expect(
+    // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasWebsite',
       }),
     ).toBeTruthy()
 
-    // @ts-ignore
+    // @ts-expect-error testing with intentionally wrong type
     organizationProfile.getWebsite = false
-    // @ts-ignore
     expect(
+    // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasWebsite',
       }),
@@ -478,11 +460,11 @@ describe('execAndValidateCondition', () => {
   })
 
   test('with expected result', () => {
-    // @ts-ignore
+    // @ts-expect-error testing with intentionally wrong type
     organizationProfile.getWebsite = true
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasWebsite',
         expectedResult: true,
@@ -490,9 +472,10 @@ describe('execAndValidateCondition', () => {
     ).toBeTruthy()
 
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       abilityBuilder.execAndValidateCondition({
         function: 'organizationHasWebsite',
+        // @ts-expect-error testing with intentionally wrong type
         expectedResult: 'abc',
       }),
     ).toBeFalsy()
@@ -500,7 +483,7 @@ describe('execAndValidateCondition', () => {
 
   test('invalid function', () => {
     expect(
-      // @ts-ignore
+      // @ts-expect-error accessing protected method for testing purposes
       () => abilityBuilder.execAndValidateCondition({ function: 'invalid' }),
     ).toThrowError('unknown condition function : invalid')
   })
@@ -710,8 +693,7 @@ describe('hasAllProfiles', () => {
 
 describe('hasRole', () => {
   beforeEach(() => {
-    // @ts-ignore
-    accessProfile.hasRole = vi.fn((role: string) => role === 'foo')
+        accessProfile.hasRole = vi.fn((role: string) => role === 'foo')
   })
 
   test('has role', () => {
@@ -724,8 +706,7 @@ describe('hasRole', () => {
 
 describe('hasAnyRole', () => {
   beforeEach(() => {
-    // @ts-ignore
-    accessProfile.hasRole = vi.fn(
+        accessProfile.hasRole = vi.fn(
       (role: string) => role === 'role1' || role === 'role2',
     )
   })
@@ -745,8 +726,7 @@ describe('hasAnyRole', () => {
 
 describe('hasAllRoles', () => {
   beforeEach(() => {
-    // @ts-ignore
-    accessProfile.hasRole = vi.fn(
+        accessProfile.hasRole = vi.fn(
       (role: string) => role === 'role1' || role === 'role2',
     )
   })
@@ -766,8 +746,8 @@ describe('hasAllRoles', () => {
 
 describe('hasModule', () => {
   beforeEach(() => {
-    // @ts-ignore
-    organizationProfile.hasModule = vi.fn((module: string) => module === 'foo')
+    // @ts-expect-error accessing non-existent property for testing purposes
+        organizationProfile.hasModule = vi.fn((module: string) => module === 'foo')
   })
 
   test('has module', () => {
@@ -780,8 +760,8 @@ describe('hasModule', () => {
 
 describe('hasAnyModule', () => {
   beforeEach(() => {
-    // @ts-ignore
-    organizationProfile.hasModule = vi.fn(
+    // @ts-expect-error accessing non-existent property for testing purposes
+        organizationProfile.hasModule = vi.fn(
       (Module: string) => Module === 'Module1' || Module === 'Module2',
     )
   })
@@ -801,8 +781,8 @@ describe('hasAnyModule', () => {
 
 describe('hasAllModules', () => {
   beforeEach(() => {
-    // @ts-ignore
-    organizationProfile.hasModule = vi.fn(
+    // @ts-expect-error accessing non-existent property for testing purposes
+        organizationProfile.hasModule = vi.fn(
       (Module: string) => Module === 'Module1' || Module === 'Module2',
     )
   })

+ 5 - 4
tests/units/services/sse/sseSource.test.ts

@@ -1,6 +1,7 @@
 import { describe, test, it, expect, beforeEach, afterEach, vi } from 'vitest'
 import { EventSourcePolyfill } from 'event-source-polyfill'
 import SseSource from '~/services/sse/sseSource'
+import type { MercureEntityUpdate } from '~/types/interfaces'
 
 class TestableSseSource extends SseSource {
   public getUrl() {
@@ -23,7 +24,7 @@ class TestableSseSource extends SseSource {
     return this.withCredentials
   }
 
-  public createEventSource(
+  public override createEventSource(
     url: string,
     withCredentials: boolean,
   ): EventSourcePolyfill {
@@ -38,7 +39,7 @@ class TestableSseSource extends SseSource {
 let mercureUrl: string
 let topic: string
 let onOpen: () => any
-let onMessage: (data: Array<any>) => any
+let onMessage: (data: MercureEntityUpdate) => any
 let onClose: () => any
 let sseSource: TestableSseSource
 
@@ -49,7 +50,7 @@ beforeEach(() => {
   topic = 'mytopic'
 
   onOpen = () => 'opened'
-  onMessage = (data: Array<any>) => 'message'
+  onMessage = (data: MercureEntityUpdate) => 'message'
   onClose = () => 'closed'
 
   sseSource = new TestableSseSource(
@@ -135,7 +136,7 @@ describe('subscribe', () => {
   })
   test('successful subscription', () => {
     onOpen = vi.fn(() => null)
-    onMessage = vi.fn((data: Array<any>) => null)
+    onMessage = vi.fn((data: MercureEntityUpdate) => null)
 
     sseSource = new TestableSseSource(
       mercureUrl,