Fix jwt-token
This commit is contained in:
@@ -1,15 +1,6 @@
|
||||
const { describe, it, beforeEach, afterEach, before, after } = require('mocha');
|
||||
const { expect } = require('chai');
|
||||
co const token = jwt.sign(
|
||||
{
|
||||
userId: user.id, // Use the UUID directly
|
||||
username: user.username,
|
||||
role: user.role,
|
||||
tenantId: 'test-tenant'
|
||||
},
|
||||
process.env.JWT_SECRET || 'test-secret',
|
||||
{ expiresIn: '1h' }
|
||||
);= require('sinon');
|
||||
const sinon = require('sinon');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { authenticateToken } = require('../../middleware/auth');
|
||||
const { setupTestEnvironment, teardownTestEnvironment, cleanDatabase, mockRequest, mockResponse, mockNext, createTestUser, createTestTenant } = require('../setup');
|
||||
@@ -19,6 +10,9 @@ describe('Authentication Middleware', () => {
|
||||
|
||||
before(async () => {
|
||||
({ models, sequelize } = await setupTestEnvironment());
|
||||
// Set models for auth middleware
|
||||
const auth = require('../../middleware/auth');
|
||||
auth.setModels(models);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
@@ -119,7 +113,7 @@ describe('Authentication Middleware', () => {
|
||||
await authenticateToken(req, res, next);
|
||||
|
||||
expect(req.user).to.exist;
|
||||
expect(req.user.userId).to.equal(user.id);
|
||||
expect(req.user.id).to.equal(user.id);
|
||||
expect(req.user.username).to.equal(user.username);
|
||||
expect(req.user.role).to.equal(user.role);
|
||||
expect(next.errors).to.have.length(0);
|
||||
@@ -147,7 +141,9 @@ describe('Authentication Middleware', () => {
|
||||
|
||||
await authenticateToken(req, res, next);
|
||||
|
||||
expect(req.user.tenantId).to.equal(tenant.slug);
|
||||
expect(req.user).to.exist;
|
||||
expect(req.user.username).to.equal(user.username);
|
||||
expect(req.tenantId).to.equal(tenant.slug);
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user