Refactor content handling to use Appwrite service instead of Astro collections, remove ViewTransitions import, update test files accordingly

This commit is contained in:
Spaghet committed 2025-08-23 20:10:43 -04:00
1 parent 9cc9768121
commit c9948befaf
13 files changed
+111 -256

No files matched your search

+62 -157
View File
@@ -1,175 +1,80 @@
import { describe, it, expect, vi } from 'vitest';
import { getBlogTemplates, createBlogPost, updateBlogPost, deleteBlogPost, createProject, updateProject, deleteProject, createWorkExperience, updateWorkExperience, deleteWorkExperience, createLegalDocument, updateLegalDocument, deleteLegalDocument } from '../appwrite-service';
import { describe, it, expect } from 'vitest';
import { getBlogPosts, getProjects, getWorkExperiences, getLegalDocuments } from '../appwrite-service';
describe('AppWrite Service', () => {
describe('getBlogTemplates', () => {
it('should return an array of blog templates', async () => {
const templates = await getBlogTemplates();
describe('getBlogPosts', () => {
it('should return an array of blog posts', async () => {
const posts = await getBlogPosts();
expect(Array.isArray(templates)).toBe(true);
expect(templates.length).toBeGreaterThan(0);
expect(Array.isArray(posts)).toBe(true);
expect(posts.length).toBeGreaterThan(0);
// Check that each template has the expected properties
templates.forEach(template => {
expect(template).toHaveProperty('id');
expect(template).toHaveProperty('name');
expect(template).toHaveProperty('slug');
// Check that each post has the expected properties
posts.forEach((post) => {
expect(post).toHaveProperty('title');
expect(post).toHaveProperty('summary');
expect(post).toHaveProperty('date');
expect(post).toHaveProperty('tags');
expect(post).toHaveProperty('draft');
expect(post).toHaveProperty('content');
expect(post).toHaveProperty('template');
expect(post).toHaveProperty('featured');
});
});
});
it('should return the correct default templates', async () => {
const templates = await getBlogTemplates();
describe('getProjects', () => {
it('should return an array of projects', async () => {
const projects = await getProjects();
// Should contain default, feature and news templates
const templateIds = templates.map(t => t.id);
expect(templateIds).toContain('default');
expect(templateIds).toContain('feature');
expect(templateIds).toContain('news');
});
});
describe('createBlogPost', () => {
it('should create a new blog post with valid data', async () => {
const postData = {
title: "Test Blog Post",
summary: "Test summary",
date: new Date(),
tags: ["test", "blog"],
draft: false,
content: "Test content",
template: "default",
featured: false
};
// Mock the database call
const mockResponse = {
$id: "test-id",
...postData
};
expect(Array.isArray(projects)).toBe(true);
expect(projects.length).toBeGreaterThan(0);
// This test would require mocking the databases.createDocument call
expect(typeof createBlogPost).toBe('function');
// Check that each project has the expected properties
projects.forEach((project) => {
expect(project).toHaveProperty('title');
expect(project).toHaveProperty('summary');
expect(project).toHaveProperty('date');
expect(project).toHaveProperty('tags');
expect(project).toHaveProperty('draft');
expect(project).toHaveProperty('content');
expect(project).toHaveProperty('demoUrl');
expect(project).toHaveProperty('repoUrl');
});
});
});
describe('updateBlogPost', () => {
it('should update an existing blog post', async () => {
const postData = {
title: "Updated Blog Post",
content: "Updated content"
};
// Mock the database call
expect(typeof updateBlogPost).toBe('function');
describe('getWorkExperiences', () => {
it('should return an array of work experiences', async () => {
const workExperiences = await getWorkExperiences();
expect(Array.isArray(workExperiences)).toBe(true);
expect(workExperiences.length).toBeGreaterThan(0);
// Check that each work experience has the expected properties
workExperiences.forEach((work) => {
expect(work).toHaveProperty('company');
expect(work).toHaveProperty('role');
expect(work).toHaveProperty('dateStart');
expect(work).toHaveProperty('content');
expect(work).toHaveProperty('dateEnd');
});
});
});
describe('deleteBlogPost', () => {
it('should delete a blog post by ID', async () => {
// Mock the database call
expect(typeof deleteBlogPost).toBe('function');
});
});
describe('createProject', () => {
it('should create a new project with valid data', async () => {
const projectData = {
title: "Test Project",
summary: "Test summary",
date: new Date(),
tags: ["test", "project"],
draft: false,
content: "Test content",
demoUrl: "https://example.com/demo",
repoUrl: "https://example.com/repo"
};
// Mock the database call
expect(typeof createProject).toBe('function');
});
});
describe('updateProject', () => {
it('should update an existing project', async () => {
const projectData = {
title: "Updated Project",
content: "Updated content"
};
// Mock the database call
expect(typeof updateProject).toBe('function');
});
});
describe('deleteProject', () => {
it('should delete a project by ID', async () => {
// Mock the database call
expect(typeof deleteProject).toBe('function');
});
});
describe('createWorkExperience', () => {
it('should create a new work experience with valid data', async () => {
const workData = {
company: "Test Company",
role: "Test Role",
dateStart: new Date(),
dateEnd: new Date()
};
// Mock the database call
expect(typeof createWorkExperience).toBe('function');
});
});
describe('updateWorkExperience', () => {
it('should update an existing work experience', async () => {
const workData = {
company: "Updated Company",
role: "Updated Role"
};
// Mock the database call
expect(typeof updateWorkExperience).toBe('function');
});
});
describe('deleteWorkExperience', () => {
it('should delete a work experience by ID', async () => {
// Mock the database call
expect(typeof deleteWorkExperience).toBe('function');
});
});
describe('createLegalDocument', () => {
it('should create a new legal document with valid data', async () => {
const docData = {
title: "Test Legal Document",
date: new Date(),
content: "Test content"
};
// Mock the database call
expect(typeof createLegalDocument).toBe('function');
});
});
describe('updateLegalDocument', () => {
it('should update an existing legal document', async () => {
const docData = {
title: "Updated Legal Document",
content: "Updated content"
};
// Mock the database call
expect(typeof updateLegalDocument).toBe('function');
});
});
describe('deleteLegalDocument', () => {
it('should delete a legal document by ID', async () => {
// Mock the database call
expect(typeof deleteLegalDocument).toBe('function');
describe('getLegalDocuments', () => {
it('should return an array of legal documents', async () => {
const legalDocuments = await getLegalDocuments();
expect(Array.isArray(legalDocuments)).toBe(true);
expect(legalDocuments.length).toBeGreaterThan(0);
// Check that each legal document has the expected properties
legalDocuments.forEach((doc) => {
expect(doc).toHaveProperty('title');
expect(doc).toHaveProperty('date');
expect(doc).toHaveProperty('content');
});
});
});
});
+2 -2
View File
@@ -93,7 +93,7 @@ if (typeof window === 'undefined') {
} else {
blogCollection = import.meta.env.PUBLIC_APPWRITE_BLOG_COLLECTION_ID || 'blog';
projectsCollection = import.meta.env.PUBLIC_APPWRITE_PROJECTS_COLLECTION_ID || "projects";
workCollection = import.meta.env.PUBLIC_APPWRITE_WORK_COLLECTION_ID || "work";
workCollection = import.meta.env.PUBLIC_APPwrite_WORK_COLLECTION_ID || "work";
legalCollection = import.meta.env.PUBLIC_APPWRITE_LEGAL_COLLECTION_ID || "legal";
databaseID = import.meta.env.PUBLIC_APPWRITE_DATABASE_ID || "main";
}
@@ -295,7 +295,7 @@ export async function getLegalDocuments(): Promise<LegalDocument[]> {
try {
const response = await databases.listDocuments<LegalDocument>(
databaseID,
workCollection
legalCollection
);
return response.documents;