mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-27 23:06:54 +05:00
Added comprehensive demo project showcasing ipuaro capabilities: New Files: - examples/demo-project/: Complete TypeScript demo application - src/: User management, auth, validation, logging (336 LOC) - tests/: Vitest unit tests for UserService - Configuration: package.json, tsconfig.json, .ipuaro.json Demo Features: - UserService with CRUD operations - AuthService with login/logout/verify - Validation utilities (email, password) - Logger utility with multiple log levels - TypeScript types and interfaces - Intentional TODOs (2) and FIXMEs (1) for tool demonstration Documentation: - README.md: Detailed usage guide with example queries - EXAMPLE_CONVERSATIONS.md: Realistic conversation scenarios - Tool demonstration scenarios (bug fix, refactoring, features) - Workflow examples (security audit, optimization, code review) Updated: - packages/ipuaro/README.md: Added Quick Start section linking to examples Project Statistics: - 12 files total - 336 lines of TypeScript code - 7 source modules demonstrating various patterns - Full test coverage examples - Demonstrates all 18 tools capabilities This completes the "Examples working" requirement for v1.0.0
142 lines
4.2 KiB
TypeScript
142 lines
4.2 KiB
TypeScript
/**
|
|
* User service tests
|
|
*/
|
|
|
|
import { describe, it, expect, beforeEach } from "vitest"
|
|
import { UserService } from "../src/services/user"
|
|
import { ValidationError } from "../src/utils/validation"
|
|
|
|
describe("UserService", () => {
|
|
let userService: UserService
|
|
|
|
beforeEach(() => {
|
|
userService = new UserService()
|
|
})
|
|
|
|
describe("createUser", () => {
|
|
it("should create a new user", async () => {
|
|
const user = await userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Test User",
|
|
password: "password123"
|
|
})
|
|
|
|
expect(user).toBeDefined()
|
|
expect(user.email).toBe("test@example.com")
|
|
expect(user.name).toBe("Test User")
|
|
expect(user.role).toBe("user")
|
|
})
|
|
|
|
it("should reject invalid email", async () => {
|
|
await expect(
|
|
userService.createUser({
|
|
email: "invalid-email",
|
|
name: "Test User",
|
|
password: "password123"
|
|
})
|
|
).rejects.toThrow(ValidationError)
|
|
})
|
|
|
|
it("should reject weak password", async () => {
|
|
await expect(
|
|
userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Test User",
|
|
password: "weak"
|
|
})
|
|
).rejects.toThrow(ValidationError)
|
|
})
|
|
|
|
it("should prevent duplicate emails", async () => {
|
|
await userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Test User",
|
|
password: "password123"
|
|
})
|
|
|
|
await expect(
|
|
userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Another User",
|
|
password: "password123"
|
|
})
|
|
).rejects.toThrow("already exists")
|
|
})
|
|
})
|
|
|
|
describe("getUserById", () => {
|
|
it("should return user by ID", async () => {
|
|
const created = await userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Test User",
|
|
password: "password123"
|
|
})
|
|
|
|
const found = await userService.getUserById(created.id)
|
|
expect(found).toEqual(created)
|
|
})
|
|
|
|
it("should return null for non-existent ID", async () => {
|
|
const found = await userService.getUserById("non-existent")
|
|
expect(found).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe("updateUser", () => {
|
|
it("should update user name", async () => {
|
|
const user = await userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Test User",
|
|
password: "password123"
|
|
})
|
|
|
|
const updated = await userService.updateUser(user.id, {
|
|
name: "Updated Name"
|
|
})
|
|
|
|
expect(updated.name).toBe("Updated Name")
|
|
expect(updated.email).toBe(user.email)
|
|
})
|
|
|
|
it("should throw error for non-existent user", async () => {
|
|
await expect(
|
|
userService.updateUser("non-existent", { name: "Test" })
|
|
).rejects.toThrow("not found")
|
|
})
|
|
})
|
|
|
|
describe("deleteUser", () => {
|
|
it("should delete user", async () => {
|
|
const user = await userService.createUser({
|
|
email: "test@example.com",
|
|
name: "Test User",
|
|
password: "password123"
|
|
})
|
|
|
|
await userService.deleteUser(user.id)
|
|
|
|
const found = await userService.getUserById(user.id)
|
|
expect(found).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe("listUsers", () => {
|
|
it("should return all users", async () => {
|
|
await userService.createUser({
|
|
email: "user1@example.com",
|
|
name: "User 1",
|
|
password: "password123"
|
|
})
|
|
|
|
await userService.createUser({
|
|
email: "user2@example.com",
|
|
name: "User 2",
|
|
password: "password123"
|
|
})
|
|
|
|
const users = await userService.listUsers()
|
|
expect(users).toHaveLength(2)
|
|
})
|
|
})
|
|
})
|