feat: Implement multi-tenancy with organization ID in LMS tables and middleware, refactor web API calls, and update analytics and gamification features."
This commit is contained in:
+43
-16
@@ -16,23 +16,50 @@ else
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# 2. Verify New Registration
|
||||
echo "Testing Registration for newuser@test.com..."
|
||||
# Clear if exists
|
||||
docker exec openccb-db-1 psql -U user -d openccb_cms -c "DELETE FROM users WHERE email='newuser@test.com';" > /dev/null 2>&1
|
||||
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:3001/auth/register \
|
||||
# 3. Verify Organization Context (Course Scoping)
|
||||
echo "Testing Course Scoping by Organization..."
|
||||
# Login to get token
|
||||
USER_DATA=$(curl -s -X POST http://localhost:3001/auth/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"email":"newuser@test.com","password":"password123","full_name":"New User","role":"instructor"}')
|
||||
-d '{"email":"juan.allende@gmail.com","password":"password123"}')
|
||||
TOKEN=$(echo "$USER_DATA" | jq -r '.token')
|
||||
ORG_ID=$(echo "$USER_DATA" | jq -r '.user.organization_id')
|
||||
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo "SUCCESS: Registration worked for newuser@test.com"
|
||||
# Cleanup
|
||||
docker exec openccb-db-1 psql -U user -d openccb_cms -c "DELETE FROM users WHERE email='newuser@test.com';" > /dev/null 2>&1
|
||||
else
|
||||
echo "FAIL: Registration failed with status $HTTP_CODE"
|
||||
curl -s -X POST http://localhost:3001/auth/register \
|
||||
if [ "$TOKEN" != "null" ]; then
|
||||
echo "SUCCESS: Got token for juan.allende@gmail.com"
|
||||
# Try to list courses
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X GET http://localhost:3001/courses \
|
||||
-H "Authorization: Bearer $TOKEN")
|
||||
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo "SUCCESS: Courses retrieved successfully with organization scope"
|
||||
else
|
||||
echo "FAIL: Failed to retrieve courses (Status: $HTTP_CODE)"
|
||||
fi
|
||||
|
||||
# 4. Verify Admin Context Switching (X-Organization-Id)
|
||||
# Create a dummy organization to test switching
|
||||
echo "Testing Admin Context Switching (X-Organization-Id)..."
|
||||
NEW_ORG_ID=$(curl -s -X POST http://localhost:3001/organizations \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"email":"newuser@test.com","password":"password123","full_name":"New User","role":"instructor"}'
|
||||
echo ""
|
||||
-d '{"name": "Context Switching Test"}' | jq -r '.id')
|
||||
|
||||
if [ "$NEW_ORG_ID" != "null" ]; then
|
||||
echo "SUCCESS: New organization created ($NEW_ORG_ID)"
|
||||
# Try to list courses using the new org context
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X GET http://localhost:3001/courses \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "X-Organization-Id: $NEW_ORG_ID")
|
||||
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
echo "SUCCESS: Context switching worked via X-Organization-Id"
|
||||
else
|
||||
echo "FAIL: Context switching failed (Status: $HTTP_CODE)"
|
||||
fi
|
||||
else
|
||||
echo "FAIL: Could not create test organization"
|
||||
fi
|
||||
else
|
||||
echo "FAIL: Could not get token for testing organization context"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user