ErrorCodeTooltip.utils.test.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { ERROR_CODE_DOCS_URLS } from 'shared-data'
  2. import { describe, expect, it } from 'vitest'
  3. import { getErrorCodeInfo } from './ErrorCodeTooltip.utils'
  4. import { Service } from '@/data/graphql/graphql'
  5. describe('getErrorCodeInfo', () => {
  6. describe('when service is undefined', () => {
  7. it('returns no definition and no docsUrl', () => {
  8. const result = getErrorCodeInfo('bad_jwt', undefined)
  9. expect(result.definition).toBeUndefined()
  10. expect(result.docsUrl).toBeUndefined()
  11. })
  12. })
  13. describe('when service is Storage (not in shared-data)', () => {
  14. it('returns no definition and no docsUrl', () => {
  15. const result = getErrorCodeInfo('some_code', Service.Storage)
  16. expect(result.definition).toBeUndefined()
  17. expect(result.docsUrl).toBeUndefined()
  18. })
  19. })
  20. describe('auth service', () => {
  21. it('returns definition for a known error code', () => {
  22. const result = getErrorCodeInfo('bad_jwt', Service.Auth)
  23. expect(result.definition).toBeDefined()
  24. expect(result.definition?.description).toBeTypeOf('string')
  25. })
  26. it('returns the auth docs URL', () => {
  27. const result = getErrorCodeInfo('bad_jwt', Service.Auth)
  28. expect(result.docsUrl).toBe(ERROR_CODE_DOCS_URLS['auth'])
  29. })
  30. it('returns undefined definition for an unknown error code', () => {
  31. const result = getErrorCodeInfo('not_a_real_code', Service.Auth)
  32. expect(result.definition).toBeUndefined()
  33. })
  34. it('returns definition for a numeric HTTP error code', () => {
  35. const result = getErrorCodeInfo('429', Service.Auth)
  36. expect(result.definition).toBeDefined()
  37. expect(result.definition?.description).toBeTypeOf('string')
  38. })
  39. it('returns undefined for a numeric code not in HTTP_ERROR_CODES', () => {
  40. const result = getErrorCodeInfo('999', Service.Auth)
  41. expect(result.definition).toBeUndefined()
  42. })
  43. })
  44. describe('realtime service', () => {
  45. it('returns the realtime docs URL', () => {
  46. const result = getErrorCodeInfo('TopicNameRequired', Service.Realtime)
  47. expect(result.docsUrl).toBe(ERROR_CODE_DOCS_URLS['realtime'])
  48. })
  49. it('returns definition for a known realtime error code', () => {
  50. const result = getErrorCodeInfo('TopicNameRequired', Service.Realtime)
  51. expect(result.definition).toBeDefined()
  52. expect(result.definition?.description).toBeTypeOf('string')
  53. })
  54. it('returns undefined definition for an unknown realtime error code', () => {
  55. const result = getErrorCodeInfo('not_a_real_code', Service.Realtime)
  56. expect(result.definition).toBeUndefined()
  57. })
  58. })
  59. })