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