ticket.ts 5.1 KB

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