Skip to content

Commit

Permalink
feat: add guardss test
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen Branje <[email protected]>
  • Loading branch information
jeroenbranje committed Jan 25, 2024
1 parent 6825cd6 commit 5e862ff
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion apps/envited.ascs.digital/common/guards/guards.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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)
})
})
})

0 comments on commit 5e862ff

Please sign in to comment.