Skip to main content
Glama
integration-test.template.ts4.99 kB
/** * Integration Test Template * * This template demonstrates the structure for integration tests. * Integration tests verify that multiple components work together correctly. * * Key Differences from Unit Tests: * - Test real component interactions * - Use real database (test instance) * - Test complete workflows * - Slower execution (acceptable) */ import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from "vitest"; import { createTestDatabase, cleanupTestDatabase, type TestDatabase } from "../utils/test-database"; import { createTestMemory } from "../utils/test-fixtures"; describe("Feature Integration", () => { let testDb: TestDatabase; // Setup test database once for all tests beforeAll(async () => { testDb = await createTestDatabase({ name: "feature_integration_test", setupSchema: true, }); }); // Cleanup test database after all tests afterAll(async () => { await cleanupTestDatabase(testDb); }); // Clear data before each test for isolation beforeEach(async () => { // await clearTestDatabase(testDb); }); afterEach(async () => { // Additional cleanup if needed }); describe("Complete Workflow", () => { it("should complete end-to-end workflow", async () => { // Arrange: Create test data const memory = createTestMemory({ content: "Integration test memory", sector: "semantic", }); // Act: Execute workflow // 1. Create memory // const created = await memoryRepository.create(memory); // 2. Generate embeddings // const embeddings = await embeddingEngine.generate(created); // 3. Store embeddings // await embeddingStorage.store(created.id, embeddings); // 4. Retrieve memory // const retrieved = await memoryRepository.retrieve(created.id); // Assert: Verify complete workflow // expect(retrieved).toBeDefined(); // expect(retrieved.id).toBe(created.id); // expect(retrieved.embeddings).toBeDefined(); // Placeholder assertion expect(testDb).toBeDefined(); }); it("should handle workflow with multiple components", async () => { // Arrange const memories = [ createTestMemory({ content: "Memory 1" }), createTestMemory({ content: "Memory 2" }), createTestMemory({ content: "Memory 3" }), ]; // Act: Create multiple memories // const created = await Promise.all( // memories.map(m => memoryRepository.create(m)) // ); // Act: Search for memories // const results = await memoryRepository.search({ // text: 'Memory', // limit: 10, // }); // Assert // expect(results.length).toBe(3); // Placeholder assertion expect(memories.length).toBe(3); }); }); describe("Cross-Component Interactions", () => { it("should coordinate between components", async () => { // Arrange const memory = createTestMemory(); // Act: Test component coordination // 1. Component A creates data // const data = await componentA.create(memory); // 2. Component B processes data // const processed = await componentB.process(data); // 3. Component C stores result // await componentC.store(processed); // Assert: Verify coordination // expect(processed).toBeDefined(); // Placeholder assertion expect(memory).toBeDefined(); }); }); describe("Error Handling", () => { it("should handle errors gracefully", async () => { // Arrange: Create invalid data const invalidMemory = createTestMemory({ content: "", // Invalid: empty content }); // Act & Assert: Verify error handling // await expect( // memoryRepository.create(invalidMemory) // ).rejects.toThrow('Content cannot be empty'); // Placeholder assertion expect(invalidMemory.content).toBe(""); }); it("should rollback on transaction failure", async () => { // Arrange const memory = createTestMemory(); // Act: Simulate transaction failure // try { // await testDb.transaction(async (tx) => { // await memoryRepository.create(memory, tx); // throw new Error('Simulated failure'); // }); // } catch (error) { // // Expected error // } // Assert: Verify rollback // const retrieved = await memoryRepository.retrieve(memory.id); // expect(retrieved).toBeNull(); // Placeholder assertion expect(memory).toBeDefined(); }); }); }); /** * Integration Test Best Practices: * * 1. Use real database (test instance) * 2. Test complete workflows * 3. Verify component interactions * 4. Test error handling and recovery * 5. Ensure test isolation (clean data between tests) * 6. Use realistic test data * 7. Test transaction boundaries * 8. Verify data consistency */

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/keyurgolani/ThoughtMcp'

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