Fix jwt-token

This commit is contained in:
2025-09-15 06:30:17 +02:00
parent 9413d45a10
commit 2392fbd8ed
2 changed files with 8 additions and 14 deletions

View File

@@ -93,13 +93,9 @@ describe('Authentication Middleware', () => {
const user = await createTestUser({ username: 'testuser', role: 'admin' }); const user = await createTestUser({ username: 'testuser', role: 'admin' });
console.log('Created user:', user.toJSON()); // Debug log console.log('Created user:', user.toJSON()); // Debug log
// Get the actual string value of the UUID
const userId = user.getDataValue('id') || user.id;
console.log('User ID for JWT:', userId, typeof userId);
const token = jwt.sign( const token = jwt.sign(
{ {
userId: userId, userId: user.id,
username: user.username, username: user.username,
role: user.role, role: user.role,
email: user.email email: user.email
@@ -117,7 +113,7 @@ describe('Authentication Middleware', () => {
await authenticateToken(req, res, next); await authenticateToken(req, res, next);
expect(req.user).to.exist; expect(req.user).to.exist;
expect(req.user.id).to.equal(userId); expect(req.user.id).to.equal(user.id);
expect(req.user.username).to.equal(user.username); expect(req.user.username).to.equal(user.username);
expect(req.user.role).to.equal(user.role); expect(req.user.role).to.equal(user.role);
expect(next.errors).to.have.length(0); expect(next.errors).to.have.length(0);
@@ -127,12 +123,9 @@ describe('Authentication Middleware', () => {
const tenant = await createTestTenant({ slug: 'test-tenant' }); const tenant = await createTestTenant({ slug: 'test-tenant' });
const user = await createTestUser({ username: 'testuser', tenant_id: tenant.id }); const user = await createTestUser({ username: 'testuser', tenant_id: tenant.id });
// Get the actual string value of the UUID
const userId = user.getDataValue('id') || user.id;
const token = jwt.sign( const token = jwt.sign(
{ {
userId: userId, userId: user.id,
username: user.username, username: user.username,
role: user.role, role: user.role,
tenantId: tenant.slug tenantId: tenant.slug
@@ -181,12 +174,9 @@ describe('Authentication Middleware', () => {
is_active: false is_active: false
}); });
// Get the actual string value of the UUID
const userId = user.getDataValue('id') || user.id;
const token = jwt.sign( const token = jwt.sign(
{ {
userId: userId, userId: user.id,
username: user.username username: user.username
}, },
process.env.JWT_SECRET || 'test-secret', process.env.JWT_SECRET || 'test-secret',

View File

@@ -129,7 +129,11 @@ async function createTestUser(userData = {}) {
}); });
} }
// Generate a simple UUID-like string for testing
const testId = 'test-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9);
const defaultUserData = { const defaultUserData = {
id: testId, // Use explicit test ID
username: 'testuser', username: 'testuser',
email: 'test@example.com', email: 'test@example.com',
password_hash: '$2b$10$example.hash.for.testing.purposes.only', password_hash: '$2b$10$example.hash.for.testing.purposes.only',