Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/api/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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+$/);
});
});
13 changes: 13 additions & 0 deletions apps/app/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
12 changes: 12 additions & 0 deletions apps/web/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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+)*$/);
});
});
30 changes: 30 additions & 0 deletions packages/auth/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
37 changes: 37 additions & 0 deletions packages/cms/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
33 changes: 33 additions & 0 deletions packages/core/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
13 changes: 13 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
38 changes: 38 additions & 0 deletions packages/database/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
Loading