ticket-articles.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (C) 2012-2024 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. // eslint-disable-next-line sonarjs/cognitive-complexity
  54. }) => {
  55. return nullableMock({
  56. __typename: 'TicketArticle',
  57. id: convertToGraphQLId('TicketArticle', options?.articleId || 1),
  58. internalId: options?.articleId || 1,
  59. from: options?.from === undefined ? defaultFromAddress : options?.from,
  60. messageId: null,
  61. to: options?.to === undefined ? null : options?.to,
  62. cc: options?.cc === undefined ? null : options?.cc,
  63. subject: options?.subject === undefined ? null : options?.subject,
  64. replyTo: options?.replyTo || null,
  65. messageIdMd5: null,
  66. contentType: options?.contentType || 'text/plain',
  67. references: null,
  68. attachmentsWithoutInline: options?.attachmentsWithoutInline || [],
  69. preferences: options?.preferences || {},
  70. bodyWithUrls: options?.bodyWithUrls || defaultBodyWithUrls,
  71. internal: !!options?.internal,
  72. createdAt: mockTicketCreateAtDate.toISOString(),
  73. author: options?.author === undefined ? defaultAuthor : options?.author,
  74. type: {
  75. __typename: 'TicketArticleType',
  76. name: options?.articleType || 'string',
  77. },
  78. sender: {
  79. __typename: 'TicketArticleSender',
  80. name: options?.senderName || EnumTicketArticleSenderName.Customer,
  81. },
  82. securityState:
  83. options?.securityState === undefined ? null : options.securityState,
  84. mediaErrorState:
  85. options?.mediaErrorState === undefined ? null : options.mediaErrorState,
  86. }) as ArticleNode
  87. }