code quality
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
@@ -55,12 +55,12 @@ describe('AnalyticsSnapshotOrmMapper', () => {
|
||||
// Given
|
||||
const orm = new AnalyticsSnapshotOrmEntity();
|
||||
orm.id = ''; // Invalid: empty
|
||||
orm.entityType = 'league' as any;
|
||||
(orm as unknown as { entityType: unknown }).entityType = 'league';
|
||||
orm.entityId = 'league-1';
|
||||
orm.period = 'daily' as any;
|
||||
(orm as unknown as { period: unknown }).period = 'daily';
|
||||
orm.startDate = new Date();
|
||||
orm.endDate = new Date();
|
||||
orm.metrics = {} as any; // Invalid: missing fields
|
||||
(orm as unknown as { metrics: unknown }).metrics = {}; // Invalid: missing fields
|
||||
orm.createdAt = new Date();
|
||||
|
||||
// When / Then
|
||||
@@ -71,20 +71,24 @@ describe('AnalyticsSnapshotOrmMapper', () => {
|
||||
// Given
|
||||
const orm = new AnalyticsSnapshotOrmEntity();
|
||||
orm.id = 'snap_1';
|
||||
orm.entityType = 'league' as any;
|
||||
(orm as unknown as { entityType: unknown }).entityType = 'league';
|
||||
orm.entityId = 'league-1';
|
||||
orm.period = 'daily' as any;
|
||||
(orm as unknown as { period: unknown }).period = 'daily';
|
||||
orm.startDate = new Date();
|
||||
orm.endDate = new Date();
|
||||
orm.metrics = { pageViews: 100 } as any; // Missing other metrics
|
||||
(orm as unknown as { metrics: unknown }).metrics = { pageViews: 100 }; // Missing other metrics
|
||||
orm.createdAt = new Date();
|
||||
|
||||
// When / Then
|
||||
expect(() => mapper.toDomain(orm)).toThrow(TypeOrmAnalyticsSchemaError);
|
||||
try {
|
||||
mapper.toDomain(orm);
|
||||
} catch (e: any) {
|
||||
expect(e.fieldName).toContain('metrics.');
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof TypeOrmAnalyticsSchemaError) {
|
||||
expect(e.fieldName).toContain('metrics.');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,10 +68,10 @@ describe('EngagementEventOrmMapper', () => {
|
||||
// Given
|
||||
const orm = new EngagementEventOrmEntity();
|
||||
orm.id = ''; // Invalid
|
||||
orm.action = 'invalid_action' as any;
|
||||
orm.entityType = 'league' as any;
|
||||
(orm as unknown as { action: unknown }).action = 'invalid_action';
|
||||
(orm as unknown as { entityType: unknown }).entityType = 'league';
|
||||
orm.entityId = 'league-1';
|
||||
orm.actorType = 'anonymous' as any;
|
||||
(orm as unknown as { actorType: unknown }).actorType = 'anonymous';
|
||||
orm.sessionId = 'sess-1';
|
||||
orm.timestamp = new Date();
|
||||
|
||||
@@ -83,21 +83,25 @@ describe('EngagementEventOrmMapper', () => {
|
||||
// Given
|
||||
const orm = new EngagementEventOrmEntity();
|
||||
orm.id = 'eng_1';
|
||||
orm.action = 'click_sponsor_logo' as any;
|
||||
orm.entityType = 'sponsor' as any;
|
||||
(orm as unknown as { action: unknown }).action = 'click_sponsor_logo';
|
||||
(orm as unknown as { entityType: unknown }).entityType = 'sponsor';
|
||||
orm.entityId = 'sponsor-1';
|
||||
orm.actorType = 'driver' as any;
|
||||
(orm as unknown as { actorType: unknown }).actorType = 'driver';
|
||||
orm.sessionId = 'sess-1';
|
||||
orm.timestamp = new Date();
|
||||
orm.metadata = { invalid: { nested: 'object' } } as any;
|
||||
(orm as unknown as { metadata: unknown }).metadata = { invalid: { nested: 'object' } };
|
||||
|
||||
// When / Then
|
||||
expect(() => mapper.toDomain(orm)).toThrow(TypeOrmAnalyticsSchemaError);
|
||||
try {
|
||||
mapper.toDomain(orm);
|
||||
} catch (e: any) {
|
||||
expect(e.reason).toBe('invalid_shape');
|
||||
expect(e.fieldName).toBe('metadata');
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof TypeOrmAnalyticsSchemaError) {
|
||||
expect(e.reason).toBe('invalid_shape');
|
||||
expect(e.fieldName).toBe('metadata');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('TypeOrmAnalyticsSnapshotRepository', () => {
|
||||
period: 'daily',
|
||||
startDate: new Date(),
|
||||
endDate: new Date(),
|
||||
metrics: {} as any,
|
||||
metrics: {} as unknown as any,
|
||||
createdAt: new Date(),
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ describe('TypeOrmAnalyticsSnapshotRepository', () => {
|
||||
period: 'daily',
|
||||
startDate: new Date(),
|
||||
endDate: new Date(),
|
||||
metrics: {} as any,
|
||||
metrics: {} as unknown as any,
|
||||
createdAt: new Date(),
|
||||
});
|
||||
|
||||
|
||||
@@ -81,8 +81,8 @@ describe('TypeOrmEngagementRepository', () => {
|
||||
// Given
|
||||
const repo: Repository<EngagementEventOrmEntity> = {
|
||||
count: vi.fn().mockResolvedValue(5),
|
||||
} as any;
|
||||
const sut = new TypeOrmEngagementRepository(repo, {} as any);
|
||||
} as unknown as Repository<EngagementEventOrmEntity>;
|
||||
const sut = new TypeOrmEngagementRepository(repo, {} as unknown as EngagementEventOrmMapper);
|
||||
const since = new Date();
|
||||
|
||||
// When
|
||||
|
||||
Reference in New Issue
Block a user