wip
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { AnalyticsEntityId } from './AnalyticsEntityId';
|
||||
|
||||
describe('AnalyticsEntityId', () => {
|
||||
it('creates a valid AnalyticsEntityId from a non-empty string', () => {
|
||||
const id = AnalyticsEntityId.create('entity_123');
|
||||
|
||||
expect(id.value).toBe('entity_123');
|
||||
});
|
||||
|
||||
it('trims whitespace from the raw value', () => {
|
||||
const id = AnalyticsEntityId.create(' entity_456 ');
|
||||
|
||||
expect(id.value).toBe('entity_456');
|
||||
});
|
||||
|
||||
it('throws for empty or whitespace-only strings', () => {
|
||||
expect(() => AnalyticsEntityId.create('')).toThrow(Error);
|
||||
expect(() => AnalyticsEntityId.create(' ')).toThrow(Error);
|
||||
});
|
||||
|
||||
it('compares equality based on underlying value', () => {
|
||||
const a = AnalyticsEntityId.create('entity_1');
|
||||
const b = AnalyticsEntityId.create('entity_1');
|
||||
const c = AnalyticsEntityId.create('entity_2');
|
||||
|
||||
expect(a.equals(b)).toBe(true);
|
||||
expect(a.equals(c)).toBe(false);
|
||||
});
|
||||
});
|
||||
37
packages/analytics/domain/value-objects/AnalyticsEntityId.ts
Normal file
37
packages/analytics/domain/value-objects/AnalyticsEntityId.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { IValueObject } from '@gridpilot/shared/domain';
|
||||
|
||||
export interface AnalyticsEntityIdProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value Object: AnalyticsEntityId
|
||||
*
|
||||
* Represents the ID of an entity (league, driver, team, race, sponsor)
|
||||
* within the analytics bounded context.
|
||||
*/
|
||||
export class AnalyticsEntityId implements IValueObject<AnalyticsEntityIdProps> {
|
||||
public readonly props: AnalyticsEntityIdProps;
|
||||
|
||||
private constructor(value: string) {
|
||||
this.props = { value };
|
||||
}
|
||||
|
||||
static create(raw: string): AnalyticsEntityId {
|
||||
const value = raw.trim();
|
||||
|
||||
if (!value) {
|
||||
throw new Error('AnalyticsEntityId must be a non-empty string');
|
||||
}
|
||||
|
||||
return new AnalyticsEntityId(value);
|
||||
}
|
||||
|
||||
get value(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<AnalyticsEntityIdProps>): boolean {
|
||||
return this.props.value === other.props.value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { AnalyticsSessionId } from './AnalyticsSessionId';
|
||||
|
||||
describe('AnalyticsSessionId', () => {
|
||||
it('creates a valid AnalyticsSessionId from a non-empty string', () => {
|
||||
const id = AnalyticsSessionId.create('session_123');
|
||||
|
||||
expect(id.value).toBe('session_123');
|
||||
});
|
||||
|
||||
it('trims whitespace from the raw value', () => {
|
||||
const id = AnalyticsSessionId.create(' session_456 ');
|
||||
|
||||
expect(id.value).toBe('session_456');
|
||||
});
|
||||
|
||||
it('throws for empty or whitespace-only strings', () => {
|
||||
expect(() => AnalyticsSessionId.create('')).toThrow(Error);
|
||||
expect(() => AnalyticsSessionId.create(' ')).toThrow(Error);
|
||||
});
|
||||
|
||||
it('compares equality based on underlying value', () => {
|
||||
const a = AnalyticsSessionId.create('session_1');
|
||||
const b = AnalyticsSessionId.create('session_1');
|
||||
const c = AnalyticsSessionId.create('session_2');
|
||||
|
||||
expect(a.equals(b)).toBe(true);
|
||||
expect(a.equals(c)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { IValueObject } from '@gridpilot/shared/domain';
|
||||
|
||||
export interface AnalyticsSessionIdProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value Object: AnalyticsSessionId
|
||||
*
|
||||
* Represents an analytics session identifier within the analytics bounded context.
|
||||
*/
|
||||
export class AnalyticsSessionId implements IValueObject<AnalyticsSessionIdProps> {
|
||||
public readonly props: AnalyticsSessionIdProps;
|
||||
|
||||
private constructor(value: string) {
|
||||
this.props = { value };
|
||||
}
|
||||
|
||||
static create(raw: string): AnalyticsSessionId {
|
||||
const value = raw.trim();
|
||||
|
||||
if (!value) {
|
||||
throw new Error('AnalyticsSessionId must be a non-empty string');
|
||||
}
|
||||
|
||||
return new AnalyticsSessionId(value);
|
||||
}
|
||||
|
||||
get value(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<AnalyticsSessionIdProps>): boolean {
|
||||
return this.props.value === other.props.value;
|
||||
}
|
||||
}
|
||||
29
packages/analytics/domain/value-objects/PageViewId.test.ts
Normal file
29
packages/analytics/domain/value-objects/PageViewId.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { PageViewId } from './PageViewId';
|
||||
|
||||
describe('PageViewId', () => {
|
||||
it('creates a valid PageViewId from a non-empty string', () => {
|
||||
const id = PageViewId.create('pv_123');
|
||||
|
||||
expect(id.value).toBe('pv_123');
|
||||
});
|
||||
|
||||
it('trims whitespace from the raw value', () => {
|
||||
const id = PageViewId.create(' pv_456 ');
|
||||
|
||||
expect(id.value).toBe('pv_456');
|
||||
});
|
||||
|
||||
it('throws for empty or whitespace-only strings', () => {
|
||||
expect(() => PageViewId.create('')).toThrow(Error);
|
||||
expect(() => PageViewId.create(' ')).toThrow(Error);
|
||||
});
|
||||
|
||||
it('compares equality based on underlying value', () => {
|
||||
const a = PageViewId.create('pv_1');
|
||||
const b = PageViewId.create('pv_1');
|
||||
const c = PageViewId.create('pv_2');
|
||||
|
||||
expect(a.equals(b)).toBe(true);
|
||||
expect(a.equals(c)).toBe(false);
|
||||
});
|
||||
});
|
||||
36
packages/analytics/domain/value-objects/PageViewId.ts
Normal file
36
packages/analytics/domain/value-objects/PageViewId.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { IValueObject } from '@gridpilot/shared/domain';
|
||||
|
||||
export interface PageViewIdProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value Object: PageViewId
|
||||
*
|
||||
* Represents the identifier of a PageView within the analytics bounded context.
|
||||
*/
|
||||
export class PageViewId implements IValueObject<PageViewIdProps> {
|
||||
public readonly props: PageViewIdProps;
|
||||
|
||||
private constructor(value: string) {
|
||||
this.props = { value };
|
||||
}
|
||||
|
||||
static create(raw: string): PageViewId {
|
||||
const value = raw.trim();
|
||||
|
||||
if (!value) {
|
||||
throw new Error('PageViewId must be a non-empty string');
|
||||
}
|
||||
|
||||
return new PageViewId(value);
|
||||
}
|
||||
|
||||
get value(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<PageViewIdProps>): boolean {
|
||||
return this.props.value === other.props.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user