online-notification-mocks.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { nullableMock } from '#tests/support/utils.ts'
  3. import type {
  4. OnlineNotificationsQuery,
  5. Scalars,
  6. } from '#shared/graphql/types.ts'
  7. import type { LastArrayElement } from 'type-fest'
  8. type OnlineNotificationNode = LastArrayElement<
  9. OnlineNotificationsQuery['onlineNotifications']['edges']
  10. >['node']
  11. export const mockOnlineNotification = (
  12. id: Scalars['ID']['output'],
  13. mockNotification: Partial<OnlineNotificationNode>,
  14. ): OnlineNotificationNode => {
  15. return {
  16. __typename: 'OnlineNotification',
  17. seen: false,
  18. createdAt: new Date().toISOString(),
  19. createdBy: {
  20. id: '123',
  21. fullname: 'Full Name',
  22. lastname: 'Name',
  23. firstname: 'Full',
  24. email: 'email@example.org',
  25. vip: false,
  26. outOfOffice: false,
  27. active: true,
  28. image: null,
  29. },
  30. typeName: 'update',
  31. objectName: 'Ticket',
  32. metaObject: {
  33. __typename: 'Ticket',
  34. id: '111',
  35. internalId: 111,
  36. title: 'Ticket Title',
  37. },
  38. id,
  39. ...mockNotification,
  40. }
  41. }
  42. export const mockOnlineNotificationQuery = (
  43. mockNotifications: Array<Partial<OnlineNotificationNode>>,
  44. ): OnlineNotificationsQuery => {
  45. const edges = mockNotifications.map((item, index) => {
  46. const id = index + 1
  47. return {
  48. cursor: `node${id}`,
  49. node: mockOnlineNotification(id.toString(), item),
  50. }
  51. })
  52. return nullableMock<OnlineNotificationsQuery>({
  53. onlineNotifications: {
  54. edges,
  55. pageInfo: {
  56. endCursor: edges.at(-1)?.cursor || null,
  57. hasNextPage: false,
  58. },
  59. },
  60. })
  61. }