Skip to main content
Glama
deepsource-coverage-gaps.test.ts4.41 kB
import nock from 'nock'; import { vi } from 'vitest'; import { DeepSourceClient, ReportType } from '../deepsource'; // Mock logger to verify it's called properly vi.mock('../utils/logging/logger', () => { const mockWarn = globalThis.vi.fn(); return { createLogger: globalThis.vi.fn(() => ({ warn: mockWarn, error: globalThis.vi.fn(), info: globalThis.vi.fn(), debug: globalThis.vi.fn(), })), __mockWarn: mockWarn, // Export for test access }; }); describe('DeepSource Client Coverage Gaps', () => { const API_KEY = 'test-api-key'; let client: DeepSourceClient; beforeEach(() => { nock.cleanAll(); vi.clearAllMocks(); client = new DeepSourceClient(API_KEY); }); afterAll(() => { nock.restore(); }); describe('getComplianceReport function', () => { it('should handle API errors correctly', async () => { // Mock the listProjects call first nock('https://api.deepsource.io') .post('/graphql/') .reply(200, { data: { viewer: { accounts: { edges: [ { node: { login: 'testorg', repositories: { edges: [ { node: { name: 'test-repo', defaultBranch: 'main', dsn: 'test-project', isPrivate: false, isActivated: true, vcsProvider: 'github', }, }, ], }, }, }, ], }, }, }, }); // Mock the second request to throw an error nock('https://api.deepsource.io').post('/graphql/').replyWithError('Network error'); // Test that the error is properly handled await expect( client.getComplianceReport('test-project', ReportType.OWASP_TOP_10) ).rejects.toThrow(); }); }); describe('getDependencyVulnerabilities function', () => { it('should handle empty project list', async () => { // Mock empty projects response nock('https://api.deepsource.io') .post('/graphql/') .reply(200, { data: { viewer: { accounts: { edges: [], }, }, }, }); const result = await client.getDependencyVulnerabilities('nonexistent-project'); expect(result).toEqual({ items: [], pageInfo: { hasNextPage: false, hasPreviousPage: false, }, totalCount: 0, }); }); }); describe('getQualityMetrics function', () => { it('should handle metric not found errors', async () => { // Mock the listProjects call first nock('https://api.deepsource.io') .post('/graphql/') .reply(200, { data: { viewer: { accounts: { edges: [ { node: { login: 'testorg', repositories: { edges: [ { node: { name: 'test-repo', defaultBranch: 'main', dsn: 'test-project', isPrivate: false, isActivated: true, vcsProvider: 'github', }, }, ], }, }, }, ], }, }, }, }); // Mock the metrics response with no metrics data nock('https://api.deepsource.io') .post('/graphql/') .reply(200, { data: { repository: { // Missing metrics or empty metrics array }, }, }); // Test empty metrics response const result = await client.getQualityMetrics('test-project', {}); expect(result).toEqual([]); }); }); });

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/sapientpants/deepsource-mcp-server'

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