mirror of
https://github.com/coleam00/Archon.git
synced 2026-01-03 05:10:27 -05:00
Add comprehensive test coverage for document CRUD operations
- Add Document interface for type safety - Fix error messages to include projectId context - Add unit tests for all projectService document methods - Add integration tests for DocsTab deletion flow - Update vitest config to include new test files
This commit is contained in:
@@ -24,6 +24,20 @@ import {
|
||||
|
||||
import { dbTaskToUITask, uiStatusToDBStatus } from '../types/project';
|
||||
|
||||
// Document interface for type safety
|
||||
export interface Document {
|
||||
id: string;
|
||||
project_id: string;
|
||||
title: string;
|
||||
content: any;
|
||||
document_type: string;
|
||||
metadata?: Record<string, any>;
|
||||
tags?: string[];
|
||||
author?: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
// API configuration - use relative URL to go through Vite proxy
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
@@ -548,9 +562,9 @@ export const projectService = {
|
||||
/**
|
||||
* List all documents for a project
|
||||
*/
|
||||
async listProjectDocuments(projectId: string): Promise<any[]> {
|
||||
async listProjectDocuments(projectId: string): Promise<Document[]> {
|
||||
try {
|
||||
const response = await callAPI<{documents: any[]}>(`/api/projects/${projectId}/docs`);
|
||||
const response = await callAPI<{documents: Document[]}>(`/api/projects/${projectId}/docs`);
|
||||
return response.documents || [];
|
||||
} catch (error) {
|
||||
console.error(`Failed to list documents for project ${projectId}:`, error);
|
||||
@@ -561,12 +575,12 @@ export const projectService = {
|
||||
/**
|
||||
* Get a specific document with full content
|
||||
*/
|
||||
async getDocument(projectId: string, docId: string): Promise<any> {
|
||||
async getDocument(projectId: string, docId: string): Promise<Document> {
|
||||
try {
|
||||
const response = await callAPI<{document: any}>(`/api/projects/${projectId}/docs/${docId}`);
|
||||
const response = await callAPI<{document: Document}>(`/api/projects/${projectId}/docs/${docId}`);
|
||||
return response.document;
|
||||
} catch (error) {
|
||||
console.error(`Failed to get document ${docId}:`, error);
|
||||
console.error(`Failed to get document ${docId} from project ${projectId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
@@ -574,9 +588,9 @@ export const projectService = {
|
||||
/**
|
||||
* Create a new document for a project
|
||||
*/
|
||||
async createDocument(projectId: string, documentData: any): Promise<any> {
|
||||
async createDocument(projectId: string, documentData: Partial<Document>): Promise<Document> {
|
||||
try {
|
||||
const response = await callAPI<{document: any}>(`/api/projects/${projectId}/docs`, {
|
||||
const response = await callAPI<{document: Document}>(`/api/projects/${projectId}/docs`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(documentData)
|
||||
});
|
||||
@@ -590,15 +604,15 @@ export const projectService = {
|
||||
/**
|
||||
* Update an existing document
|
||||
*/
|
||||
async updateDocument(projectId: string, docId: string, updates: any): Promise<any> {
|
||||
async updateDocument(projectId: string, docId: string, updates: Partial<Document>): Promise<Document> {
|
||||
try {
|
||||
const response = await callAPI<{document: any}>(`/api/projects/${projectId}/docs/${docId}`, {
|
||||
const response = await callAPI<{document: Document}>(`/api/projects/${projectId}/docs/${docId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(updates)
|
||||
});
|
||||
return response.document;
|
||||
} catch (error) {
|
||||
console.error(`Failed to update document ${docId}:`, error);
|
||||
console.error(`Failed to update document ${docId} in project ${projectId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
@@ -610,7 +624,7 @@ export const projectService = {
|
||||
try {
|
||||
await callAPI<void>(`/api/projects/${projectId}/docs/${docId}`, { method: 'DELETE' });
|
||||
} catch (error) {
|
||||
console.error(`Failed to delete document ${docId}:`, error);
|
||||
console.error(`Failed to delete document ${docId} from project ${projectId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user