useTicketView.spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import { generateObjectData } from '#tests/graphql/builders/index.ts'
  4. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  5. import type { Ticket } from '#shared/graphql/types.ts'
  6. import { useTicketView } from '../useTicketView.ts'
  7. const ticketDefault = generateObjectData<Ticket>('Ticket')
  8. const ticket = ref<Ticket | undefined>(ticketDefault)
  9. describe('useTicketView', () => {
  10. it('check agent permission', () => {
  11. mockPermissions([])
  12. const { isTicketAgent, isTicketCustomer } = useTicketView(ticket)
  13. expect(isTicketAgent.value).toBe(false)
  14. expect(isTicketCustomer.value).toBe(false)
  15. mockPermissions(['ticket.agent'])
  16. ticket.value!.policy.agentReadAccess = true
  17. expect(isTicketAgent.value).toBe(true)
  18. expect(isTicketCustomer.value).toBe(false)
  19. })
  20. it('check customer permissions', () => {
  21. mockPermissions(['ticket.customer'])
  22. ticket.value!.policy.agentReadAccess = false
  23. const { isTicketAgent, isTicketCustomer } = useTicketView(ticket)
  24. expect(isTicketAgent.value).toBe(false)
  25. expect(isTicketCustomer.value).toBe(true)
  26. })
  27. it('check ticket editable state', async () => {
  28. const { isTicketEditable } = useTicketView(ticket)
  29. expect(isTicketEditable.value).toBe(true)
  30. ticket.value = {
  31. ...ticketDefault,
  32. policy: {
  33. ...ticketDefault.policy,
  34. __typename: 'PolicyTicket',
  35. update: false,
  36. agentReadAccess: true,
  37. },
  38. }
  39. expect(isTicketEditable.value).toBe(false)
  40. ticket.value = undefined
  41. expect(isTicketEditable.value).toBe(false)
  42. })
  43. })