ticket.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { nullableMock } from '#tests/support/utils.ts'
  3. import type { TicketQuery } from '#shared/graphql/types.ts'
  4. import { EnumTicketStateColorCode } from '#shared/graphql/types.ts'
  5. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  6. export const mockTicketCreateDate = new Date(2011, 11, 11, 11, 11, 11, 11)
  7. export const mockTicketUpdateDate = new Date(2011, 12, 12, 12, 12, 12, 12)
  8. export const defaultOwner = {
  9. __typename: 'User',
  10. id: convertToGraphQLId('User', 1),
  11. internalId: 1,
  12. firstname: 'Foo',
  13. lastname: 'Test',
  14. }
  15. export const defaultOrganization = {
  16. __typename: 'Organization',
  17. id: convertToGraphQLId('Organization', 1),
  18. internalId: 1,
  19. name: 'Zammad Foundation',
  20. vip: false,
  21. active: true,
  22. }
  23. export const defaultCustomer = {
  24. __typename: 'User',
  25. id: convertToGraphQLId('User', 2),
  26. internalId: 2,
  27. firstname: 'Nicole',
  28. lastname: 'Braun',
  29. fullname: 'Nicole Braun',
  30. phone: '',
  31. mobile: '',
  32. image: null,
  33. vip: false,
  34. active: true,
  35. outOfOffice: false,
  36. outOfOfficeStartAt: null,
  37. outOfOfficeEndAt: null,
  38. email: 'nicole.braun@zammad.org',
  39. organization: {
  40. __typename: 'Organization',
  41. id: convertToGraphQLId('Organization', 1),
  42. internalId: 1,
  43. name: 'Zammad Foundation',
  44. active: true,
  45. objectAttributeValues: [],
  46. },
  47. hasSecondaryOrganizations: true,
  48. policy: { __typename: 'PolicyDefault', update: true },
  49. }
  50. export const defaultState = {
  51. __typename: 'TicketState',
  52. id: convertToGraphQLId('Ticket::State', 2),
  53. name: 'open',
  54. stateType: {
  55. __typename: 'TicketStateType',
  56. name: 'open',
  57. },
  58. }
  59. export const defaultGroup = {
  60. __typename: 'Group',
  61. id: convertToGraphQLId('Group', 2),
  62. name: 'Test Agents',
  63. emailAddress: null,
  64. sharedDrafts: true,
  65. }
  66. export const defaultPriority = {
  67. __typename: 'TicketPriority',
  68. id: 'gid://zammad/Ticket::Priority/2',
  69. name: '2 normal',
  70. defaultCreate: true,
  71. uiColor: null,
  72. }
  73. export const defaultPolicy = {
  74. __typename: 'PolicyTicket',
  75. update: true,
  76. agentReadAccess: true,
  77. }
  78. export const defaultMentions = {
  79. __typename: 'Mentions',
  80. totalCount: 0,
  81. edges: [],
  82. }
  83. /**
  84. * Options: can be expanded
  85. * Make sure to set old values as defaults to be backwards compatible
  86. * * */
  87. export const createDummyTicket = <R = TicketQuery['ticket']>(options?: {
  88. ticketId?: string
  89. owner?: TicketQuery['ticket']['owner']
  90. customer?: TicketQuery['ticket']['customer']
  91. organization?: TicketQuery['ticket']['organization']
  92. state?: TicketQuery['ticket']['state']
  93. articleType?: string
  94. group?: TicketQuery['ticket']['group']
  95. defaultPriority?: TicketQuery['ticket']['priority']
  96. defaultPolicy?: TicketQuery['ticket']['policy']
  97. mentions?: TicketQuery['ticket']['mentions']
  98. colorCode?: EnumTicketStateColorCode
  99. title?: TicketQuery['ticket']['title']
  100. number?: TicketQuery['ticket']['number']
  101. checklist?: TicketQuery['ticket']['checklist']
  102. referencingChecklistTickets?: TicketQuery['ticket']['referencingChecklistTickets']
  103. tags?: string[]
  104. // eslint-disable-next-line sonarjs/cognitive-complexity
  105. }): R => {
  106. return nullableMock({
  107. __typename: 'Ticket',
  108. createArticleType: {
  109. __typename: 'TicketArticleType',
  110. id: convertToGraphQLId('Ticket::Article', 5),
  111. name: options?.articleType || 'email',
  112. },
  113. id: convertToGraphQLId('Ticket', options?.ticketId || 1),
  114. internalId: options?.ticketId || 1,
  115. number: options?.number || '89002',
  116. title: options?.title || 'Test Ticket',
  117. createdAt: mockTicketCreateDate.toISOString(),
  118. escalationAt: null,
  119. updatedAt: mockTicketUpdateDate.toISOString(),
  120. pendingTime: null,
  121. owner: options?.owner === undefined ? defaultOwner : options?.owner,
  122. customer:
  123. options?.customer === undefined ? defaultCustomer : options?.customer,
  124. organization:
  125. options?.organization === undefined
  126. ? defaultOrganization
  127. : options?.organization,
  128. state: options?.state === undefined ? defaultState : options?.state,
  129. group: options?.group === undefined ? defaultGroup : options?.group,
  130. priority:
  131. options?.defaultPriority === undefined
  132. ? defaultPriority
  133. : options?.defaultPriority,
  134. objectAttributeValues: [],
  135. policy:
  136. options?.defaultPolicy === undefined
  137. ? defaultPolicy
  138. : options?.defaultPolicy,
  139. tags: options?.tags || [],
  140. timeUnit: null,
  141. timeUnitsPerType: [],
  142. subscribed: false,
  143. preferences: {},
  144. stateColorCode: options?.colorCode || EnumTicketStateColorCode.Open,
  145. firstResponseEscalationAt: null,
  146. closeEscalationAt: null,
  147. updateEscalationAt: null,
  148. initialChannel: null,
  149. mentions: options?.mentions || defaultMentions,
  150. checklist: options?.checklist || null,
  151. referencingChecklistTickets: options?.referencingChecklistTickets || [],
  152. }) as R
  153. }