ticket-articles.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. import { nullableMock } from '#tests/support/utils.ts'
  3. import {
  4. EnumTicketArticleSenderName,
  5. type TicketArticlesQuery,
  6. } from '#shared/graphql/types.ts'
  7. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  8. import type { LastArrayElement } from 'type-fest'
  9. export const mockTicketCreateAtDate = new Date(2011, 11, 11, 11, 11, 11, 11)
  10. export const defaultAuthor = {
  11. __typename: 'User',
  12. id: '11',
  13. firstname: 'Author',
  14. lastname: 'Joe',
  15. fullname: 'Author Joe',
  16. active: true,
  17. image: null,
  18. authorizations: [],
  19. }
  20. export const defaultFromAddress = {
  21. __typename: 'AddressesField',
  22. raw: 'Nicole Braun <nicole.braun@zammad.org>',
  23. parsed: [
  24. {
  25. __typename: 'EmailAddressParsed',
  26. name: 'Nicole Braun',
  27. emailAddress: 'nicole.braun@zammad.org',
  28. isSystemAddress: false,
  29. },
  30. ],
  31. }
  32. export const defaultBodyWithUrls = '<p>Default test body</p>'
  33. type ArticleNode = LastArrayElement<
  34. TicketArticlesQuery['articles']['edges']
  35. >['node']
  36. export const createDummyArticle = (options?: {
  37. articleId?: number
  38. from?: ArticleNode['from']
  39. author?: ArticleNode['author']
  40. internal?: ArticleNode['internal']
  41. bodyWithUrls?: ArticleNode['bodyWithUrls']
  42. to?: ArticleNode['to']
  43. cc?: ArticleNode['cc']
  44. replyTo?: ArticleNode['replyTo']
  45. subject?: ArticleNode['subject']
  46. articleType?: string
  47. attachmentsWithoutInline?: ArticleNode['attachmentsWithoutInline']
  48. contentType?: ArticleNode['contentType']
  49. securityState?: ArticleNode['securityState']
  50. senderName?: EnumTicketArticleSenderName
  51. mediaErrorState?: ArticleNode['mediaErrorState']
  52. preferences?: ArticleNode['preferences']
  53. detectedLanguage?: ArticleNode['detectedLanguage']
  54. // eslint-disable-next-line sonarjs/cognitive-complexity
  55. }) => {
  56. return nullableMock({
  57. __typename: 'TicketArticle',
  58. id: convertToGraphQLId('TicketArticle', options?.articleId || 1),
  59. internalId: options?.articleId || 1,
  60. from: options?.from === undefined ? defaultFromAddress : options?.from,
  61. messageId: null,
  62. to: options?.to === undefined ? null : options?.to,
  63. cc: options?.cc === undefined ? null : options?.cc,
  64. subject: options?.subject === undefined ? null : options?.subject,
  65. replyTo: options?.replyTo || null,
  66. messageIdMd5: null,
  67. contentType: options?.contentType || 'text/plain',
  68. references: null,
  69. attachmentsWithoutInline: options?.attachmentsWithoutInline || [],
  70. preferences: options?.preferences || {},
  71. bodyWithUrls: options?.bodyWithUrls || defaultBodyWithUrls,
  72. internal: !!options?.internal,
  73. createdAt: mockTicketCreateAtDate.toISOString(),
  74. author: options?.author === undefined ? defaultAuthor : options?.author,
  75. type: {
  76. __typename: 'TicketArticleType',
  77. name: options?.articleType || 'string',
  78. },
  79. sender: {
  80. __typename: 'TicketArticleSender',
  81. name: options?.senderName || EnumTicketArticleSenderName.Customer,
  82. },
  83. securityState:
  84. options?.securityState === undefined ? null : options.securityState,
  85. mediaErrorState:
  86. options?.mediaErrorState === undefined ? null : options.mediaErrorState,
  87. detectedLanguage: options?.detectedLanguage ?? null,
  88. }) as ArticleNode
  89. }