|
@@ -1,10 +1,7 @@
|
|
|
import { describe, test, expect, vi, beforeEach } from 'vitest'
|
|
import { describe, test, expect, vi, beforeEach } from 'vitest'
|
|
|
//@ts-expect-error false error
|
|
//@ts-expect-error false error
|
|
|
import type { MongoAbility } from '@casl/ability/dist/types/Ability'
|
|
import type { MongoAbility } from '@casl/ability/dist/types/Ability'
|
|
|
-import type {
|
|
|
|
|
- AbilitiesType,
|
|
|
|
|
- AccessProfile,
|
|
|
|
|
-} from '~/types/interfaces'
|
|
|
|
|
|
|
+import type { AbilitiesType, AccessProfile } from '~/types/interfaces'
|
|
|
import AbilityBuilder from '~/services/rights/abilityBuilder'
|
|
import AbilityBuilder from '~/services/rights/abilityBuilder'
|
|
|
import { ABILITIES } from '~/types/enum/enums'
|
|
import { ABILITIES } from '~/types/enum/enums'
|
|
|
import type OrganizationProfile from '~/models/Organization/OrganizationProfile'
|
|
import type OrganizationProfile from '~/models/Organization/OrganizationProfile'
|
|
@@ -266,7 +263,7 @@ describe('execAndValidateCondition', () => {
|
|
|
|
|
|
|
|
test('organizationHasAnyModule', () => {
|
|
test('organizationHasAnyModule', () => {
|
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
|
- organizationProfile.hasModule = vi.fn(
|
|
|
|
|
|
|
+ organizationProfile.hasModule = vi.fn(
|
|
|
(module: string) => module === 'module1' || module === 'module2',
|
|
(module: string) => module === 'module1' || module === 'module2',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -322,7 +319,7 @@ describe('execAndValidateCondition', () => {
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.isSchool = false
|
|
|
|
|
|
|
+ organizationProfile.isSchool = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -332,7 +329,7 @@ describe('execAndValidateCondition', () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('organizationIsArtist', () => {
|
|
test('organizationIsArtist', () => {
|
|
|
- organizationProfile.isArtist = true
|
|
|
|
|
|
|
+ organizationProfile.isArtist = true
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -340,7 +337,7 @@ describe('execAndValidateCondition', () => {
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.isArtist = false
|
|
|
|
|
|
|
+ organizationProfile.isArtist = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -350,7 +347,7 @@ describe('execAndValidateCondition', () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('organizationIsManagerProduct', () => {
|
|
test('organizationIsManagerProduct', () => {
|
|
|
- organizationProfile.isManagerProduct = true
|
|
|
|
|
|
|
+ organizationProfile.isManagerProduct = true
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -358,7 +355,7 @@ describe('execAndValidateCondition', () => {
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.isManagerProduct = false
|
|
|
|
|
|
|
+ organizationProfile.isManagerProduct = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -370,13 +367,13 @@ describe('execAndValidateCondition', () => {
|
|
|
test('organizationHasChildren', () => {
|
|
test('organizationHasChildren', () => {
|
|
|
organizationProfile.hasChildren = true
|
|
organizationProfile.hasChildren = true
|
|
|
expect(
|
|
expect(
|
|
|
- // @ts-expect-error accessing protected method for testing purposes
|
|
|
|
|
|
|
+ // @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
|
function: 'organizationHasChildren',
|
|
function: 'organizationHasChildren',
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.hasChildren = false
|
|
|
|
|
|
|
+ organizationProfile.hasChildren = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -386,7 +383,7 @@ describe('execAndValidateCondition', () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('organizationIsAssociation', () => {
|
|
test('organizationIsAssociation', () => {
|
|
|
- organizationProfile.isAssociation = true
|
|
|
|
|
|
|
+ organizationProfile.isAssociation = true
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -394,7 +391,7 @@ describe('execAndValidateCondition', () => {
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.isAssociation = false
|
|
|
|
|
|
|
+ organizationProfile.isAssociation = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -404,7 +401,7 @@ describe('execAndValidateCondition', () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('organizationIsShowAdherentList', () => {
|
|
test('organizationIsShowAdherentList', () => {
|
|
|
- organizationProfile.isShowAdherentList = true
|
|
|
|
|
|
|
+ organizationProfile.isShowAdherentList = true
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -412,7 +409,7 @@ describe('execAndValidateCondition', () => {
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.isShowAdherentList = false
|
|
|
|
|
|
|
+ organizationProfile.isShowAdherentList = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -422,7 +419,7 @@ describe('execAndValidateCondition', () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('organizationIsCmf', () => {
|
|
test('organizationIsCmf', () => {
|
|
|
- organizationProfile.isCmf = true
|
|
|
|
|
|
|
+ organizationProfile.isCmf = true
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -430,7 +427,7 @@ describe('execAndValidateCondition', () => {
|
|
|
}),
|
|
}),
|
|
|
).toBeTruthy()
|
|
).toBeTruthy()
|
|
|
|
|
|
|
|
- organizationProfile.isCmf = false
|
|
|
|
|
|
|
+ organizationProfile.isCmf = false
|
|
|
expect(
|
|
expect(
|
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
// @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
@@ -442,7 +439,7 @@ describe('execAndValidateCondition', () => {
|
|
|
test('organizationHasWebsite', () => {
|
|
test('organizationHasWebsite', () => {
|
|
|
organizationProfile.getWebsite = 'https://example.com'
|
|
organizationProfile.getWebsite = 'https://example.com'
|
|
|
expect(
|
|
expect(
|
|
|
- // @ts-expect-error accessing protected method for testing purposes
|
|
|
|
|
|
|
+ // @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
|
function: 'organizationHasWebsite',
|
|
function: 'organizationHasWebsite',
|
|
|
}),
|
|
}),
|
|
@@ -450,7 +447,7 @@ describe('execAndValidateCondition', () => {
|
|
|
|
|
|
|
|
organizationProfile.getWebsite = null
|
|
organizationProfile.getWebsite = null
|
|
|
expect(
|
|
expect(
|
|
|
- // @ts-expect-error accessing protected method for testing purposes
|
|
|
|
|
|
|
+ // @ts-expect-error accessing protected method for testing purposes
|
|
|
abilityBuilder.execAndValidateCondition({
|
|
abilityBuilder.execAndValidateCondition({
|
|
|
function: 'organizationHasWebsite',
|
|
function: 'organizationHasWebsite',
|
|
|
}),
|
|
}),
|
|
@@ -690,7 +687,7 @@ describe('hasAllProfiles', () => {
|
|
|
|
|
|
|
|
describe('hasRole', () => {
|
|
describe('hasRole', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- accessProfile.hasRole = vi.fn((role: string) => role === 'foo')
|
|
|
|
|
|
|
+ accessProfile.hasRole = vi.fn((role: string) => role === 'foo')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('has role', () => {
|
|
test('has role', () => {
|
|
@@ -703,7 +700,7 @@ describe('hasRole', () => {
|
|
|
|
|
|
|
|
describe('hasAnyRole', () => {
|
|
describe('hasAnyRole', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- accessProfile.hasRole = vi.fn(
|
|
|
|
|
|
|
+ accessProfile.hasRole = vi.fn(
|
|
|
(role: string) => role === 'role1' || role === 'role2',
|
|
(role: string) => role === 'role1' || role === 'role2',
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -723,7 +720,7 @@ describe('hasAnyRole', () => {
|
|
|
|
|
|
|
|
describe('hasAllRoles', () => {
|
|
describe('hasAllRoles', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- accessProfile.hasRole = vi.fn(
|
|
|
|
|
|
|
+ accessProfile.hasRole = vi.fn(
|
|
|
(role: string) => role === 'role1' || role === 'role2',
|
|
(role: string) => role === 'role1' || role === 'role2',
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -744,7 +741,7 @@ describe('hasAllRoles', () => {
|
|
|
describe('hasModule', () => {
|
|
describe('hasModule', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
|
- organizationProfile.hasModule = vi.fn((module: string) => module === 'foo')
|
|
|
|
|
|
|
+ organizationProfile.hasModule = vi.fn((module: string) => module === 'foo')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test('has module', () => {
|
|
test('has module', () => {
|
|
@@ -758,7 +755,7 @@ describe('hasModule', () => {
|
|
|
describe('hasAnyModule', () => {
|
|
describe('hasAnyModule', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
|
- organizationProfile.hasModule = vi.fn(
|
|
|
|
|
|
|
+ organizationProfile.hasModule = vi.fn(
|
|
|
(Module: string) => Module === 'Module1' || Module === 'Module2',
|
|
(Module: string) => Module === 'Module1' || Module === 'Module2',
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -779,7 +776,7 @@ describe('hasAnyModule', () => {
|
|
|
describe('hasAllModules', () => {
|
|
describe('hasAllModules', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
// @ts-expect-error accessing non-existent property for testing purposes
|
|
|
- organizationProfile.hasModule = vi.fn(
|
|
|
|
|
|
|
+ organizationProfile.hasModule = vi.fn(
|
|
|
(Module: string) => Module === 'Module1' || Module === 'Module2',
|
|
(Module: string) => Module === 'Module1' || Module === 'Module2',
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|