Skip to content

Commit a1b5e5d

Browse files
authored
Merge pull request #15 from zopiolabs/release/v0.3.0
release: v0.3.0
2 parents f901bdb + 42d9a81 commit a1b5e5d

File tree

8 files changed

+188
-0
lines changed

8 files changed

+188
-0
lines changed

apps/api/src/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('API App', () => {
4+
it('should have a basic test', () => {
5+
expect(true).toBe(true);
6+
});
7+
8+
it('should validate API endpoint structure', () => {
9+
const endpoint = '/api/v1/users';
10+
expect(endpoint).toMatch(/^\/api\/v\d+\/\w+$/);
11+
});
12+
});

apps/app/src/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('App', () => {
4+
it('should have a basic test', () => {
5+
expect(true).toBe(true);
6+
});
7+
8+
it('should validate app configuration', () => {
9+
const config = { name: 'AICD App', version: '1.0.0' };
10+
expect(config).toHaveProperty('name');
11+
expect(config).toHaveProperty('version');
12+
});
13+
});

apps/web/src/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('Web App', () => {
4+
it('should have a basic test', () => {
5+
expect(true).toBe(true);
6+
});
7+
8+
it('should validate web route structure', () => {
9+
const route = '/dashboard/users';
10+
expect(route).toMatch(/^\/\w+(\/\w+)*$/);
11+
});
12+
});

packages/auth/src/index.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { authenticate, createToken } from './index';
3+
import type { User } from '@aicd/core';
4+
5+
describe('Auth', () => {
6+
it('should have an authenticate function', () => {
7+
expect(typeof authenticate).toBe('function');
8+
});
9+
10+
it('should return null for any token (placeholder)', () => {
11+
const consoleSpy = vi.spyOn(console, 'log');
12+
const result = authenticate('test-token');
13+
14+
expect(result).toBeNull();
15+
expect(consoleSpy).toHaveBeenCalledWith('Authenticating token:', 'test-token');
16+
17+
consoleSpy.mockRestore();
18+
});
19+
20+
it('should create a token for a user', () => {
21+
const user: User = {
22+
id: '123',
23+
email: 'test@example.com',
24+
name: 'Test User'
25+
};
26+
27+
const token = createToken(user);
28+
expect(token).toBe('token-123');
29+
});
30+
});

packages/cms/src/index.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import CMS from './index';
3+
4+
describe('CMS', () => {
5+
it('should create a CMS instance', () => {
6+
const cms = new CMS();
7+
expect(cms).toBeInstanceOf(CMS);
8+
});
9+
10+
it('should return null when getting content', async () => {
11+
const cms = new CMS();
12+
const consoleSpy = vi.spyOn(console, 'log');
13+
14+
const result = await cms.getContent('test-id');
15+
16+
expect(result).toBeNull();
17+
expect(consoleSpy).toHaveBeenCalledWith('Getting content:', 'test-id');
18+
19+
consoleSpy.mockRestore();
20+
});
21+
22+
it('should create content', async () => {
23+
const cms = new CMS();
24+
const consoleSpy = vi.spyOn(console, 'log');
25+
26+
const contentData = {
27+
title: 'Test Content',
28+
body: 'Test body'
29+
};
30+
31+
await cms.createContent(contentData);
32+
33+
expect(consoleSpy).toHaveBeenCalledWith('Creating content:', contentData);
34+
35+
consoleSpy.mockRestore();
36+
});
37+
});

packages/core/src/index.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { formatDate, validateInput } from './index';
3+
4+
describe('formatDate', () => {
5+
it('should format a valid date string', () => {
6+
const result = formatDate('2024-01-01');
7+
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
8+
});
9+
10+
it('should format a Date object', () => {
11+
const date = new Date('2024-01-01');
12+
const result = formatDate(date);
13+
expect(result).toBe(date.toISOString());
14+
});
15+
16+
it('should throw an error for invalid date', () => {
17+
expect(() => formatDate('invalid-date')).toThrow('Invalid date provided');
18+
});
19+
});
20+
21+
describe('validateInput', () => {
22+
it('should return true for valid input', () => {
23+
expect(validateInput('test')).toBe(true);
24+
expect(validateInput(' test ')).toBe(true);
25+
});
26+
27+
it('should return false for empty or invalid input', () => {
28+
expect(validateInput('')).toBe(false);
29+
expect(validateInput(' ')).toBe(false);
30+
expect(validateInput(null as any)).toBe(false);
31+
expect(validateInput(undefined as any)).toBe(false);
32+
});
33+
});

packages/core/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@ export function validateInput(input: string): boolean {
1717
return input.trim().length > 0;
1818
}
1919

20+
/**
21+
* Format a date string for consistent display across the application
22+
* @param date - The date to format (string or Date object)
23+
* @returns Formatted date string in ISO format
24+
*/
25+
export function formatDate(date: string | Date): string {
26+
const dateObj = typeof date === 'string' ? new Date(date) : date;
27+
if (Number.isNaN(dateObj.getTime())) {
28+
throw new Error('Invalid date provided');
29+
}
30+
return dateObj.toISOString();
31+
}
32+
2033
export * from './types';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { Database, type DatabaseConfig } from './index';
3+
4+
describe('Database', () => {
5+
it('should create a database instance', () => {
6+
const config: DatabaseConfig = {
7+
connectionString: 'test://localhost:5432/test'
8+
};
9+
const db = new Database(config);
10+
expect(db).toBeInstanceOf(Database);
11+
});
12+
13+
it('should log connection message', async () => {
14+
const config: DatabaseConfig = {
15+
connectionString: 'test://localhost:5432/test'
16+
};
17+
const db = new Database(config);
18+
const consoleSpy = vi.spyOn(console, 'log');
19+
20+
await db.connect();
21+
22+
expect(consoleSpy).toHaveBeenCalledWith('Connecting to database with connection string: test://localhost:5432/test');
23+
consoleSpy.mockRestore();
24+
});
25+
26+
it('should log disconnect message', async () => {
27+
const config: DatabaseConfig = {
28+
connectionString: 'test://localhost:5432/test'
29+
};
30+
const db = new Database(config);
31+
const consoleSpy = vi.spyOn(console, 'log');
32+
33+
await db.disconnect();
34+
35+
expect(consoleSpy).toHaveBeenCalledWith('Disconnecting from database...');
36+
consoleSpy.mockRestore();
37+
});
38+
});

0 commit comments

Comments
 (0)