ticket.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright (C) 2012-2025 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. id: convertToGraphQLId('Ticket::StateType', 2),
  57. name: 'open',
  58. },
  59. }
  60. export const defaultGroup = {
  61. __typename: 'Group',
  62. id: convertToGraphQLId('Group', 2),
  63. name: 'Test Agents',
  64. emailAddress: null,
  65. sharedDrafts: true,
  66. }
  67. export const defaultPriority = {
  68. __typename: 'TicketPriority',
  69. id: 'gid://zammad/Ticket::Priority/2',
  70. name: '2 normal',
  71. defaultCreate: true,
  72. uiColor: null,
  73. }
  74. export const defaultPolicy = {
  75. __typename: 'PolicyTicket',
  76. update: true,
  77. agentReadAccess: true,
  78. }
  79. export const defaultMentions = {
  80. __typename: 'Mentions',
  81. totalCount: 0,
  82. edges: [],
  83. }
  84. /**
  85. * Options: can be expanded
  86. * Make sure to set old values as defaults to be backwards compatible
  87. * * */
  88. export const createDummyTicket = <R = TicketQuery['ticket']>(options?: {
  89. ticketId?: string
  90. owner?: TicketQuery['ticket']['owner']
  91. customer?: TicketQuery['ticket']['customer']
  92. organization?: TicketQuery['ticket']['organization']
  93. state?: TicketQuery['ticket']['state']
  94. articleType?: string
  95. group?: TicketQuery['ticket']['group']
  96. defaultPriority?: TicketQuery['ticket']['priority']
  97. defaultPolicy?: TicketQuery['ticket']['policy']
  98. mentions?: TicketQuery['ticket']['mentions']
  99. subscribed?: TicketQuery['ticket']['subscribed']
  100. colorCode?: EnumTicketStateColorCode
  101. title?: TicketQuery['ticket']['title']
  102. number?: TicketQuery['ticket']['number']
  103. checklist?: TicketQuery['ticket']['checklist']
  104. referencingChecklistTickets?: TicketQuery['ticket']['referencingChecklistTickets']
  105. timeUnit?: TicketQuery['ticket']['timeUnit']
  106. timeUnitsPerType?: TicketQuery['ticket']['timeUnitsPerType']
  107. tags?: string[]
  108. externalReferences?: TicketQuery['ticket']['externalReferences']
  109. preferences?: TicketQuery['ticket']['preferences']
  110. // eslint-disable-next-line sonarjs/cognitive-complexity
  111. }): R => {
  112. return nullableMock({
  113. __typename: 'Ticket',
  114. createArticleType: {
  115. __typename: 'TicketArticleType',
  116. id: convertToGraphQLId('Ticket::Article', 5),
  117. name: options?.articleType || 'email',
  118. },
  119. id: convertToGraphQLId('Ticket', options?.ticketId || 1),
  120. internalId: options?.ticketId || 1,
  121. number: options?.number || '89002',
  122. title: options?.title || 'Test Ticket',
  123. createdAt: mockTicketCreateDate.toISOString(),
  124. escalationAt: null,
  125. updatedAt: mockTicketUpdateDate.toISOString(),
  126. pendingTime: null,
  127. owner: options?.owner === undefined ? defaultOwner : options?.owner,
  128. customer:
  129. options?.customer === undefined ? defaultCustomer : options?.customer,
  130. organization:
  131. options?.organization === undefined
  132. ? defaultOrganization
  133. : options?.organization,
  134. state: options?.state === undefined ? defaultState : options?.state,
  135. group: options?.group === undefined ? defaultGroup : options?.group,
  136. priority:
  137. options?.defaultPriority === undefined
  138. ? defaultPriority
  139. : options?.defaultPriority,
  140. objectAttributeValues: [],
  141. policy:
  142. options?.defaultPolicy === undefined
  143. ? defaultPolicy
  144. : options?.defaultPolicy,
  145. tags: options?.tags || [],
  146. timeUnit: options?.timeUnit || null,
  147. timeUnitsPerType: options?.timeUnitsPerType || [],
  148. subscribed: options?.subscribed || false,
  149. preferences: options?.preferences || {},
  150. stateColorCode: options?.colorCode || EnumTicketStateColorCode.Open,
  151. firstResponseEscalationAt: null,
  152. closeEscalationAt: null,
  153. updateEscalationAt: null,
  154. externalReferences: options?.externalReferences,
  155. initialChannel: null,
  156. mentions: options?.mentions || defaultMentions,
  157. checklist: options?.checklist || null,
  158. referencingChecklistTickets: options?.referencingChecklistTickets || [],
  159. }) as R
  160. }