harden media
This commit is contained in:
@@ -22,6 +22,7 @@ interface OpenAPISchema {
|
||||
enum?: string[];
|
||||
nullable?: boolean;
|
||||
description?: string;
|
||||
default?: unknown;
|
||||
}
|
||||
|
||||
interface OpenAPISpec {
|
||||
@@ -367,5 +368,41 @@ describe('API Contract Validation', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should have no empty string defaults for avatar/logo URLs', async () => {
|
||||
const content = await fs.readFile(openapiPath, 'utf-8');
|
||||
const spec: OpenAPISpec = JSON.parse(content);
|
||||
const schemas = spec.components.schemas;
|
||||
|
||||
// Check DTOs that should use URL|null pattern
|
||||
const mediaRelatedDTOs = [
|
||||
'GetAvatarOutputDTO',
|
||||
'UpdateAvatarInputDTO',
|
||||
'DashboardDriverSummaryDTO',
|
||||
'DriverProfileDriverSummaryDTO',
|
||||
'DriverLeaderboardItemDTO',
|
||||
'TeamListItemDTO',
|
||||
'LeagueSummaryDTO',
|
||||
'SponsorDTO',
|
||||
];
|
||||
|
||||
for (const dtoName of mediaRelatedDTOs) {
|
||||
const schema = schemas[dtoName];
|
||||
if (!schema || !schema.properties) continue;
|
||||
|
||||
// Check for avatarUrl, logoUrl properties
|
||||
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
||||
if (propName === 'avatarUrl' || propName === 'logoUrl') {
|
||||
// Should be string type, nullable (no empty string defaults)
|
||||
expect(propSchema.type).toBe('string');
|
||||
expect(propSchema.nullable).toBe(true);
|
||||
// Should not have default value of empty string
|
||||
if (propSchema.default !== undefined) {
|
||||
expect(propSchema.default).not.toBe('');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user