diff --git a/apps/api/src/index.test.ts b/apps/api/src/index.test.ts new file mode 100644 index 0000000..4724145 --- /dev/null +++ b/apps/api/src/index.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from 'vitest'; + +describe('API App', () => { + it('should have a basic test', () => { + expect(true).toBe(true); + }); + + it('should validate API endpoint structure', () => { + const endpoint = '/api/v1/users'; + expect(endpoint).toMatch(/^\/api\/v\d+\/\w+$/); + }); +}); diff --git a/apps/app/src/index.test.ts b/apps/app/src/index.test.ts new file mode 100644 index 0000000..8b33f02 --- /dev/null +++ b/apps/app/src/index.test.ts @@ -0,0 +1,13 @@ +import { describe, expect, it } from 'vitest'; + +describe('App', () => { + it('should have a basic test', () => { + expect(true).toBe(true); + }); + + it('should validate app configuration', () => { + const config = { name: 'AICD App', version: '1.0.0' }; + expect(config).toHaveProperty('name'); + expect(config).toHaveProperty('version'); + }); +}); diff --git a/apps/web/src/index.test.ts b/apps/web/src/index.test.ts new file mode 100644 index 0000000..2b95afc --- /dev/null +++ b/apps/web/src/index.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from 'vitest'; + +describe('Web App', () => { + it('should have a basic test', () => { + expect(true).toBe(true); + }); + + it('should validate web route structure', () => { + const route = '/dashboard/users'; + expect(route).toMatch(/^\/\w+(\/\w+)*$/); + }); +}); diff --git a/packages/auth/src/index.test.ts b/packages/auth/src/index.test.ts new file mode 100644 index 0000000..176f0fb --- /dev/null +++ b/packages/auth/src/index.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it, vi } from 'vitest'; +import { authenticate, createToken } from './index'; +import type { User } from '@aicd/core'; + +describe('Auth', () => { + it('should have an authenticate function', () => { + expect(typeof authenticate).toBe('function'); + }); + + it('should return null for any token (placeholder)', () => { + const consoleSpy = vi.spyOn(console, 'log'); + const result = authenticate('test-token'); + + expect(result).toBeNull(); + expect(consoleSpy).toHaveBeenCalledWith('Authenticating token:', 'test-token'); + + consoleSpy.mockRestore(); + }); + + it('should create a token for a user', () => { + const user: User = { + id: '123', + email: 'test@example.com', + name: 'Test User' + }; + + const token = createToken(user); + expect(token).toBe('token-123'); + }); +}); diff --git a/packages/cms/src/index.test.ts b/packages/cms/src/index.test.ts new file mode 100644 index 0000000..eb144a2 --- /dev/null +++ b/packages/cms/src/index.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, it, vi } from 'vitest'; +import CMS from './index'; + +describe('CMS', () => { + it('should create a CMS instance', () => { + const cms = new CMS(); + expect(cms).toBeInstanceOf(CMS); + }); + + it('should return null when getting content', async () => { + const cms = new CMS(); + const consoleSpy = vi.spyOn(console, 'log'); + + const result = await cms.getContent('test-id'); + + expect(result).toBeNull(); + expect(consoleSpy).toHaveBeenCalledWith('Getting content:', 'test-id'); + + consoleSpy.mockRestore(); + }); + + it('should create content', async () => { + const cms = new CMS(); + const consoleSpy = vi.spyOn(console, 'log'); + + const contentData = { + title: 'Test Content', + body: 'Test body' + }; + + await cms.createContent(contentData); + + expect(consoleSpy).toHaveBeenCalledWith('Creating content:', contentData); + + consoleSpy.mockRestore(); + }); +}); diff --git a/packages/core/src/index.test.ts b/packages/core/src/index.test.ts new file mode 100644 index 0000000..93341b5 --- /dev/null +++ b/packages/core/src/index.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from 'vitest'; +import { formatDate, validateInput } from './index'; + +describe('formatDate', () => { + it('should format a valid date string', () => { + const result = formatDate('2024-01-01'); + expect(result).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/); + }); + + it('should format a Date object', () => { + const date = new Date('2024-01-01'); + const result = formatDate(date); + expect(result).toBe(date.toISOString()); + }); + + it('should throw an error for invalid date', () => { + expect(() => formatDate('invalid-date')).toThrow('Invalid date provided'); + }); +}); + +describe('validateInput', () => { + it('should return true for valid input', () => { + expect(validateInput('test')).toBe(true); + expect(validateInput(' test ')).toBe(true); + }); + + it('should return false for empty or invalid input', () => { + expect(validateInput('')).toBe(false); + expect(validateInput(' ')).toBe(false); + expect(validateInput(null as any)).toBe(false); + expect(validateInput(undefined as any)).toBe(false); + }); +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 5810fa1..cb6c707 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -17,4 +17,17 @@ export function validateInput(input: string): boolean { return input.trim().length > 0; } +/** + * Format a date string for consistent display across the application + * @param date - The date to format (string or Date object) + * @returns Formatted date string in ISO format + */ +export function formatDate(date: string | Date): string { + const dateObj = typeof date === 'string' ? new Date(date) : date; + if (Number.isNaN(dateObj.getTime())) { + throw new Error('Invalid date provided'); + } + return dateObj.toISOString(); +} + export * from './types'; diff --git a/packages/database/src/index.test.ts b/packages/database/src/index.test.ts new file mode 100644 index 0000000..7d431b5 --- /dev/null +++ b/packages/database/src/index.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it, vi } from 'vitest'; +import { Database, type DatabaseConfig } from './index'; + +describe('Database', () => { + it('should create a database instance', () => { + const config: DatabaseConfig = { + connectionString: 'test://localhost:5432/test' + }; + const db = new Database(config); + expect(db).toBeInstanceOf(Database); + }); + + it('should log connection message', async () => { + const config: DatabaseConfig = { + connectionString: 'test://localhost:5432/test' + }; + const db = new Database(config); + const consoleSpy = vi.spyOn(console, 'log'); + + await db.connect(); + + expect(consoleSpy).toHaveBeenCalledWith('Connecting to database with connection string: test://localhost:5432/test'); + consoleSpy.mockRestore(); + }); + + it('should log disconnect message', async () => { + const config: DatabaseConfig = { + connectionString: 'test://localhost:5432/test' + }; + const db = new Database(config); + const consoleSpy = vi.spyOn(console, 'log'); + + await db.disconnect(); + + expect(consoleSpy).toHaveBeenCalledWith('Disconnecting from database...'); + consoleSpy.mockRestore(); + }); +});