Skip to main content
Glama
createGetIssueChangeLogs.test.ts2.52 kB
import { Failure, Success } from '../../../../utils/try' import { callJiraApi, RestMethod } from '../../callJiraApi' import createGetIssueChangeLogs from '../createGetIssueChangeLogs' import type { IssueChangeLogResponseBody } from '../../../types/issue.types' import type { JiraApiConfig } from '../../apiTypes' // Mock the callJiraApi function jest.mock('../../callJiraApi') const mockedCallJiraApi = callJiraApi as jest.MockedFunction<typeof callJiraApi> describe('createGetIssueChangeLogs', () => { const mockConfig: JiraApiConfig = { baseUrl: 'https://jira.example.com', username: 'testuser', apiToken: 'test-token', } const issueIdOrKey = 'TEST-123' const mockResponse: IssueChangeLogResponseBody = { self: 'https://jira.example.com/rest/api/3/issue/TEST-123/changelog', values: [], startAt: 0, maxResults: 50, total: 0, isLast: true, } beforeEach(() => { jest.clearAllMocks() }) test('should return successful response when API call succeeds', async () => { // Setup mockedCallJiraApi.mockResolvedValue(Success(mockResponse)) // Execute const getIssueChangeLogs = createGetIssueChangeLogs(mockConfig, issueIdOrKey) const result = await getIssueChangeLogs() // Verify expect(mockedCallJiraApi).toHaveBeenCalledWith({ endpoint: `/rest/api/3/issue/${issueIdOrKey}/changelog?maxResults=50&startAt=0`, method: RestMethod.GET, config: mockConfig, }) expect(result.success).toBe(true) expect(result.value).toEqual(mockResponse) }) test('should return failure when API call fails', async () => { // Setup const mockError = new Error('API Error') mockedCallJiraApi.mockResolvedValue(Failure(mockError)) // Execute const getIssueChangeLogs = createGetIssueChangeLogs(mockConfig, issueIdOrKey) const result = await getIssueChangeLogs() // Verify expect(result.success).toBe(false) expect(result.error).toEqual(mockError) }) test('should use custom startAt and maxResults parameters when provided', async () => { // Setup mockedCallJiraApi.mockResolvedValue(Success(mockResponse)) const customStartAt = 10 const customMaxResults = 25 // Execute const getIssueChangeLogs = createGetIssueChangeLogs(mockConfig, issueIdOrKey) await getIssueChangeLogs(customStartAt, customMaxResults) // Verify expect(mockedCallJiraApi).toHaveBeenCalledWith({ endpoint: `/rest/api/3/issue/${issueIdOrKey}/changelog?maxResults=${customMaxResults}&startAt=${customStartAt}`, method: RestMethod.GET, config: mockConfig, }) }) })

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