admin area
This commit is contained in:
127
core/admin/domain/value-objects/UserStatus.test.ts
Normal file
127
core/admin/domain/value-objects/UserStatus.test.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { UserStatus } from './UserStatus';
|
||||
|
||||
describe('UserStatus', () => {
|
||||
describe('TDD - Test First', () => {
|
||||
it('should create a valid status from string', () => {
|
||||
// Arrange & Act
|
||||
const status = UserStatus.fromString('active');
|
||||
|
||||
// Assert
|
||||
expect(status.value).toBe('active');
|
||||
});
|
||||
|
||||
it('should trim whitespace', () => {
|
||||
// Arrange & Act
|
||||
const status = UserStatus.fromString(' suspended ');
|
||||
|
||||
// Assert
|
||||
expect(status.value).toBe('suspended');
|
||||
});
|
||||
|
||||
it('should throw error for empty string', () => {
|
||||
// Arrange & Act & Assert
|
||||
expect(() => UserStatus.fromString('')).toThrow('Status cannot be empty');
|
||||
expect(() => UserStatus.fromString(' ')).toThrow('Status cannot be empty');
|
||||
});
|
||||
|
||||
it('should throw error for null or undefined', () => {
|
||||
// Arrange & Act & Assert
|
||||
expect(() => UserStatus.fromString(null as unknown as string)).toThrow('Status cannot be empty');
|
||||
expect(() => UserStatus.fromString(undefined as unknown as string)).toThrow('Status cannot be empty');
|
||||
});
|
||||
|
||||
it('should handle all valid statuses', () => {
|
||||
// Arrange & Act
|
||||
const active = UserStatus.fromString('active');
|
||||
const suspended = UserStatus.fromString('suspended');
|
||||
const deleted = UserStatus.fromString('deleted');
|
||||
|
||||
// Assert
|
||||
expect(active.value).toBe('active');
|
||||
expect(suspended.value).toBe('suspended');
|
||||
expect(deleted.value).toBe('deleted');
|
||||
});
|
||||
|
||||
it('should detect active status', () => {
|
||||
// Arrange
|
||||
const active = UserStatus.fromString('active');
|
||||
const suspended = UserStatus.fromString('suspended');
|
||||
const deleted = UserStatus.fromString('deleted');
|
||||
|
||||
// Assert
|
||||
expect(active.isActive()).toBe(true);
|
||||
expect(suspended.isActive()).toBe(false);
|
||||
expect(deleted.isActive()).toBe(false);
|
||||
});
|
||||
|
||||
it('should detect suspended status', () => {
|
||||
// Arrange
|
||||
const active = UserStatus.fromString('active');
|
||||
const suspended = UserStatus.fromString('suspended');
|
||||
const deleted = UserStatus.fromString('deleted');
|
||||
|
||||
// Assert
|
||||
expect(active.isSuspended()).toBe(false);
|
||||
expect(suspended.isSuspended()).toBe(true);
|
||||
expect(deleted.isSuspended()).toBe(false);
|
||||
});
|
||||
|
||||
it('should detect deleted status', () => {
|
||||
// Arrange
|
||||
const active = UserStatus.fromString('active');
|
||||
const suspended = UserStatus.fromString('suspended');
|
||||
const deleted = UserStatus.fromString('deleted');
|
||||
|
||||
// Assert
|
||||
expect(active.isDeleted()).toBe(false);
|
||||
expect(suspended.isDeleted()).toBe(false);
|
||||
expect(deleted.isDeleted()).toBe(true);
|
||||
});
|
||||
|
||||
it('should support equals comparison', () => {
|
||||
// Arrange
|
||||
const status1 = UserStatus.fromString('active');
|
||||
const status2 = UserStatus.fromString('active');
|
||||
const status3 = UserStatus.fromString('suspended');
|
||||
|
||||
// Assert
|
||||
expect(status1.equals(status2)).toBe(true);
|
||||
expect(status1.equals(status3)).toBe(false);
|
||||
});
|
||||
|
||||
it('should support toString', () => {
|
||||
// Arrange
|
||||
const status = UserStatus.fromString('active');
|
||||
|
||||
// Assert
|
||||
expect(status.toString()).toBe('active');
|
||||
});
|
||||
|
||||
it('should handle custom statuses', () => {
|
||||
// Arrange & Act
|
||||
const customStatus = UserStatus.fromString('pending');
|
||||
|
||||
// Assert
|
||||
expect(customStatus.value).toBe('pending');
|
||||
expect(customStatus.isActive()).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle case sensitivity', () => {
|
||||
// Arrange & Act
|
||||
const status1 = UserStatus.fromString('Active');
|
||||
const status2 = UserStatus.fromString('active');
|
||||
|
||||
// Assert - Should preserve case but compare as-is
|
||||
expect(status1.value).toBe('Active');
|
||||
expect(status2.value).toBe('active');
|
||||
});
|
||||
|
||||
it('should handle special characters in status names', () => {
|
||||
// Arrange & Act
|
||||
const status = UserStatus.fromString('under-review');
|
||||
|
||||
// Assert
|
||||
expect(status.value).toBe('under-review');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user