| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import {Ability} from "@casl/ability";
- import {createStore} from "~/tests/unit/Helpers";
- import {AbilitiesType, AccessStore} from "~/types/interfaces";
- import {$accessProfile} from "~/services/profile/accessProfile";
- import {ABILITIES} from "~/types/enums";
- import {accessProfile as accessModule} from "~/tests/unit/fixture/state/profile"
- let ability: Ability, store:AccessStore, accessProfile:any
- beforeEach( ()=>{
- ability = new Ability();
- store = createStore()
- store.registerModule('profile',{})
- store.registerModule(['profile','access'], accessModule)
- accessProfile = $accessProfile(store, ability)
- })
- describe('hasRole()', () => {
- it('should return true if there is no role', () => {
- expect(accessProfile.hasRole(null)).toBeTruthy()
- })
- it('should return false if profile dont have the role', () =>{
- const role_to_have = ['ROLE_EVENT']
- expect(accessProfile.hasRole(role_to_have)).toBeFalsy()
- })
- it('should return true if profile have the role', () =>{
- const role_to_have = ['ROLE_USERS']
- store.commit('access/setRoles', ['ROLE_USERS'])
- expect(accessProfile.hasRole(role_to_have)).toBeTruthy()
- })
- })
- describe('hasAbility()', () => {
- it('should return true if there is no ability', () => {
- expect(accessProfile.hasAbility(null)).toBeTruthy()
- })
- it('should return false if profile dont have the ability', () =>{
- const ability_to_have:Array<AbilitiesType> = [{
- action: ABILITIES.MANAGE,
- subject: 'bills'
- }]
- expect(accessProfile.hasAbility(ability_to_have)).toBeFalsy()
- })
- it('should return true if profile dont have the ability', () =>{
- const manage_bills:AbilitiesType = {
- action: ABILITIES.MANAGE,
- subject: 'bills'
- }
- const ability_to_have:Array<AbilitiesType> = [manage_bills]
- ability.update([manage_bills])
- expect(accessProfile.hasAbility(ability_to_have)).toBeTruthy()
- })
- })
|