useEmailFileUrls.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import { useEmailFileUrls } from '#shared/composables/useEmailFileUrls.ts'
  4. import { createDummyArticle } from '#shared/entities/ticket-article/__tests__/mocks/ticket-articles.ts'
  5. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  6. describe('useEmailFileUrls', () => {
  7. it('should return originalFormattingUrl and rawMessageUrl for email articles', () => {
  8. const { originalFormattingUrl, rawMessageUrl } = useEmailFileUrls(
  9. ref(
  10. createDummyArticle({
  11. articleType: 'email',
  12. attachmentsWithoutInline: [
  13. {
  14. id: convertToGraphQLId('Store', 123),
  15. preferences: {
  16. 'original-format': true,
  17. },
  18. internalId: 123,
  19. name: 'test.txt',
  20. },
  21. ],
  22. }),
  23. ),
  24. ref(222),
  25. )
  26. expect(originalFormattingUrl.value).toBe(
  27. '/api/v1/ticket_attachment/222/1/123?disposition=attachment',
  28. )
  29. expect(rawMessageUrl.value).toBe('/api/v1/ticket_article_plain/1')
  30. })
  31. it('should return only rawMessageUrl for email articles without original format attachment', () => {
  32. const { originalFormattingUrl, rawMessageUrl } = useEmailFileUrls(
  33. ref(
  34. createDummyArticle({
  35. articleType: 'email',
  36. }),
  37. ),
  38. ref(222),
  39. )
  40. expect(originalFormattingUrl.value).toBeUndefined()
  41. expect(rawMessageUrl.value).toBe('/api/v1/ticket_article_plain/1')
  42. })
  43. it('should return nothing for other article types', () => {
  44. const { originalFormattingUrl, rawMessageUrl } = useEmailFileUrls(
  45. ref(createDummyArticle()),
  46. ref(222),
  47. )
  48. expect(originalFormattingUrl.value).toBeUndefined()
  49. expect(rawMessageUrl.value).toBeUndefined()
  50. })
  51. })