Spaces:
Sleeping
Sleeping
fix(user-model): remove invited_at and activated_at to match migrated users table schema
Browse files
src/app/models/user.py
CHANGED
|
@@ -38,9 +38,8 @@ class User(BaseModel):
|
|
| 38 |
display_name = Column(String(255), nullable=True)
|
| 39 |
is_active = Column(Boolean, default=True)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
activated_at = Column(DateTime(timezone=True), nullable=True)
|
| 44 |
|
| 45 |
# Health & Safety (for field agents)
|
| 46 |
health_info = Column(JSONB, default={})
|
|
|
|
| 38 |
display_name = Column(String(255), nullable=True)
|
| 39 |
is_active = Column(Boolean, default=True)
|
| 40 |
|
| 41 |
+
# Note: invited_at and activated_at removed - tracked in user_invitations table
|
| 42 |
+
# See migration: 14_cleanup_users_table.sql
|
|
|
|
| 43 |
|
| 44 |
# Health & Safety (for field agents)
|
| 45 |
health_info = Column(JSONB, default={})
|
tests/integration/test_admin_edit_profiles.js
CHANGED
|
@@ -22,7 +22,7 @@ const BASE_URL = 'https://kamau1-swiftops-backend.hf.space';
|
|
| 22 |
|
| 23 |
// Admin credentials
|
| 24 |
const ADMIN_EMAIL = 'lewis.kamau421@gmail.com';
|
| 25 |
-
const ADMIN_PASSWORD = 'TestPass123';
|
| 26 |
|
| 27 |
// Field agents to manage
|
| 28 |
const LESLEY_EMAIL = 'lesley@example.com';
|
|
|
|
| 22 |
|
| 23 |
// Admin credentials
|
| 24 |
const ADMIN_EMAIL = 'lewis.kamau421@gmail.com';
|
| 25 |
+
const ADMIN_PASSWORD = 'TestPass123!'; // Note: Password requires special character
|
| 26 |
|
| 27 |
// Field agents to manage
|
| 28 |
const LESLEY_EMAIL = 'lesley@example.com';
|
tests/integration/test_auth_api.js
CHANGED
|
@@ -11,7 +11,7 @@ const https = require('https');
|
|
| 11 |
|
| 12 |
const BASE_URL = 'https://kamau1-swiftops-backend.hf.space';
|
| 13 |
const TEST_EMAIL = 'lewis.kamau421@gmail.com';
|
| 14 |
-
const TEST_PASSWORD = 'TestPass123';
|
| 15 |
|
| 16 |
// Store token between tests
|
| 17 |
let authToken = null;
|
|
|
|
| 11 |
|
| 12 |
const BASE_URL = 'https://kamau1-swiftops-backend.hf.space';
|
| 13 |
const TEST_EMAIL = 'lewis.kamau421@gmail.com';
|
| 14 |
+
const TEST_PASSWORD = 'TestPass123!'; // Note: Password requires special character
|
| 15 |
|
| 16 |
// Store token between tests
|
| 17 |
let authToken = null;
|
tests/integration/test_invitation_flow.js
CHANGED
|
@@ -15,7 +15,7 @@ const https = require('https');
|
|
| 15 |
|
| 16 |
const BASE_URL = 'https://kamau1-swiftops-backend.hf.space';
|
| 17 |
const ADMIN_EMAIL = 'lewis.kamau421@gmail.com';
|
| 18 |
-
const ADMIN_PASSWORD = 'TestPass123';
|
| 19 |
|
| 20 |
// New user to invite
|
| 21 |
const INVITE_EMAIL = 'lesley@example.com';
|
|
|
|
| 15 |
|
| 16 |
const BASE_URL = 'https://kamau1-swiftops-backend.hf.space';
|
| 17 |
const ADMIN_EMAIL = 'lewis.kamau421@gmail.com';
|
| 18 |
+
const ADMIN_PASSWORD = 'TestPass123!'; // Note: Password requires special character
|
| 19 |
|
| 20 |
// New user to invite
|
| 21 |
const INVITE_EMAIL = 'lesley@example.com';
|
tests/integration/test_register_admin.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Register Admin User
|
| 5 |
+
* Quick script to register the admin user for testing
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
const https = require('https');
|
| 9 |
+
|
| 10 |
+
const BASE_URL = 'https://kamau1-swiftops-backend.hf.space';
|
| 11 |
+
const ADMIN_EMAIL = 'lewis.kamau421@gmail.com';
|
| 12 |
+
const ADMIN_PASSWORD = 'TestPass123!';
|
| 13 |
+
|
| 14 |
+
function makeRequest(method, path, data = null) {
|
| 15 |
+
return new Promise((resolve, reject) => {
|
| 16 |
+
const url = new URL(path, BASE_URL);
|
| 17 |
+
const options = {
|
| 18 |
+
method,
|
| 19 |
+
headers: { 'Content-Type': 'application/json' }
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
const req = https.request(url, options, (res) => {
|
| 23 |
+
let body = '';
|
| 24 |
+
res.on('data', chunk => body += chunk);
|
| 25 |
+
res.on('end', () => {
|
| 26 |
+
try {
|
| 27 |
+
resolve({ status: res.statusCode, data: JSON.parse(body) });
|
| 28 |
+
} catch (e) {
|
| 29 |
+
resolve({ status: res.statusCode, data: body });
|
| 30 |
+
}
|
| 31 |
+
});
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
req.on('error', reject);
|
| 35 |
+
if (data) req.write(JSON.stringify(data));
|
| 36 |
+
req.end();
|
| 37 |
+
});
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
async function registerAdmin() {
|
| 41 |
+
console.log('🔐 Registering Admin User...');
|
| 42 |
+
console.log(`Email: ${ADMIN_EMAIL}`);
|
| 43 |
+
console.log(`Password: ${ADMIN_PASSWORD}`);
|
| 44 |
+
|
| 45 |
+
const response = await makeRequest('POST', '/api/v1/auth/register', {
|
| 46 |
+
email: ADMIN_EMAIL,
|
| 47 |
+
password: ADMIN_PASSWORD,
|
| 48 |
+
first_name: 'Lewis',
|
| 49 |
+
last_name: 'Kamau',
|
| 50 |
+
phone: '+254712345678'
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
if (response.status === 201 || response.status === 200) {
|
| 54 |
+
console.log('✅ Admin registered successfully!');
|
| 55 |
+
console.log(`User ID: ${response.data.user.id}`);
|
| 56 |
+
console.log(`Token: ${response.data.access_token.substring(0, 30)}...`);
|
| 57 |
+
} else if (response.status === 400 && response.data.detail?.includes('already registered')) {
|
| 58 |
+
console.log('⚠️ User already exists - trying to login...');
|
| 59 |
+
|
| 60 |
+
const loginResponse = await makeRequest('POST', '/api/v1/auth/login', {
|
| 61 |
+
email: ADMIN_EMAIL,
|
| 62 |
+
password: ADMIN_PASSWORD
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
if (loginResponse.status === 200) {
|
| 66 |
+
console.log('✅ Login successful!');
|
| 67 |
+
console.log(`User ID: ${loginResponse.data.user.id}`);
|
| 68 |
+
} else {
|
| 69 |
+
console.log('❌ Login failed - password might be different');
|
| 70 |
+
console.log('Try resetting the password or use a different email');
|
| 71 |
+
}
|
| 72 |
+
} else {
|
| 73 |
+
console.log('❌ Registration failed:', response.status);
|
| 74 |
+
console.log(JSON.stringify(response.data, null, 2));
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
registerAdmin().catch(console.error);
|