ticket.ts 4.3 KB

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