diff --git a/apps/envited.ascs.digital/common/guards/guards.test.ts b/apps/envited.ascs.digital/common/guards/guards.test.ts index ee66f96f..e0fb92e7 100644 --- a/apps/envited.ascs.digital/common/guards/guards.test.ts +++ b/apps/envited.ascs.digital/common/guards/guards.test.ts @@ -1,5 +1,5 @@ import { USER_CREDENTIAL } from '../../common/fixtures' -import { Session, User } from '../types' +import { Role, Session, User } from '../types' import * as SUT from './guards' describe('common/guards', () => { @@ -42,4 +42,43 @@ describe('common/guards', () => { expect(result).toEqual(true) }) }) + + describe('isFederator', () => { + it.each([ + [Role.federator, true], + [Role.principal, false], + ])('should check if logged in user is a federator', (role, expected) => { + // when ... we want to check if the user has the federator role + const session = { + user: { + pkh: 'PKH', + role, + }, + } + // then ... we should get the result as expected + const result = SUT.isFederator(session as Session) + + expect(result).toEqual(expected) + }) + }) + + describe('isPrincipal', () => { + it.each([ + [Role.federator, false], + [Role.principal, true], + [Role.user, false], + ])('should check if logged in user is a principal', (role, expected) => { + // when ... we want to check if the user has the principal + const session = { + user: { + pkh: 'PKH', + role, + }, + } + // then ... we should get the result as expected + const result = SUT.isPrincipal(session as Session) + + expect(result).toEqual(expected) + }) + }) })