File size: 6,467 Bytes
35765b5
 
 
 
 
 
698b2c1
35765b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""Complete API test with user creation flow."""

import requests
import json
import sys

BASE_URL = "http://localhost:8000"

print("="*60)
print("PROJECT MEMORY - COMPLETE API TEST")
print("="*60)

def test_api():
    # Check if server is running
    try:
        response = requests.get(f"{BASE_URL}/")
        print(f"✓ Server is running: {response.json()['message']}")
    except:
        print("❌ Server is not running!")
        print("Start it with: uvicorn app.main:app --reload")
        return
    
    print("\n" + "="*60)
    print("1. CREATE USER")
    print("="*60)
    
    # Create a new user
    user_data = {
        "firstName": "John",
        "lastName": "Doe",
        "avatar_url": "https://example.com/avatar.jpg"
    }
    
    print(f"POST /api/users")
    print(f"Body: {json.dumps(user_data, indent=2)}")
    
    response = requests.post(f"{BASE_URL}/api/users", json=user_data)
    print(f"Status: {response.status_code}")
    
    if response.status_code != 200:
        print(f"Error: {response.text}")
        return
    
    user = response.json()
    user_id = user["id"]
    print(f"✓ Created user: {user_id}")
    print(f"Response: {json.dumps(user, indent=2)}")
    
    print("\n" + "="*60)
    print("2. GET USER")
    print("="*60)
    
    print(f"GET /api/users/{user_id}")
    response = requests.get(f"{BASE_URL}/api/users/{user_id}")
    print(f"Status: {response.status_code}")
    print(f"Response: {json.dumps(response.json(), indent=2)}")
    
    print("\n" + "="*60)
    print("3. LIST ALL USERS")
    print("="*60)
    
    print(f"GET /api/users")
    response = requests.get(f"{BASE_URL}/api/users")
    print(f"Status: {response.status_code}")
    users = response.json()
    print(f"Total users: {len(users)}")
    for u in users[:3]:  # Show first 3 users
        print(f"  - {u['firstName']} {u['lastName']} ({u['id']})")
    
    print("\n" + "="*60)
    print("4. CREATE PROJECT")
    print("="*60)
    
    project_data = {
        "name": "Test Project",
        "description": "API Testing Project",
        "userId": user_id
    }
    
    print(f"POST /api/projects")
    print(f"Body: {json.dumps(project_data, indent=2)}")
    
    response = requests.post(f"{BASE_URL}/api/projects", json=project_data)
    print(f"Status: {response.status_code}")
    
    if response.status_code != 200:
        print(f"Error: {response.text}")
        return
    
    project = response.json()
    project_id = project["id"]
    print(f"✓ Created project: {project_id}")
    
    print("\n" + "="*60)
    print("5. LIST USER'S PROJECTS")
    print("="*60)
    
    print(f"GET /api/projects?userId={user_id}")
    response = requests.get(f"{BASE_URL}/api/projects?userId={user_id}")
    print(f"Status: {response.status_code}")
    projects = response.json()
    print(f"User has {len(projects)} project(s)")
    
    print("\n" + "="*60)
    print("6. CREATE TASK")
    print("="*60)
    
    task_data = {
        "title": "Implement user authentication",
        "description": "Add login and registration features",
        "assignedTo": user_id
    }
    
    print(f"POST /api/projects/{project_id}/tasks")
    print(f"Body: {json.dumps(task_data, indent=2)}")
    
    response = requests.post(f"{BASE_URL}/api/projects/{project_id}/tasks", json=task_data)
    print(f"Status: {response.status_code}")
    
    if response.status_code != 200:
        print(f"Error: {response.text}")
        return
        
    task = response.json()
    task_id = task["id"]
    print(f"✓ Created task: {task_id}")
    
    print("\n" + "="*60)
    print("7. LIST TASKS")
    print("="*60)
    
    print(f"GET /api/projects/{project_id}/tasks")
    response = requests.get(f"{BASE_URL}/api/projects/{project_id}/tasks")
    print(f"Status: {response.status_code}")
    tasks = response.json()
    print(f"Project has {len(tasks)} task(s)")
    
    print("\n" + "="*60)
    print("8. COMPLETE TASK (with AI documentation)")
    print("="*60)
    
    complete_data = {
        "userId": user_id,
        "whatIDid": "Implemented OAuth2 authentication with JWT tokens",
        "codeSnippet": "def authenticate(token): return jwt.decode(token, SECRET_KEY)"
    }
    
    print(f"POST /api/tasks/{task_id}/complete")
    print(f"Body: {json.dumps(complete_data, indent=2)}")
    print("⏳ This will call Gemini AI to generate documentation...")
    
    response = requests.post(f"{BASE_URL}/api/tasks/{task_id}/complete", json=complete_data)
    print(f"Status: {response.status_code}")
    
    if response.status_code == 200:
        print(f"✓ Task completed with AI documentation")
        print(f"Response: {json.dumps(response.json(), indent=2)}")
    else:
        print(f"Note: Task completion requires GEMINI_API_KEY in .env")
        print(f"Response: {response.text}")
    
    print("\n" + "="*60)
    print("9. GET ACTIVITY FEED")
    print("="*60)
    
    print(f"GET /api/projects/{project_id}/activity")
    response = requests.get(f"{BASE_URL}/api/projects/{project_id}/activity")
    print(f"Status: {response.status_code}")
    if response.status_code == 200:
        activity = response.json()
        print(f"Activity entries: {len(activity)}")
    
    print("\n" + "="*60)
    print("TEST COMPLETE - ALL ENDPOINTS WORKING!")
    print("="*60)
    
    print(f"""
SUMMARY OF CREATED DATA:
- User ID: {user_id}
- Project ID: {project_id}
- Task ID: {task_id}

You can now use these IDs to test other endpoints!
""")
    
    print("="*60)
    print("CURL EXAMPLES WITH YOUR DATA")
    print("="*60)
    
    print(f"""
# Create another user
curl -X POST {BASE_URL}/api/users \\
  -H "Content-Type: application/json" \\
  -d '{{"firstName": "Jane", "lastName": "Smith"}}'

# Get your user
curl {BASE_URL}/api/users/{user_id}

# List all users
curl {BASE_URL}/api/users

# Create another project
curl -X POST {BASE_URL}/api/projects \\
  -H "Content-Type: application/json" \\
  -d '{{"name": "Another Project", "description": "Description", "userId": "{user_id}"}}'

# Join a project (create a second user first)
curl -X POST {BASE_URL}/api/projects/{project_id}/join \\
  -H "Content-Type: application/json" \\
  -d '{{"userId": "ANOTHER_USER_ID"}}'

# Search project memory (after completing tasks)
curl -X POST {BASE_URL}/api/projects/{project_id}/search \\
  -H "Content-Type: application/json" \\
  -d '{{"query": "authentication"}}'
""")

if __name__ == "__main__":
    test_api()