Skip to main content
Glama
mockClient.ts5.14 kB
import { vi } from 'vitest'; import { createToolClient } from '../../utils/tools.js'; /** * Shared mock objects for asset tests * Provides standardized mock client and asset objects used across all asset tests */ // Create mock functions for the client export const mockAssetGet = vi.fn(); export const mockAssetCreate = vi.fn(); export const mockAssetUpdate = vi.fn(); export const mockAssetDelete = vi.fn(); export const mockAssetPublish = vi.fn(); export const mockAssetUnpublish = vi.fn(); export const mockAssetArchive = vi.fn(); export const mockAssetUnarchive = vi.fn(); export const mockAssetGetMany = vi.fn(); export const mockAssetProcessForAllLocales = vi.fn(); // Mock bulk operations export const mockBulkActionPublish = vi.fn(); export const mockBulkActionUnpublish = vi.fn(); export const mockBulkActionGet = vi.fn(); /** * Standard mock Contentful client with all asset operations */ export const mockClient = { asset: { get: mockAssetGet, create: mockAssetCreate, update: mockAssetUpdate, delete: mockAssetDelete, publish: mockAssetPublish, unpublish: mockAssetUnpublish, archive: mockAssetArchive, unarchive: mockAssetUnarchive, getMany: mockAssetGetMany, processForAllLocales: mockAssetProcessForAllLocales, }, bulkAction: { publish: mockBulkActionPublish, unpublish: mockBulkActionUnpublish, get: mockBulkActionGet, }, }; /** * Sets up the mock client for tests * Call this in beforeEach to ensure the mock is properly configured */ export function setupMockClient() { vi.mocked(createToolClient).mockReturnValue( mockClient as unknown as ReturnType<typeof createToolClient>, ); } /** * Standard mock asset object used across tests */ export const mockAsset = { sys: { id: 'test-asset-id', type: 'Asset' as const, version: 1, space: { sys: { type: 'Link' as const, linkType: 'Space' as const, id: 'test-space-id', }, }, environment: { sys: { type: 'Link' as const, linkType: 'Environment' as const, id: 'test-environment', }, }, createdAt: '2023-01-01T00:00:00Z', updatedAt: '2023-01-01T00:00:00Z', publishedVersion: 1, }, fields: { title: { 'en-US': 'Test Asset', }, description: { 'en-US': 'A test asset for unit tests', }, file: { 'en-US': { fileName: 'test-image.jpg', contentType: 'image/jpeg', url: 'https://images.ctfassets.net/test/test-image.jpg', details: { size: 12345, image: { width: 800, height: 600, }, }, }, }, }, metadata: { tags: [], concepts: [], }, }; /** * Mock archived asset object */ export const mockArchivedAsset = { ...mockAsset, sys: { ...mockAsset.sys, archivedVersion: 1, archivedAt: '2023-01-02T00:00:00Z', }, }; /** * Standard test arguments for asset operations */ export const mockArgs = { spaceId: 'test-space-id', environmentId: 'test-environment', assetId: 'test-asset-id', }; /** * Mock file object for upload tests */ export const mockFile = { fileName: 'test-image.jpg', contentType: 'image/jpeg', upload: 'https://upload.example.com/test-upload-url', }; /** * Mock assets list response */ export const mockAssetsResponse = { total: 2, skip: 0, limit: 3, items: [ mockAsset, { ...mockAsset, sys: { ...mockAsset.sys, id: 'another-asset-id' }, fields: { ...mockAsset.fields, title: { 'en-US': 'Another Test Asset' }, }, }, ], }; /** * Mock bulk action response */ export const mockBulkAction = { sys: { id: 'bulk-action-id', type: 'BulkAction', status: 'succeeded', createdAt: '2023-01-01T00:00:00Z', updatedAt: '2023-01-01T00:00:00Z', }, action: 'publish', payload: {}, }; /** * Mock processed asset for upload */ export const mockProcessedAsset = { ...mockAsset, fields: { ...mockAsset.fields, file: { 'en-US': { ...mockAsset.fields.file['en-US'], url: 'https://images.ctfassets.net/processed/test-image.jpg', }, }, }, }; /** * Mock taxonomy concepts for testing */ export const mockTaxonomyConcepts = { concept1: { sys: { type: 'Link' as const, linkType: 'TaxonomyConcept' as const, id: 'concept-1', }, }, concept2: { sys: { type: 'Link' as const, linkType: 'TaxonomyConcept' as const, id: 'concept-2', }, }, existingConcept: { sys: { type: 'Link' as const, linkType: 'TaxonomyConcept' as const, id: 'existing-concept', }, }, }; /** * Mock tags for testing */ export const mockTags = { tag1: { sys: { type: 'Link' as const, linkType: 'Tag' as const, id: 'tag-1', }, }, tag2: { sys: { type: 'Link' as const, linkType: 'Tag' as const, id: 'tag-2', }, }, existingTag: { sys: { type: 'Link' as const, linkType: 'Tag' as const, id: 'existing-tag', }, }, };

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

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