ticket.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. subscribed?: TicketQuery['ticket']['subscribed']
  99. colorCode?: EnumTicketStateColorCode
  100. title?: TicketQuery['ticket']['title']
  101. number?: TicketQuery['ticket']['number']
  102. checklist?: TicketQuery['ticket']['checklist']
  103. referencingChecklistTickets?: TicketQuery['ticket']['referencingChecklistTickets']
  104. timeUnit?: TicketQuery['ticket']['timeUnit']
  105. timeUnitsPerType?: TicketQuery['ticket']['timeUnitsPerType']
  106. tags?: string[]
  107. externalReferences?: TicketQuery['ticket']['externalReferences']
  108. preferences?: TicketQuery['ticket']['preferences']
  109. // eslint-disable-next-line sonarjs/cognitive-complexity
  110. }): R => {
  111. return nullableMock({
  112. __typename: 'Ticket',
  113. createArticleType: {
  114. __typename: 'TicketArticleType',
  115. id: convertToGraphQLId('Ticket::Article', 5),
  116. name: options?.articleType || 'email',
  117. },
  118. id: convertToGraphQLId('Ticket', options?.ticketId || 1),
  119. internalId: options?.ticketId || 1,
  120. number: options?.number || '89002',
  121. title: options?.title || 'Test Ticket',
  122. createdAt: mockTicketCreateDate.toISOString(),
  123. escalationAt: null,
  124. updatedAt: mockTicketUpdateDate.toISOString(),
  125. pendingTime: null,
  126. owner: options?.owner === undefined ? defaultOwner : options?.owner,
  127. customer:
  128. options?.customer === undefined ? defaultCustomer : options?.customer,
  129. organization:
  130. options?.organization === undefined
  131. ? defaultOrganization
  132. : options?.organization,
  133. state: options?.state === undefined ? defaultState : options?.state,
  134. group: options?.group === undefined ? defaultGroup : options?.group,
  135. priority:
  136. options?.defaultPriority === undefined
  137. ? defaultPriority
  138. : options?.defaultPriority,
  139. objectAttributeValues: [],
  140. policy:
  141. options?.defaultPolicy === undefined
  142. ? defaultPolicy
  143. : options?.defaultPolicy,
  144. tags: options?.tags || [],
  145. timeUnit: options?.timeUnit || null,
  146. timeUnitsPerType: options?.timeUnitsPerType || [],
  147. subscribed: options?.subscribed || false,
  148. preferences: options?.preferences || {},
  149. stateColorCode: options?.colorCode || EnumTicketStateColorCode.Open,
  150. firstResponseEscalationAt: null,
  151. closeEscalationAt: null,
  152. updateEscalationAt: null,
  153. externalReferences: options?.externalReferences,
  154. initialChannel: null,
  155. mentions: options?.mentions || defaultMentions,
  156. checklist: options?.checklist || null,
  157. referencingChecklistTickets: options?.referencingChecklistTickets || [],
  158. }) as R
  159. }