Skip to main content
Glama
errorMessageUtils.test.ts2.62 kB
/** * Tests for error message utilities */ import { getErrorMessage } from '../errorMessageUtils' describe('errorMessageUtils', () => { describe('getErrorMessage', () => { it('should return first error message when errorMessages array has content', () => { const errorData = { errorMessages: ['First error', 'Second error'], } const status = 404 const result = getErrorMessage(errorData, status) expect(result).toBe('Error: First error, Status: 404') }) it('should return default message when errorMessages array is empty', () => { const errorData = { errorMessages: [], } const status = 400 const result = getErrorMessage(errorData, status) expect(result).toBe('Failed to fetch Jira issue. Status: 400') }) it('should return default message when errorMessages is undefined', () => { const errorData = {} const status = 500 const result = getErrorMessage(errorData, status) expect(result).toBe('Failed to fetch Jira issue. Status: 500') }) it('should return default message when errorMessages is null', () => { const errorData = { errorMessages: null, } as any const status = 500 const result = getErrorMessage(errorData, status) expect(result).toBe('Failed to fetch Jira issue. Status: 500') }) it('should return default message when errorMessages is not an array', () => { const errorData = { errorMessages: 'Not an array', } as any const status = 403 const result = getErrorMessage(errorData, status) expect(result).toBe('Failed to fetch Jira issue. Status: 403') }) it('should handle array with length check independently', () => { // This tests the specific branch where Array.isArray() is true but the length check fails const errorDataWithEmptyArray = { errorMessages: [], } const status = 401 // Force Array.isArray to return true but length to be 0 jest.spyOn(Array, 'isArray').mockReturnValueOnce(true) const result = getErrorMessage(errorDataWithEmptyArray, status) expect(result).toBe('Failed to fetch Jira issue. Status: 401') }) it('should test optional chaining branch specifically', () => { // Create a custom array-like object that passes Array.isArray but has no length property const customArray = Object.create(Array.prototype) // This will pass Array.isArray check but the optional chaining will need to kick in const errorData = { errorMessages: customArray, } const status = 418 const result = getErrorMessage(errorData, status) expect(result).toBe('Failed to fetch Jira issue. Status: 418') }) }) })

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tbreeding/jira-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server