utils.spec.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import {
  3. convertToGraphQLId,
  4. isGraphQLId,
  5. ensureGraphqlId,
  6. parseGraphqlId,
  7. getIdFromGraphQLId,
  8. } from '../utils.ts'
  9. describe('isGraphQLId', () => {
  10. it('check for valid id', async () => {
  11. expect(isGraphQLId('gid://zammad/Organization/1')).toBe(true)
  12. })
  13. it('check for invalid id', async () => {
  14. expect(isGraphQLId('invalid')).toBe(false)
  15. })
  16. })
  17. describe('convertToGraphQLId', () => {
  18. it('check convertion', async () => {
  19. expect(convertToGraphQLId('Organization', 1)).toBe(
  20. 'gid://zammad/Organization/1',
  21. )
  22. })
  23. })
  24. describe('convertToGraphQLId', () => {
  25. it('check convertion', async () => {
  26. expect(convertToGraphQLId('Organization', 1)).toBe(
  27. 'gid://zammad/Organization/1',
  28. )
  29. })
  30. })
  31. describe('ensureGraphqlId', () => {
  32. it('check that we have always a GraphQL id', async () => {
  33. expect(ensureGraphqlId('Organization', 1)).toBe(
  34. 'gid://zammad/Organization/1',
  35. )
  36. })
  37. it('check that we have always a GraphQL id (also when it has the correct format)', async () => {
  38. expect(ensureGraphqlId('Organization', 'gid://zammad/Organization/1')).toBe(
  39. 'gid://zammad/Organization/1',
  40. )
  41. })
  42. })
  43. describe('getIdFromGraphQLId', () => {
  44. it('check that ID can parsed from graphqlId ', async () => {
  45. expect(getIdFromGraphQLId('gid://zammad/Organization/1')).toBe(1)
  46. })
  47. })
  48. describe('parseGraphqlId', () => {
  49. it('correctly parses graphqlId ', async () => {
  50. expect(parseGraphqlId('gid://zammad/Organization/1')).toEqual({
  51. relation: 'Organization',
  52. id: 1,
  53. })
  54. })
  55. })