.
This commit is contained in:
		
							
								
								
									
										90
									
								
								qwen/nodejs/tests/unit/models/User.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								qwen/nodejs/tests/unit/models/User.test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
// tests/unit/models/User.test.js
 | 
			
		||||
const User = require('../../../models/User');
 | 
			
		||||
 | 
			
		||||
describe('User Model', () => {
 | 
			
		||||
  test('should create a new user with provided data', () => {
 | 
			
		||||
    const userData = {
 | 
			
		||||
      id: 'test-id',
 | 
			
		||||
      email: 'test@example.com',
 | 
			
		||||
      passwordHash: 'hashed_password',
 | 
			
		||||
      firstName: 'John',
 | 
			
		||||
      lastName: 'Doe',
 | 
			
		||||
      userType: 'job-seeker',
 | 
			
		||||
      tenantId: 'tenant1'
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const user = User.create(userData);
 | 
			
		||||
 | 
			
		||||
    expect(user.id).toBe('test-id');
 | 
			
		||||
    expect(user.email).toBe('test@example.com');
 | 
			
		||||
    expect(user.firstName).toBe('John');
 | 
			
		||||
    expect(user.lastName).toBe('Doe');
 | 
			
		||||
    expect(user.userType).toBe('job-seeker');
 | 
			
		||||
    expect(user.tenantId).toBe('tenant1');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should generate ID if not provided', () => {
 | 
			
		||||
    const userData = {
 | 
			
		||||
      email: 'test@example.com',
 | 
			
		||||
      passwordHash: 'hashed_password',
 | 
			
		||||
      firstName: 'John',
 | 
			
		||||
      lastName: 'Doe',
 | 
			
		||||
      userType: 'job-seeker',
 | 
			
		||||
      tenantId: 'tenant1'
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const user = User.create(userData);
 | 
			
		||||
 | 
			
		||||
    expect(user.id).toBeDefined();
 | 
			
		||||
    expect(typeof user.id).toBe('string');
 | 
			
		||||
    expect(user.id.length).toBeGreaterThan(0);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should validate required fields', () => {
 | 
			
		||||
    const user = new User(
 | 
			
		||||
      'test-id',
 | 
			
		||||
      'test@example.com',
 | 
			
		||||
      'hashed_password',
 | 
			
		||||
      'John',
 | 
			
		||||
      'Doe',
 | 
			
		||||
      'job-seeker',
 | 
			
		||||
      'tenant1'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    expect(() => user.validate()).not.toThrow();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should throw error if missing required fields', () => {
 | 
			
		||||
    const user = new User();
 | 
			
		||||
 | 
			
		||||
    expect(() => user.validate()).toThrow('Missing required fields');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should throw error for invalid email format', () => {
 | 
			
		||||
    const user = new User(
 | 
			
		||||
      'test-id',
 | 
			
		||||
      'invalid-email',
 | 
			
		||||
      'hashed_password',
 | 
			
		||||
      'John',
 | 
			
		||||
      'Doe',
 | 
			
		||||
      'job-seeker',
 | 
			
		||||
      'tenant1'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    expect(() => user.validate()).toThrow('Invalid email format');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should throw error for invalid user type', () => {
 | 
			
		||||
    const user = new User(
 | 
			
		||||
      'test-id',
 | 
			
		||||
      'test@example.com',
 | 
			
		||||
      'hashed_password',
 | 
			
		||||
      'John',
 | 
			
		||||
      'Doe',
 | 
			
		||||
      'invalid-type',
 | 
			
		||||
      'tenant1'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    expect(() => user.validate()).toThrow('User type must be either job-seeker or job-provider');
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user